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

Env: Allow skipping setting a configuration value by specifying it as null. #41084

Merged
merged 4 commits into from
May 24, 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
1 change: 1 addition & 0 deletions packages/env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased
### Enhancement
- Removed the need for quotation marks when passing options to `wp-env run`.
- Setting a `config` key to `null` will prevent adding the constant to `wp-config.php` even if a default value is defined by `wp-env`.

## 4.7.0 (2022-05-18)

Expand Down
2 changes: 2 additions & 0 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ WP_HOME: 'http://localhost',

On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false.

These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely.

Additionally, the values referencing a URL include the specified port for the given environment. So if you set `testsPort: 3000, port: 2000`, `WP_HOME` (for example) will be `http://localhost:3000` on the tests instance and `http://localhost:2000` on the development instance.

### Examples
Expand Down
5 changes: 5 additions & 0 deletions packages/env/lib/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ async function configureWordPress( environment, config, spinner ) {
for ( let [ key, value ] of Object.entries(
config.env[ environment ].config
) ) {
// Allow the configuration to skip a default constant by specifying it as null.
if ( null === value ) {
continue;
}

// Add quotes around string values to work with multi-word strings better.
value = typeof value === 'string' ? `"${ value }"` : value;
setupCommands.push(
Expand Down