From 7465c32125099fa75fe1ca415a0276379428846e Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe <mail@torounit.com> Date: Mon, 18 Apr 2022 17:33:10 +0900 Subject: [PATCH 1/2] allow override `core` by the `WP_ENV_CORE` environment variable. --- packages/env/README.md | 4 ++-- packages/env/lib/config/config.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/env/README.md b/packages/env/README.md index ad87cbe4cd5c1..d3f4a0ae5bc0a 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 401077c495f30..4239f3e254e6b 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -256,6 +256,11 @@ function withOverrides( config ) { getNumberFromEnvVariable( 'WP_ENV_TESTS_PORT' ) || config.env.tests.port; + // Override WordPress core with environment variable. + config.env.development.core = + process.env.WP_ENV_CORE || config.env.development.core; + config.env.tests.core = process.env.WP_ENV_CORE || config.env.tests.core; + // Override PHP version with environment variable. config.env.development.phpVersion = process.env.WP_ENV_PHP_VERSION || config.env.development.phpVersion; From 1049cb8d2059f281a8b6091ef6f78e4839df0002 Mon Sep 17 00:00:00 2001 From: Hiroshi Urabe <mail@torounit.com> Date: Mon, 18 Apr 2022 19:40:24 +0900 Subject: [PATCH 2/2] override coreSource --- packages/env/lib/config/config.js | 14 +++++++++++--- packages/env/lib/config/parse-config.js | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 4239f3e254e6b..fc68a63007f45 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' ); /** @@ -257,9 +258,16 @@ function withOverrides( config ) { config.env.tests.port; // Override WordPress core with environment variable. - config.env.development.core = - process.env.WP_ENV_CORE || config.env.development.core; - config.env.tests.core = process.env.WP_ENV_CORE || config.env.tests.core; + 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 = diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index bc8a8aeafa4d1..e278ca1ba57dc 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;