From 53977c637d766d2c41aa99cf0290cee05763d3e0 Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe Date: Tue, 19 Apr 2022 13:20:00 +0900 Subject: [PATCH] [wp-env]: Add support to override `core` by the `WP_ENV_CORE` environment variable. (#40407) * allow override `core` by the `WP_ENV_CORE` environment variable. * override coreSource --- packages/env/README.md | 4 ++-- packages/env/lib/config/config.js | 13 +++++++++++++ packages/env/lib/config/parse-config.js | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/env/README.md b/packages/env/README.md index ad87cbe4cd5c1a..d3f4a0ae5bc0ac 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -534,9 +534,9 @@ This is useful for plugin development. } ``` -#### Latest development WordPress + current directory as a plugin +### Latest development WordPress + current directory as a plugin -This is useful for plugin development when upstream Core changes need to be tested. +This is useful for plugin development when upstream Core changes need to be tested. This can also be set via the environment variable `WP_ENV_CORE`. ```json { diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 401077c495f30d..fc68a63007f45c 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -13,6 +13,7 @@ const detectDirectoryType = require( './detect-directory-type' ); const { validateConfig, ValidationError } = require( './validate-config' ); const readRawConfigFile = require( './read-raw-config-file' ); const parseConfig = require( './parse-config' ); +const { includeTestsPath, parseSourceString } = parseConfig; const md5 = require( '../md5' ); /** @@ -256,6 +257,18 @@ function withOverrides( config ) { getNumberFromEnvVariable( 'WP_ENV_TESTS_PORT' ) || config.env.tests.port; + // Override WordPress core with environment variable. + if ( process.env.WP_ENV_CORE ) { + const coreSource = includeTestsPath( + parseSourceString( process.env.WP_ENV_CORE, { + workDirectoryPath: config.workDirectoryPath, + } ), + { workDirectoryPath: config.workDirectoryPath } + ); + config.env.development.coreSource = coreSource; + config.env.tests.coreSource = coreSource; + } + // Override PHP version with environment variable. config.env.development.phpVersion = process.env.WP_ENV_PHP_VERSION || config.env.development.phpVersion; diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index bc8a8aeafa4d1e..e278ca1ba57dc3 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -136,6 +136,7 @@ function parseSourceString( sourceString, { workDirectoryPath } ) { `Invalid or unrecognized source: "${ sourceString }".` ); } +module.exports.parseSourceString = parseSourceString; /** * Given a source object, returns a new source object with the testsPath @@ -160,3 +161,4 @@ function includeTestsPath( source, { workDirectoryPath } ) { ), }; } +module.exports.includeTestsPath = includeTestsPath;