Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wp-env]: Add support to override core by the WP_ENV_CORE environment variable. #40407

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;