@wordpress/env 11.0.1-next.v.20260206T143.0 → 11.0.1-next.v.202602111440.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/lib/cli.js +5 -0
- package/lib/commands/clean.js +3 -1
- package/lib/commands/cleanup.js +17 -8
- package/lib/commands/destroy.js +14 -7
- package/lib/commands/logs.js +14 -7
- package/lib/commands/reset.js +6 -2
- package/lib/commands/run.js +10 -8
- package/lib/commands/start.js +11 -9
- package/lib/commands/status.js +13 -7
- package/lib/commands/stop.js +10 -5
- package/lib/config/load-config.js +34 -5
- package/lib/config/parse-config.js +36 -21
- package/lib/config/test/__snapshots__/config-integration.js.snap +4 -0
- package/lib/runtime/docker/index.js +22 -4
- package/lib/runtime/docker/init-config.js +13 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -295,6 +295,42 @@ Here is a summary:
|
|
|
295
295
|
|
|
296
296
|
`wp-env` creates generated files in the `wp-env` home directory. By default, this is `~/.wp-env`. The exception is Linux, where files are placed at `~/wp-env` [for compatibility with Snap Packages](https://github.com/WordPress/gutenberg/issues/20180#issuecomment-587046325). The `wp-env` home directory contains a subdirectory for each project named `/$md5_of_project_path`. To change the `wp-env` home directory, set the `WP_ENV_HOME` environment variable. For example, running `WP_ENV_HOME="something" wp-env start` will download the project files to the directory `./something/$md5_of_project_path` (relative to the current directory).
|
|
297
297
|
|
|
298
|
+
### Global options
|
|
299
|
+
|
|
300
|
+
These options apply to all `wp-env` commands:
|
|
301
|
+
|
|
302
|
+
```
|
|
303
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
304
|
+
--config Path to a custom .wp-env.json configuration file. [string]
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The `--config` option allows you to use a custom configuration file instead of the default `.wp-env.json`. This is useful for running multiple parallel environments from the same directory.
|
|
308
|
+
|
|
309
|
+
When using a custom config file, the override file is derived from its name. For example:
|
|
310
|
+
- `--config=staging.json` will look for `staging.override.json`
|
|
311
|
+
- `--config=./configs/dev.wp-env.json` will look for `./configs/dev.wp-env.override.json`
|
|
312
|
+
|
|
313
|
+
#### Running parallel environments
|
|
314
|
+
|
|
315
|
+
You can run multiple wp-env environments from the same folder by using different config files and ports:
|
|
316
|
+
|
|
317
|
+
```sh
|
|
318
|
+
# Start first environment with default config
|
|
319
|
+
wp-env start
|
|
320
|
+
|
|
321
|
+
# Start second environment with custom config on different ports
|
|
322
|
+
WP_ENV_PORT=8890 WP_ENV_TESTS_PORT=8891 wp-env start --config=./staging.json
|
|
323
|
+
|
|
324
|
+
# Check status of each environment
|
|
325
|
+
wp-env status
|
|
326
|
+
wp-env status --config=./staging.json
|
|
327
|
+
|
|
328
|
+
# Stop specific environment
|
|
329
|
+
wp-env stop --config=./staging.json
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Each config file gets its own isolated Docker containers and data, so changes in one environment don't affect the other.
|
|
333
|
+
|
|
298
334
|
### `wp-env start`
|
|
299
335
|
|
|
300
336
|
The start command installs and initializes the WordPress environment, which includes downloading any specified remote sources. By default, `wp-env` will not update or re-configure the environment except when the configuration file changes. Tell `wp-env` to update sources and apply the configuration options again with `wp-env start --update`. This will not overwrite any existing content.
|
package/lib/cli.js
CHANGED
|
@@ -101,6 +101,11 @@ module.exports = function cli() {
|
|
|
101
101
|
describe: 'Enable debug output.',
|
|
102
102
|
default: false,
|
|
103
103
|
} );
|
|
104
|
+
yargs.option( 'config', {
|
|
105
|
+
type: 'string',
|
|
106
|
+
describe: 'Path to a custom .wp-env.json configuration file.',
|
|
107
|
+
requiresArg: true,
|
|
108
|
+
} );
|
|
104
109
|
|
|
105
110
|
yargs.parserConfiguration( {
|
|
106
111
|
// Treats unknown options as arguments for commands to deal with instead of discarding them.
|
package/lib/commands/clean.js
CHANGED
|
@@ -26,16 +26,18 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
26
26
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
27
27
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
28
28
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
29
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
29
30
|
*/
|
|
30
31
|
module.exports = async function clean( {
|
|
31
32
|
environment,
|
|
32
33
|
spinner,
|
|
33
34
|
scripts,
|
|
34
35
|
debug,
|
|
36
|
+
config: customConfigPath,
|
|
35
37
|
} ) {
|
|
36
38
|
spinner.warn( 'The `clean` command is deprecated. Use `reset` instead.' );
|
|
37
39
|
|
|
38
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
40
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
39
41
|
const runtime = getRuntime(
|
|
40
42
|
await detectRuntime( config.workDirectoryPath )
|
|
41
43
|
);
|
package/lib/commands/cleanup.js
CHANGED
|
@@ -19,14 +19,21 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
19
19
|
* Removes Docker containers, volumes, networks, and local files,
|
|
20
20
|
* but preserves Docker images for faster re-starts.
|
|
21
21
|
*
|
|
22
|
-
* @param {Object}
|
|
23
|
-
* @param {Object}
|
|
24
|
-
* @param {boolean}
|
|
25
|
-
* @param {boolean}
|
|
26
|
-
* @param {boolean}
|
|
22
|
+
* @param {Object} options
|
|
23
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
24
|
+
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
25
|
+
* @param {boolean} options.force If true, skips the confirmation prompt.
|
|
26
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
27
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
27
28
|
*/
|
|
28
|
-
module.exports = async function cleanup( {
|
|
29
|
-
|
|
29
|
+
module.exports = async function cleanup( {
|
|
30
|
+
spinner,
|
|
31
|
+
scripts,
|
|
32
|
+
force,
|
|
33
|
+
debug,
|
|
34
|
+
config: customConfigPath,
|
|
35
|
+
} ) {
|
|
36
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
30
37
|
|
|
31
38
|
try {
|
|
32
39
|
await fs.readdir( config.workDirectoryPath );
|
|
@@ -35,7 +42,9 @@ module.exports = async function cleanup( { spinner, scripts, force, debug } ) {
|
|
|
35
42
|
return;
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
const runtime = getRuntime(
|
|
45
|
+
const runtime = getRuntime(
|
|
46
|
+
await detectRuntime( config.workDirectoryPath )
|
|
47
|
+
);
|
|
39
48
|
|
|
40
49
|
spinner.info( runtime.getCleanupWarningMessage() );
|
|
41
50
|
|
package/lib/commands/destroy.js
CHANGED
|
@@ -16,14 +16,21 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
16
16
|
/**
|
|
17
17
|
* Destroy the development server.
|
|
18
18
|
*
|
|
19
|
-
* @param {Object}
|
|
20
|
-
* @param {Object}
|
|
21
|
-
* @param {boolean}
|
|
22
|
-
* @param {boolean}
|
|
23
|
-
* @param {boolean}
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
21
|
+
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
22
|
+
* @param {boolean} options.force If true, skips the confirmation prompt.
|
|
23
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
24
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
24
25
|
*/
|
|
25
|
-
module.exports = async function destroy( {
|
|
26
|
-
|
|
26
|
+
module.exports = async function destroy( {
|
|
27
|
+
spinner,
|
|
28
|
+
scripts,
|
|
29
|
+
force,
|
|
30
|
+
debug,
|
|
31
|
+
config: customConfigPath,
|
|
32
|
+
} ) {
|
|
33
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
27
34
|
|
|
28
35
|
try {
|
|
29
36
|
await fs.readdir( config.workDirectoryPath );
|
package/lib/commands/logs.js
CHANGED
|
@@ -13,14 +13,21 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
13
13
|
/**
|
|
14
14
|
* Displays the Docker & PHP logs on the given environment.
|
|
15
15
|
*
|
|
16
|
-
* @param {Object}
|
|
17
|
-
* @param {Object}
|
|
18
|
-
* @param {Object}
|
|
19
|
-
* @param {Object}
|
|
20
|
-
* @param {boolean}
|
|
16
|
+
* @param {Object} options
|
|
17
|
+
* @param {Object} options.environment The environment to run the command in (develop or tests).
|
|
18
|
+
* @param {Object} options.watch If true, follow along with log output.
|
|
19
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
20
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
21
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
21
22
|
*/
|
|
22
|
-
module.exports = async function logs( {
|
|
23
|
-
|
|
23
|
+
module.exports = async function logs( {
|
|
24
|
+
environment,
|
|
25
|
+
watch,
|
|
26
|
+
spinner,
|
|
27
|
+
debug,
|
|
28
|
+
config: customConfigPath,
|
|
29
|
+
} ) {
|
|
30
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
24
31
|
const runtime = getRuntime(
|
|
25
32
|
await detectRuntime( config.workDirectoryPath )
|
|
26
33
|
);
|
package/lib/commands/reset.js
CHANGED
|
@@ -24,15 +24,19 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
24
24
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
25
25
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
26
26
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
27
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
27
28
|
*/
|
|
28
29
|
module.exports = async function reset( {
|
|
29
30
|
environment,
|
|
30
31
|
spinner,
|
|
31
32
|
scripts,
|
|
32
33
|
debug,
|
|
34
|
+
config: customConfigPath,
|
|
33
35
|
} ) {
|
|
34
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
35
|
-
const runtime = getRuntime(
|
|
36
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
37
|
+
const runtime = getRuntime(
|
|
38
|
+
await detectRuntime( config.workDirectoryPath )
|
|
39
|
+
);
|
|
36
40
|
|
|
37
41
|
await runtime.clean( config, { environment, spinner, debug } );
|
|
38
42
|
|
package/lib/commands/run.js
CHANGED
|
@@ -13,13 +13,14 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
13
13
|
/**
|
|
14
14
|
* Runs an arbitrary command on the given Docker container.
|
|
15
15
|
*
|
|
16
|
-
* @param {Object}
|
|
17
|
-
* @param {string}
|
|
18
|
-
* @param {string[]}
|
|
19
|
-
* @param {string[]}
|
|
20
|
-
* @param {string}
|
|
21
|
-
* @param {Object}
|
|
22
|
-
* @param {boolean}
|
|
16
|
+
* @param {Object} options
|
|
17
|
+
* @param {string} options.container The Docker container to run the command on.
|
|
18
|
+
* @param {string[]} options.command The command to run.
|
|
19
|
+
* @param {string[]} options.'--' Any arguments that were passed after a double dash.
|
|
20
|
+
* @param {string} options.envCwd The working directory for the command to be executed from.
|
|
21
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
22
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
23
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
23
24
|
*/
|
|
24
25
|
module.exports = async function run( {
|
|
25
26
|
container,
|
|
@@ -28,8 +29,9 @@ module.exports = async function run( {
|
|
|
28
29
|
envCwd,
|
|
29
30
|
spinner,
|
|
30
31
|
debug,
|
|
32
|
+
config: customConfigPath,
|
|
31
33
|
} ) {
|
|
32
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
34
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
33
35
|
const runtime = getRuntime(
|
|
34
36
|
await detectRuntime( config.workDirectoryPath )
|
|
35
37
|
);
|
package/lib/commands/start.js
CHANGED
|
@@ -21,14 +21,15 @@ const { getRuntime, getSavedRuntime, saveRuntime } = require( '../runtime' );
|
|
|
21
21
|
/**
|
|
22
22
|
* Starts the development server.
|
|
23
23
|
*
|
|
24
|
-
* @param {Object}
|
|
25
|
-
* @param {Object}
|
|
26
|
-
* @param {boolean}
|
|
27
|
-
* @param {string}
|
|
28
|
-
* @param {string}
|
|
29
|
-
* @param {boolean}
|
|
30
|
-
* @param {boolean}
|
|
31
|
-
* @param {string}
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
26
|
+
* @param {boolean} options.update If true, update sources.
|
|
27
|
+
* @param {string} options.xdebug The Xdebug mode to set.
|
|
28
|
+
* @param {string} options.spx The SPX mode to set.
|
|
29
|
+
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
30
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
31
|
+
* @param {string} options.runtime The runtime to use ('docker' or 'playground').
|
|
32
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
32
33
|
*/
|
|
33
34
|
module.exports = async function start( {
|
|
34
35
|
spinner,
|
|
@@ -38,6 +39,7 @@ module.exports = async function start( {
|
|
|
38
39
|
scripts,
|
|
39
40
|
debug,
|
|
40
41
|
runtime: runtimeName = 'docker',
|
|
42
|
+
config: customConfigPath,
|
|
41
43
|
} ) {
|
|
42
44
|
spinner.text = 'Reading configuration.';
|
|
43
45
|
|
|
@@ -48,7 +50,7 @@ module.exports = async function start( {
|
|
|
48
50
|
await checkForLegacyInstall( spinner );
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
53
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
52
54
|
config.debug = debug;
|
|
53
55
|
|
|
54
56
|
// Check if switching runtimes and prompt user to destroy old environment first.
|
package/lib/commands/status.js
CHANGED
|
@@ -39,15 +39,21 @@ function isEnvironmentInitialized( config ) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Outputs the status of the wp-env environment.
|
|
41
41
|
*
|
|
42
|
-
* @param {Object}
|
|
43
|
-
* @param {Object}
|
|
44
|
-
* @param {boolean}
|
|
45
|
-
* @param {boolean}
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
44
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
45
|
+
* @param {boolean} options.json True to output as JSON.
|
|
46
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
46
47
|
*/
|
|
47
|
-
module.exports = async function status( {
|
|
48
|
+
module.exports = async function status( {
|
|
49
|
+
spinner,
|
|
50
|
+
debug,
|
|
51
|
+
json,
|
|
52
|
+
config: customConfigPath,
|
|
53
|
+
} ) {
|
|
48
54
|
spinner.text = 'Getting environment status.';
|
|
49
55
|
|
|
50
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
56
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
51
57
|
|
|
52
58
|
// Check if environment is initialized by looking for runtime-specific files.
|
|
53
59
|
// We check for these files specifically because the work directory may exist
|
|
@@ -70,7 +76,7 @@ module.exports = async function status( { spinner, debug, json } ) {
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
// Detect and get runtime.
|
|
73
|
-
const runtimeName = detectRuntime( config.workDirectoryPath );
|
|
79
|
+
const runtimeName = await detectRuntime( config.workDirectoryPath );
|
|
74
80
|
const runtime = getRuntime( runtimeName );
|
|
75
81
|
|
|
76
82
|
// Get status from runtime.
|
package/lib/commands/stop.js
CHANGED
|
@@ -13,12 +13,17 @@ const { getRuntime, detectRuntime } = require( '../runtime' );
|
|
|
13
13
|
/**
|
|
14
14
|
* Stops the development server.
|
|
15
15
|
*
|
|
16
|
-
* @param {Object}
|
|
17
|
-
* @param {Object}
|
|
18
|
-
* @param {boolean}
|
|
16
|
+
* @param {Object} options
|
|
17
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
18
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
19
|
+
* @param {string|null} options.config Path to a custom .wp-env.json configuration file.
|
|
19
20
|
*/
|
|
20
|
-
module.exports = async function stop( {
|
|
21
|
-
|
|
21
|
+
module.exports = async function stop( {
|
|
22
|
+
spinner,
|
|
23
|
+
debug,
|
|
24
|
+
config: customConfigPath,
|
|
25
|
+
} ) {
|
|
26
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
22
27
|
const runtime = getRuntime(
|
|
23
28
|
await detectRuntime( config.workDirectoryPath )
|
|
24
29
|
);
|
|
@@ -11,6 +11,7 @@ const fs = require( 'fs' ).promises;
|
|
|
11
11
|
const getCacheDirectory = require( './get-cache-directory' );
|
|
12
12
|
const md5 = require( '../md5' );
|
|
13
13
|
const { parseConfig, getConfigFilePath } = require( './parse-config' );
|
|
14
|
+
const { ValidationError } = require( './validate-config' );
|
|
14
15
|
const postProcessConfig = require( './post-process-config' );
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -35,12 +36,31 @@ const postProcessConfig = require( './post-process-config' );
|
|
|
35
36
|
/**
|
|
36
37
|
* Loads any configuration from a given directory.
|
|
37
38
|
*
|
|
38
|
-
* @param {string}
|
|
39
|
+
* @param {string} configDirectoryPath The directory we want to load the config from.
|
|
40
|
+
* @param {string|null} customConfigPath Optional custom config file path.
|
|
39
41
|
*
|
|
40
42
|
* @return {Promise<WPConfig>} The config object we've loaded.
|
|
41
43
|
*/
|
|
42
|
-
module.exports = async function loadConfig(
|
|
43
|
-
|
|
44
|
+
module.exports = async function loadConfig(
|
|
45
|
+
configDirectoryPath,
|
|
46
|
+
customConfigPath = null
|
|
47
|
+
) {
|
|
48
|
+
const configFilePath = getConfigFilePath(
|
|
49
|
+
configDirectoryPath,
|
|
50
|
+
'local',
|
|
51
|
+
customConfigPath
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// If a custom config path was provided, verify the file exists.
|
|
55
|
+
if ( customConfigPath ) {
|
|
56
|
+
try {
|
|
57
|
+
await fs.stat( configFilePath );
|
|
58
|
+
} catch ( error ) {
|
|
59
|
+
throw new ValidationError(
|
|
60
|
+
`Config file not found: ${ configFilePath }`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
44
64
|
|
|
45
65
|
const cacheDirectoryPath = path.resolve(
|
|
46
66
|
await getCacheDirectory(),
|
|
@@ -49,7 +69,11 @@ module.exports = async function loadConfig( configDirectoryPath ) {
|
|
|
49
69
|
|
|
50
70
|
// Parse any configuration we found in the given directory.
|
|
51
71
|
// This comes merged and prepared for internal consumption.
|
|
52
|
-
let config = await parseConfig(
|
|
72
|
+
let config = await parseConfig(
|
|
73
|
+
configDirectoryPath,
|
|
74
|
+
cacheDirectoryPath,
|
|
75
|
+
customConfigPath
|
|
76
|
+
);
|
|
53
77
|
|
|
54
78
|
// Make sure to perform any additional post-processing that
|
|
55
79
|
// may be needed before the config object is ready for
|
|
@@ -64,9 +88,14 @@ module.exports = async function loadConfig( configDirectoryPath ) {
|
|
|
64
88
|
),
|
|
65
89
|
configDirectoryPath,
|
|
66
90
|
workDirectoryPath: cacheDirectoryPath,
|
|
91
|
+
customConfigPath,
|
|
67
92
|
detectedLocalConfig: await hasLocalConfig( [
|
|
68
93
|
configFilePath,
|
|
69
|
-
getConfigFilePath(
|
|
94
|
+
getConfigFilePath(
|
|
95
|
+
configDirectoryPath,
|
|
96
|
+
'override',
|
|
97
|
+
customConfigPath
|
|
98
|
+
),
|
|
70
99
|
] ),
|
|
71
100
|
lifecycleScripts: config.lifecycleScripts,
|
|
72
101
|
env: config.env,
|
|
@@ -111,22 +111,27 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
|
|
|
111
111
|
* constructs an object in the format used internally.
|
|
112
112
|
*
|
|
113
113
|
*
|
|
114
|
-
* @param {string}
|
|
115
|
-
* @param {string}
|
|
114
|
+
* @param {string} configDirectoryPath A path to the directory we are parsing the config for.
|
|
115
|
+
* @param {string} cacheDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
116
|
+
* @param {string|null} customConfigPath Optional custom config file path.
|
|
116
117
|
*
|
|
117
118
|
* @return {Promise<WPRootConfig>} Parsed config.
|
|
118
119
|
*/
|
|
119
|
-
async function parseConfig(
|
|
120
|
+
async function parseConfig(
|
|
121
|
+
configDirectoryPath,
|
|
122
|
+
cacheDirectoryPath,
|
|
123
|
+
customConfigPath = null
|
|
124
|
+
) {
|
|
120
125
|
// The local config will be used to override any defaults.
|
|
121
126
|
const localConfig = await parseConfigFile(
|
|
122
|
-
getConfigFilePath( configDirectoryPath ),
|
|
127
|
+
getConfigFilePath( configDirectoryPath, 'local', customConfigPath ),
|
|
123
128
|
{ cacheDirectoryPath }
|
|
124
129
|
);
|
|
125
130
|
|
|
126
131
|
// Any overrides that can be used in place
|
|
127
132
|
// of properties set by the local config.
|
|
128
133
|
const overrideConfig = await parseConfigFile(
|
|
129
|
-
getConfigFilePath( configDirectoryPath, 'override' ),
|
|
134
|
+
getConfigFilePath( configDirectoryPath, 'override', customConfigPath ),
|
|
130
135
|
{ cacheDirectoryPath }
|
|
131
136
|
);
|
|
132
137
|
|
|
@@ -161,27 +166,37 @@ async function parseConfig( configDirectoryPath, cacheDirectoryPath ) {
|
|
|
161
166
|
/**
|
|
162
167
|
* Gets the path to the config file.
|
|
163
168
|
*
|
|
164
|
-
* @param {string}
|
|
165
|
-
* @param {string}
|
|
169
|
+
* @param {string} configDirectoryPath The path to the directory containing config files.
|
|
170
|
+
* @param {string} type The type of config file we're interested in: 'local' or 'override'.
|
|
171
|
+
* @param {string|null} customConfigPath Optional custom config file path (only used for 'local' type).
|
|
166
172
|
*
|
|
167
173
|
* @return {string} The path to the config file.
|
|
168
174
|
*/
|
|
169
|
-
function getConfigFilePath(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
175
|
+
function getConfigFilePath(
|
|
176
|
+
configDirectoryPath,
|
|
177
|
+
type = 'local',
|
|
178
|
+
customConfigPath = null
|
|
179
|
+
) {
|
|
180
|
+
// If a custom config path is provided for the local config, use it.
|
|
181
|
+
if ( type === 'local' && customConfigPath ) {
|
|
182
|
+
return path.resolve( customConfigPath );
|
|
183
|
+
}
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
// For override, derive from custom config: staging.json -> staging.override.json
|
|
186
|
+
if ( type === 'override' && customConfigPath ) {
|
|
187
|
+
const resolved = path.resolve( customConfigPath );
|
|
188
|
+
const ext = path.extname( resolved );
|
|
189
|
+
const base = path.basename( resolved, ext );
|
|
190
|
+
const dir = path.dirname( resolved );
|
|
191
|
+
return path.join( dir, `${ base }.override${ ext }` );
|
|
192
|
+
}
|
|
181
193
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
194
|
+
// Default behavior.
|
|
195
|
+
const fileName =
|
|
196
|
+
type === 'local' ? '.wp-env.json' : '.wp-env.override.json';
|
|
197
|
+
|
|
198
|
+
if ( type !== 'local' && type !== 'override' ) {
|
|
199
|
+
throw new Error( `Invalid config file type "${ type }.` );
|
|
185
200
|
}
|
|
186
201
|
|
|
187
202
|
return path.resolve( configDirectoryPath, fileName );
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
exports[`Config Integration should load local and override configuration files 1`] = `
|
|
4
4
|
{
|
|
5
5
|
"configDirectoryPath": "/test/gutenberg",
|
|
6
|
+
"customConfigPath": null,
|
|
6
7
|
"detectedLocalConfig": true,
|
|
7
8
|
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
8
9
|
"env": {
|
|
@@ -84,6 +85,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
84
85
|
exports[`Config Integration should load local configuration file 1`] = `
|
|
85
86
|
{
|
|
86
87
|
"configDirectoryPath": "/test/gutenberg",
|
|
88
|
+
"customConfigPath": null,
|
|
87
89
|
"detectedLocalConfig": true,
|
|
88
90
|
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
89
91
|
"env": {
|
|
@@ -165,6 +167,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
165
167
|
exports[`Config Integration should use default configuration 1`] = `
|
|
166
168
|
{
|
|
167
169
|
"configDirectoryPath": "/test/gutenberg",
|
|
170
|
+
"customConfigPath": null,
|
|
168
171
|
"detectedLocalConfig": true,
|
|
169
172
|
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
170
173
|
"env": {
|
|
@@ -246,6 +249,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
246
249
|
exports[`Config Integration should use environment variables over local and override configuration files 1`] = `
|
|
247
250
|
{
|
|
248
251
|
"configDirectoryPath": "/test/gutenberg",
|
|
252
|
+
"customConfigPath": null,
|
|
249
253
|
"detectedLocalConfig": true,
|
|
250
254
|
"dockerComposeConfigPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338/docker-compose.yml",
|
|
251
255
|
"env": {
|
|
@@ -107,6 +107,7 @@ class DockerRuntime {
|
|
|
107
107
|
xdebug,
|
|
108
108
|
spx,
|
|
109
109
|
writeChanges: true,
|
|
110
|
+
customConfigPath: config.customConfigPath,
|
|
110
111
|
} );
|
|
111
112
|
|
|
112
113
|
// Check if the hash of the config has changed. If so, run configuration.
|
|
@@ -375,6 +376,7 @@ class DockerRuntime {
|
|
|
375
376
|
const { dockerComposeConfigPath } = await initConfig( {
|
|
376
377
|
spinner,
|
|
377
378
|
debug,
|
|
379
|
+
customConfigPath: config.customConfigPath,
|
|
378
380
|
} );
|
|
379
381
|
|
|
380
382
|
spinner.text = 'Stopping WordPress.';
|
|
@@ -452,7 +454,11 @@ class DockerRuntime {
|
|
|
452
454
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
453
455
|
*/
|
|
454
456
|
async clean( config, { environment, spinner, debug } ) {
|
|
455
|
-
const fullConfig = await initConfig( {
|
|
457
|
+
const fullConfig = await initConfig( {
|
|
458
|
+
spinner,
|
|
459
|
+
debug,
|
|
460
|
+
customConfigPath: config.customConfigPath,
|
|
461
|
+
} );
|
|
456
462
|
|
|
457
463
|
const description = `${ environment } environment${
|
|
458
464
|
environment === 'all' ? 's' : ''
|
|
@@ -525,7 +531,11 @@ class DockerRuntime {
|
|
|
525
531
|
// Validate the container name (throws for deprecated containers)
|
|
526
532
|
validateRunContainer( container );
|
|
527
533
|
|
|
528
|
-
const fullConfig = await initConfig( {
|
|
534
|
+
const fullConfig = await initConfig( {
|
|
535
|
+
spinner,
|
|
536
|
+
debug,
|
|
537
|
+
customConfigPath: config.customConfigPath,
|
|
538
|
+
} );
|
|
529
539
|
|
|
530
540
|
// Shows a contextual tip for the given command.
|
|
531
541
|
const joinedCommand = command.join( ' ' );
|
|
@@ -552,7 +562,11 @@ class DockerRuntime {
|
|
|
552
562
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
553
563
|
*/
|
|
554
564
|
async logs( config, { environment, watch, spinner, debug } ) {
|
|
555
|
-
const fullConfig = await initConfig( {
|
|
565
|
+
const fullConfig = await initConfig( {
|
|
566
|
+
spinner,
|
|
567
|
+
debug,
|
|
568
|
+
customConfigPath: config.customConfigPath,
|
|
569
|
+
} );
|
|
556
570
|
|
|
557
571
|
// If we show text while watching the logs, it will continue showing up every
|
|
558
572
|
// few lines in the logs as they happen, which isn't a good look. So only
|
|
@@ -621,7 +635,11 @@ class DockerRuntime {
|
|
|
621
635
|
async getStatus( config, { spinner, debug } ) {
|
|
622
636
|
spinner.text = 'Getting environment status.';
|
|
623
637
|
|
|
624
|
-
const fullConfig = await initConfig( {
|
|
638
|
+
const fullConfig = await initConfig( {
|
|
639
|
+
spinner,
|
|
640
|
+
debug,
|
|
641
|
+
customConfigPath: config.customConfigPath,
|
|
642
|
+
} );
|
|
625
643
|
const dockerComposeConfig = {
|
|
626
644
|
config: fullConfig.dockerComposeConfigPath,
|
|
627
645
|
log: debug,
|
|
@@ -22,16 +22,17 @@ const buildDockerComposeConfig = require( './build-docker-compose-config' );
|
|
|
22
22
|
* ./.wp-env.json, creates ~/.wp-env, ~/.wp-env/docker-compose.yml, and
|
|
23
23
|
* ~/.wp-env/Dockerfile.
|
|
24
24
|
*
|
|
25
|
-
* @param {Object}
|
|
26
|
-
* @param {Object}
|
|
27
|
-
* @param {boolean}
|
|
28
|
-
* @param {string}
|
|
29
|
-
* @param {string}
|
|
30
|
-
* @param {boolean}
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
25
|
+
* @param {Object} options
|
|
26
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
27
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
28
|
+
* @param {string} options.xdebug The Xdebug mode to set. Defaults to "off".
|
|
29
|
+
* @param {string} options.spx The SPX mode to set. Defaults to "off".
|
|
30
|
+
* @param {boolean} options.writeChanges If true, writes the parsed config to the
|
|
31
|
+
* required docker files like docker-compose
|
|
32
|
+
* and Dockerfile. By default, this is false
|
|
33
|
+
* and only the `start` command writes any
|
|
34
|
+
* changes.
|
|
35
|
+
* @param {string|null} options.customConfigPath Path to a custom .wp-env.json configuration file.
|
|
35
36
|
* @return {WPConfig} The-env config object.
|
|
36
37
|
*/
|
|
37
38
|
module.exports = async function initConfig( {
|
|
@@ -40,8 +41,9 @@ module.exports = async function initConfig( {
|
|
|
40
41
|
xdebug = 'off',
|
|
41
42
|
spx = 'off',
|
|
42
43
|
writeChanges = false,
|
|
44
|
+
customConfigPath = null,
|
|
43
45
|
} ) {
|
|
44
|
-
const config = await loadConfig( path.resolve( '.' ) );
|
|
46
|
+
const config = await loadConfig( path.resolve( '.' ), customConfigPath );
|
|
45
47
|
config.debug = debug;
|
|
46
48
|
|
|
47
49
|
// Adding this to the config allows the start command to understand that the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "11.0.1-next.v.
|
|
3
|
+
"version": "11.0.1-next.v.202602111440.0+a307a2e35",
|
|
4
4
|
"description": "A zero-config, self contained local WordPress environment for development and testing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"scripts": {
|
|
65
65
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "e0a2324a9690e55f4101d61113f4bbbf240b55ed"
|
|
68
68
|
}
|