Skip to content

Commit

Permalink
[wp-env]: Add support to override core by the WP_ENV_CORE environ…
Browse files Browse the repository at this point in the history
…ment variable. (#40407)

* allow override `core` by the `WP_ENV_CORE` environment variable.

* override coreSource
  • Loading branch information
torounit authored Apr 19, 2022
1 parent 65e412f commit 53977c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
13 changes: 13 additions & 0 deletions packages/env/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

/**
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -160,3 +161,4 @@ function includeTestsPath( source, { workDirectoryPath } ) {
),
};
}
module.exports.includeTestsPath = includeTestsPath;

0 comments on commit 53977c6

Please sign in to comment.