@wordpress/env 11.0.1-next.v.202602111440.0 → 11.0.1-next.v.202602200903.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 +50 -70
- package/lib/cli.js +2 -2
- package/lib/commands/start.js +7 -4
- package/lib/config/load-config.js +1 -0
- package/lib/config/parse-config.js +22 -1
- package/lib/config/post-process-config.js +38 -16
- package/lib/config/test/__snapshots__/config-integration.js.snap +12 -0
- package/lib/config/test/parse-config.js +65 -0
- package/lib/config/test/post-process-config.js +52 -0
- package/lib/runtime/docker/build-docker-compose-config.js +151 -139
- package/lib/runtime/docker/download-sources.js +5 -1
- package/lib/runtime/docker/download-wp-phpunit.js +3 -0
- package/lib/runtime/docker/index.js +141 -69
- package/lib/runtime/docker/init-config.js +7 -1
- package/lib/runtime/docker/wordpress.js +5 -0
- package/lib/runtime/playground/blueprint-builder.js +19 -19
- package/lib/runtime/playground/index.js +40 -8
- package/lib/test/build-docker-compose-config.js +64 -0
- package/lib/test/cli.js +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -39,17 +39,16 @@ $ wp-env start --runtime=playground
|
|
|
39
39
|
| Feature | Docker | Playground |
|
|
40
40
|
|---------|--------|------------|
|
|
41
41
|
| Requires Docker | Yes | No |
|
|
42
|
-
| Test environment | Yes | No |
|
|
43
42
|
| Xdebug | Yes | Yes |
|
|
44
43
|
| SPX profiling | Yes | No |
|
|
45
|
-
| phpMyAdmin | Yes |
|
|
44
|
+
| phpMyAdmin | Yes | Yes |
|
|
46
45
|
| MySQL database | Yes | No (SQLite) |
|
|
47
46
|
| Multisite | Yes | Yes |
|
|
48
47
|
| Custom PHP version | Yes | Yes |
|
|
49
48
|
| Plugin/theme mounting | Yes | Yes |
|
|
50
49
|
| `wp-env run` command | Yes | No |
|
|
51
50
|
|
|
52
|
-
The Playground runtime is ideal for quick testing or environments where Docker is unavailable. However, it lacks some features available in the Docker runtime, such as the
|
|
51
|
+
The Playground runtime is ideal for quick testing or environments where Docker is unavailable. However, it lacks some features available in the Docker runtime, such as the `run` command for executing arbitrary commands.
|
|
53
52
|
|
|
54
53
|
Once started with a runtime, wp-env will automatically detect and use the same runtime for subsequent commands (`stop`, `destroy`, etc.) until the environment is destroyed.
|
|
55
54
|
|
|
@@ -136,7 +135,7 @@ First, check that `wp-env` is running. One way to do this is to have Docker prin
|
|
|
136
135
|
$ docker ps
|
|
137
136
|
```
|
|
138
137
|
|
|
139
|
-
In this table, by default, you should see
|
|
138
|
+
In this table, by default, you should see two entries: `wordpress` with port 8888 and `mariadb`.
|
|
140
139
|
|
|
141
140
|
### 2. Check the port number
|
|
142
141
|
|
|
@@ -214,9 +213,9 @@ While we do provide a default `wp-tests-config.php` file within the environment,
|
|
|
214
213
|
|
|
215
214
|
## Using `composer`, `phpunit`, and `wp-cli` tools.
|
|
216
215
|
|
|
217
|
-
For ease of use, Composer, PHPUnit, and wp-cli are available
|
|
216
|
+
For ease of use, Composer, PHPUnit, and wp-cli are available in the environment. To run these executables, use `wp-env run <container> <tool> <command>`. For example, `wp-env run cli composer install`, or `wp-env run cli phpunit`. You can also access various shells like `wp-env run cli bash` or `wp-env run cli wp shell`.
|
|
218
217
|
|
|
219
|
-
|
|
218
|
+
The `cli` and `wordpress` containers share a database and mapped volumes, but more tools are available in the `cli` container. For test isolation, use `--config` with a separate config file to run a parallel environment (see [Running parallel environments](#running-parallel-environments)).
|
|
220
219
|
|
|
221
220
|
By default, the cwd of the run command is the root of the WordPress install. If you're working on a plugin, you likely need to pass `--env-cwd` to make sure composer/phpunit commands are executed relative to the plugin you're working on. For example, `wp-env run cli --env-cwd=wp-content/plugins/gutenberg composer install`.
|
|
222
221
|
|
|
@@ -304,12 +303,15 @@ These options apply to all `wp-env` commands:
|
|
|
304
303
|
--config Path to a custom .wp-env.json configuration file. [string]
|
|
305
304
|
```
|
|
306
305
|
|
|
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.
|
|
306
|
+
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. Each config file gets its own isolated set of Docker containers and data.
|
|
308
307
|
|
|
309
|
-
When using a custom config file, the override file is derived from its name. For example:
|
|
308
|
+
When using a custom config file, the override file is derived from its name by inserting `.override` before the extension. For example:
|
|
309
|
+
- `--config=.wp-env.test.json` will look for `.wp-env.test.override.json`
|
|
310
310
|
- `--config=staging.json` will look for `staging.override.json`
|
|
311
311
|
- `--config=./configs/dev.wp-env.json` will look for `./configs/dev.wp-env.override.json`
|
|
312
312
|
|
|
313
|
+
Override files for custom configs work the same way as `.wp-env.override.json` does for the default config (see [.wp-env.override.json](#wp-envoverridejson)).
|
|
314
|
+
|
|
313
315
|
#### Running parallel environments
|
|
314
316
|
|
|
315
317
|
You can run multiple wp-env environments from the same folder by using different config files and ports:
|
|
@@ -319,7 +321,7 @@ You can run multiple wp-env environments from the same folder by using different
|
|
|
319
321
|
wp-env start
|
|
320
322
|
|
|
321
323
|
# Start second environment with custom config on different ports
|
|
322
|
-
WP_ENV_PORT=8890
|
|
324
|
+
WP_ENV_PORT=8890 wp-env start --config=./staging.json
|
|
323
325
|
|
|
324
326
|
# Check status of each environment
|
|
325
327
|
wp-env status
|
|
@@ -339,8 +341,7 @@ The start command installs and initializes the WordPress environment, which incl
|
|
|
339
341
|
wp-env start
|
|
340
342
|
|
|
341
343
|
Starts WordPress for development on port 8888 (http://localhost:8888)
|
|
342
|
-
(override with WP_ENV_PORT)
|
|
343
|
-
(override with WP_ENV_TESTS_PORT). The current working directory must be a
|
|
344
|
+
(override with WP_ENV_PORT). The current working directory must be a
|
|
344
345
|
WordPress installation, a plugin, a theme, or contain a .wp-env.json file. After
|
|
345
346
|
first install, use the '--update' flag to download updates to mapped sources and
|
|
346
347
|
to re-apply WordPress configuration options.
|
|
@@ -370,7 +371,7 @@ Options:
|
|
|
370
371
|
```sh
|
|
371
372
|
wp-env stop
|
|
372
373
|
|
|
373
|
-
Stops running WordPress for development and
|
|
374
|
+
Stops running WordPress for development and frees the ports.
|
|
374
375
|
|
|
375
376
|
Options:
|
|
376
377
|
--debug Enable debug output. [boolean] [default: false]
|
|
@@ -385,7 +386,7 @@ Resets the WordPress databases.
|
|
|
385
386
|
|
|
386
387
|
Positionals:
|
|
387
388
|
environment Which environments' databases to reset.
|
|
388
|
-
|
|
389
|
+
[string] [choices: "all", "development", "tests"] [default: "development"]
|
|
389
390
|
|
|
390
391
|
Options:
|
|
391
392
|
--debug Enable debug output. [boolean] [default: false]
|
|
@@ -421,8 +422,8 @@ containers.
|
|
|
421
422
|
|
|
422
423
|
Positionals:
|
|
423
424
|
container The Docker service to run the command on.
|
|
424
|
-
|
|
425
|
-
|
|
425
|
+
[string] [required] [choices: "mysql", "wordpress", "cli", "composer",
|
|
426
|
+
"phpmyadmin"]
|
|
426
427
|
command The command to run. [required]
|
|
427
428
|
|
|
428
429
|
Options:
|
|
@@ -446,29 +447,27 @@ ID user_login display_name user_email user_registered roles
|
|
|
446
447
|
✔ Ran `wp user list` in 'cli'. (in 2s 374ms)
|
|
447
448
|
```
|
|
448
449
|
|
|
449
|
-
#### Creating a post on the
|
|
450
|
+
#### Creating a post on the development instance:
|
|
450
451
|
|
|
451
452
|
```sh
|
|
452
|
-
wp-env run
|
|
453
|
+
wp-env run cli "wp post create --post_type=page --post_title='Ready'"
|
|
453
454
|
|
|
454
|
-
ℹ Starting 'wp post create --post_type=page --post_title='Ready'' on the
|
|
455
|
+
ℹ Starting 'wp post create --post_type=page --post_title='Ready'' on the cli container.
|
|
455
456
|
|
|
456
457
|
Success: Created post 5.
|
|
457
|
-
✔ Ran `wp post create --post_type=page --post_title='Ready'` in '
|
|
458
|
+
✔ Ran `wp post create --post_type=page --post_title='Ready'` in 'cli'. (in 3s 293ms)
|
|
458
459
|
```
|
|
459
460
|
|
|
460
|
-
#### Opening the WordPress shell
|
|
461
|
+
#### Opening the WordPress shell and running PHP commands:
|
|
461
462
|
|
|
462
463
|
```sh
|
|
463
|
-
wp-env run
|
|
464
|
-
ℹ Starting 'wp shell' on the
|
|
464
|
+
wp-env run cli wp shell
|
|
465
|
+
ℹ Starting 'wp shell' on the cli container. Exit the WordPress shell with ctrl-c.
|
|
465
466
|
|
|
466
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_mysql_1 ... done
|
|
467
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_tests-wordpress_1 ... done
|
|
468
467
|
wp> echo( 'hello world!' );
|
|
469
468
|
hello world!
|
|
470
469
|
wp> ^C
|
|
471
|
-
✔ Ran `wp shell` in '
|
|
470
|
+
✔ Ran `wp shell` in 'cli'. (in 16s 400ms)
|
|
472
471
|
```
|
|
473
472
|
|
|
474
473
|
#### Installing a plugin or theme on the development instance
|
|
@@ -489,7 +488,7 @@ Success: Installed 1 of 1 plugins.
|
|
|
489
488
|
|
|
490
489
|
#### Changing the permalink structure
|
|
491
490
|
|
|
492
|
-
|
|
491
|
+
Pretty permalinks are enabled by default using the `/%year%/%monthnum%/%day%/%postname%/` structure, matching the WordPress core behavior on fresh installs. You can change the structure if needed:
|
|
493
492
|
|
|
494
493
|
**Examples**
|
|
495
494
|
|
|
@@ -542,7 +541,7 @@ displays PHP and Docker logs for given WordPress environment.
|
|
|
542
541
|
|
|
543
542
|
Positionals:
|
|
544
543
|
environment Which environment to display the logs from.
|
|
545
|
-
|
|
544
|
+
[string] [choices: "development"] [default: "development"]
|
|
546
545
|
|
|
547
546
|
Options:
|
|
548
547
|
--debug Enable debug output. [boolean] [default: false]
|
|
@@ -569,7 +568,6 @@ environment:
|
|
|
569
568
|
- xdebug: off
|
|
570
569
|
- http port: 8888
|
|
571
570
|
- mysql port: 13306
|
|
572
|
-
- test http port: 8889
|
|
573
571
|
```
|
|
574
572
|
|
|
575
573
|
```sh
|
|
@@ -585,7 +583,7 @@ Options:
|
|
|
585
583
|
|
|
586
584
|
You can customize the WordPress installation, plugins and themes that the development environment will use by specifying a `.wp-env.json` file in the directory that you run `wp-env` from.
|
|
587
585
|
|
|
588
|
-
`.wp-env.json` supports
|
|
586
|
+
`.wp-env.json` supports the following fields:
|
|
589
587
|
|
|
590
588
|
| Field | Type | Default | Description |
|
|
591
589
|
|----------------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
|
@@ -593,16 +591,17 @@ You can customize the WordPress installation, plugins and themes that the develo
|
|
|
593
591
|
| `"phpVersion"` | `string\|null` | `null` | The PHP version to use. If `null` is specified, `wp-env` will use the default version used with production release of WordPress. |
|
|
594
592
|
| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. |
|
|
595
593
|
| `"themes"` | `string[]` | `[]` | A list of themes to install in the environment. |
|
|
596
|
-
| `"port"` | `integer` | `8888`
|
|
597
|
-
| `"
|
|
594
|
+
| `"port"` | `integer` | `8888` | The primary port number to use for the installation. You'll access the instance through the port: 'http://localhost:8888'. |
|
|
595
|
+
| `"testsEnvironment"` | `boolean` | `false` | _Deprecated._ Whether to create a separate test environment with its own database and containers. Use `--config` with a separate config file instead. |
|
|
598
596
|
| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. |
|
|
599
597
|
| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. |
|
|
600
|
-
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose.
|
|
601
|
-
| `"
|
|
598
|
+
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. |
|
|
599
|
+
| `"phpmyadmin"` | `boolean` | `false` | Whether to enable phpMyAdmin for database management. |
|
|
600
|
+
| `"phpmyadminPort"` | `integer` | `null` (randomly assigned) | The port number for phpMyAdmin (Docker only). Setting this also enables phpMyAdmin. |
|
|
602
601
|
| `"multisite"` | `boolean` | `false` | Whether to set up a multisite installation. |
|
|
603
602
|
| `"lifecycleScripts"` | `Object` | `"{}"` | Mapping of commands that should be executed at certain points in the lifecycle. |
|
|
604
603
|
|
|
605
|
-
_Note: the port number environment
|
|
604
|
+
_Note: the port number environment variable (`WP_ENV_PORT`) takes precedence over the .wp-env.json value._
|
|
606
605
|
|
|
607
606
|
Several types of strings can be passed into the `core`, `plugins`, `themes`, and `mappings` fields.
|
|
608
607
|
|
|
@@ -616,7 +615,7 @@ Several types of strings can be passed into the `core`, `plugins`, `themes`, and
|
|
|
616
615
|
|
|
617
616
|
Remote sources will be downloaded into a temporary directory located in `~/.wp-env`.
|
|
618
617
|
|
|
619
|
-
Additionally, the key `env` is available to override any of the above options on
|
|
618
|
+
Additionally, the key `env` is available to override any of the above options on the development environment. For example, take the following `.wp-env.json` file:
|
|
620
619
|
|
|
621
620
|
```json
|
|
622
621
|
{
|
|
@@ -628,29 +627,21 @@ Additionally, the key `env` is available to override any of the above options on
|
|
|
628
627
|
"env": {
|
|
629
628
|
"development": {
|
|
630
629
|
"themes": [ "./one-theme" ]
|
|
631
|
-
},
|
|
632
|
-
"tests": {
|
|
633
|
-
"config": {
|
|
634
|
-
"KEY_1": false
|
|
635
|
-
},
|
|
636
|
-
"port": 3000,
|
|
637
|
-
"mysqlPort": 13306,
|
|
638
|
-
"phpmyadminPort": 9001
|
|
639
630
|
}
|
|
640
631
|
}
|
|
641
632
|
}
|
|
642
633
|
```
|
|
643
634
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
On the tests instance, `cwd` is still mapped as a plugin, but no theme is mapped. Additionally, while KEY_2 is still set to false, KEY_1 is overridden and set to false. 3000 overrides the default port as well.
|
|
635
|
+
Here, `cwd` will be mapped as a plugin, `one-theme` will be mapped as a theme, KEY_1 will be set to true, and KEY_2 will be set to false.
|
|
647
636
|
|
|
648
|
-
|
|
637
|
+
For running a separate test environment, use `--config` with a separate config file instead of `env.tests` (see [Running parallel environments](#running-parallel-environments)).
|
|
649
638
|
|
|
650
639
|
## .wp-env.override.json
|
|
651
640
|
|
|
652
641
|
Any fields here will take precedence over .wp-env.json. This file is useful when ignored from version control, to persist local development overrides. Note that options like `plugins` and `themes` are not merged. As a result, if you set `plugins` in your override file, this will override all of the plugins listed in the base-level config. The only keys which are merged are `config` and `mappings`. This means that you can set your own wp-config values without losing any of the default values.
|
|
653
642
|
|
|
643
|
+
When using `--config` with a custom config file, the override file name is derived by inserting `.override` before the extension. For example, `.wp-env.test.json` will look for `.wp-env.test.override.json`.
|
|
644
|
+
|
|
654
645
|
## Default wp-config values.
|
|
655
646
|
|
|
656
647
|
On the development instance, these wp-config values are defined by default:
|
|
@@ -666,11 +657,9 @@ WP_SITEURL: 'http://localhost',
|
|
|
666
657
|
WP_HOME: 'http://localhost',
|
|
667
658
|
```
|
|
668
659
|
|
|
669
|
-
On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false.
|
|
670
|
-
|
|
671
660
|
These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely.
|
|
672
661
|
|
|
673
|
-
|
|
662
|
+
The values referencing a URL include the specified port. So if you set `port: 2000`, `WP_HOME` (for example) will be `http://localhost:2000`.
|
|
674
663
|
|
|
675
664
|
## Lifecycle Scripts
|
|
676
665
|
|
|
@@ -770,21 +759,19 @@ Since all plugins in the `plugins` key are activated by default, you should use
|
|
|
770
759
|
}
|
|
771
760
|
```
|
|
772
761
|
|
|
773
|
-
### Map a plugin only in
|
|
762
|
+
### Map a plugin only in a specific environment
|
|
774
763
|
|
|
775
|
-
If you need a plugin active in one environment but not
|
|
764
|
+
If you need a plugin active in one environment but not another, use `--config` with a separate config file. For example, create a `test.wp-env.json` that includes an extra test plugin:
|
|
776
765
|
|
|
777
766
|
```json
|
|
778
767
|
{
|
|
779
|
-
"plugins": [ "." ],
|
|
780
|
-
"
|
|
781
|
-
"tests": {
|
|
782
|
-
"plugins": [ ".", "path/to/test/plugin" ]
|
|
783
|
-
}
|
|
784
|
-
}
|
|
768
|
+
"plugins": [ ".", "path/to/test/plugin" ],
|
|
769
|
+
"port": 8889
|
|
785
770
|
}
|
|
786
771
|
```
|
|
787
772
|
|
|
773
|
+
Then start it with `wp-env start --config=test.wp-env.json`.
|
|
774
|
+
|
|
788
775
|
### Custom Port Numbers
|
|
789
776
|
|
|
790
777
|
You can tell `wp-env` to use a custom port number so that your instance does not conflict with other `wp-env` instances.
|
|
@@ -792,21 +779,15 @@ You can tell `wp-env` to use a custom port number so that your instance does not
|
|
|
792
779
|
```json
|
|
793
780
|
{
|
|
794
781
|
"plugins": [ "." ],
|
|
795
|
-
"port": 4013
|
|
796
|
-
"env": {
|
|
797
|
-
"tests": {
|
|
798
|
-
"port": 4012
|
|
799
|
-
}
|
|
800
|
-
}
|
|
782
|
+
"port": 4013
|
|
801
783
|
}
|
|
802
784
|
```
|
|
803
785
|
|
|
804
786
|
These can also be set via environment variables:
|
|
805
787
|
|
|
806
|
-
- `WP_ENV_PORT` to override the
|
|
807
|
-
- `
|
|
808
|
-
-
|
|
809
|
-
- By default, MySQL aren't exposed to the host, which means no chance of port conflicts. But these can also be overridden for the development and testing environments via `WP_ENV_MYSQL_PORT` and `WP_ENV_TESTS_MYSQL_PORT`, respectively.
|
|
788
|
+
- `WP_ENV_PORT` to override the web server's port.
|
|
789
|
+
- phpMyAdmin is not enabled by default. Enable it with `"phpmyadmin": true` in `.wp-env.json`. The Docker runtime port can also be overridden via `WP_ENV_PHPMYADMIN_PORT`.
|
|
790
|
+
- By default, MySQL isn't exposed to the host, which means no chance of port conflicts. But this can also be overridden via `WP_ENV_MYSQL_PORT`.
|
|
810
791
|
|
|
811
792
|
### Specific PHP Version
|
|
812
793
|
|
|
@@ -877,8 +858,7 @@ wp-env start --spx
|
|
|
877
858
|
|
|
878
859
|
Once enabled, you can access the SPX web UI by visiting any page in your WordPress environment with the query parameters `?SPX_KEY=dev&SPX_UI_URI=/`. For example:
|
|
879
860
|
|
|
880
|
-
-
|
|
881
|
-
- Test site: `http://localhost:8889/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
861
|
+
- `http://localhost:8888/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
882
862
|
|
|
883
863
|
From the SPX interface, you can:
|
|
884
864
|
- Enable profiling for subsequent requests
|
package/lib/cli.js
CHANGED
|
@@ -179,7 +179,7 @@ module.exports = function cli() {
|
|
|
179
179
|
type: 'string',
|
|
180
180
|
describe: "Which environments' databases to reset.",
|
|
181
181
|
choices: [ 'all', 'development', 'tests' ],
|
|
182
|
-
default: '
|
|
182
|
+
default: 'development',
|
|
183
183
|
} );
|
|
184
184
|
args.option( 'scripts', {
|
|
185
185
|
type: 'boolean',
|
|
@@ -197,7 +197,7 @@ module.exports = function cli() {
|
|
|
197
197
|
type: 'string',
|
|
198
198
|
describe: "Which environments' databases to reset.",
|
|
199
199
|
choices: [ 'all', 'development', 'tests' ],
|
|
200
|
-
default: '
|
|
200
|
+
default: 'development',
|
|
201
201
|
} );
|
|
202
202
|
args.option( 'scripts', {
|
|
203
203
|
type: 'boolean',
|
package/lib/commands/start.js
CHANGED
|
@@ -93,10 +93,13 @@ module.exports = async function start( {
|
|
|
93
93
|
spinner.start();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
if ( config.testsEnvironment !== false ) {
|
|
97
|
+
spinner.warn(
|
|
98
|
+
'Warning: wp-env starts both development and tests environments by default.\n' +
|
|
99
|
+
'This behavior is deprecated and will be removed in a future version.\n' +
|
|
100
|
+
'To avoid this warning, add "testsEnvironment": false to your .wp-env.json.\n' +
|
|
101
|
+
'The "env", "testsPort", and "testsEnvironment" options are also deprecated.\n' +
|
|
102
|
+
'Use the --config option with a separate config file for test environments instead.\n'
|
|
100
103
|
);
|
|
101
104
|
spinner.start();
|
|
102
105
|
}
|
|
@@ -89,6 +89,7 @@ module.exports = async function loadConfig(
|
|
|
89
89
|
configDirectoryPath,
|
|
90
90
|
workDirectoryPath: cacheDirectoryPath,
|
|
91
91
|
customConfigPath,
|
|
92
|
+
testsEnvironment: config.testsEnvironment !== false,
|
|
92
93
|
detectedLocalConfig: await hasLocalConfig( [
|
|
93
94
|
configFilePath,
|
|
94
95
|
getConfigFilePath(
|
|
@@ -51,7 +51,8 @@ const mergeConfigs = require( './merge-configs' );
|
|
|
51
51
|
* @property {WPSource[]} themeSources Themes to load in the environment.
|
|
52
52
|
* @property {number} port The port to use.
|
|
53
53
|
* @property {number} mysqlPort The port to use for MySQL. Random if empty.
|
|
54
|
-
* @property {
|
|
54
|
+
* @property {boolean} phpmyadmin Whether to enable phpMyAdmin.
|
|
55
|
+
* @property {number} phpmyadminPort The port to use for phpMyAdmin. Random if empty.
|
|
55
56
|
* @property {boolean} multisite Whether to set up a multisite installation.
|
|
56
57
|
* @property {Object} config Mapping of wp-config.php constants to their desired values.
|
|
57
58
|
* @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
|
|
@@ -89,6 +90,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
|
|
|
89
90
|
port: 8888,
|
|
90
91
|
testsPort: 8889,
|
|
91
92
|
mysqlPort: null,
|
|
93
|
+
phpmyadmin: false,
|
|
92
94
|
phpmyadminPort: null,
|
|
93
95
|
multisite: false,
|
|
94
96
|
mappings: {},
|
|
@@ -306,6 +308,7 @@ function getEnvironmentVarOverrides( cacheDirectoryPath ) {
|
|
|
306
308
|
if ( overrides.phpmyadminPort ) {
|
|
307
309
|
overrideConfig.env.development.phpmyadminPort =
|
|
308
310
|
overrides.phpmyadminPort;
|
|
311
|
+
overrideConfig.env.development.phpmyadmin = true;
|
|
309
312
|
}
|
|
310
313
|
|
|
311
314
|
if ( overrides.testsPort ) {
|
|
@@ -382,6 +385,14 @@ async function parseRootConfig( configFile, rawConfig, options ) {
|
|
|
382
385
|
checkPort( configFile, `testsPort`, rawConfig.testsPort );
|
|
383
386
|
parsedConfig.testsPort = rawConfig.testsPort;
|
|
384
387
|
}
|
|
388
|
+
if ( rawConfig.testsEnvironment !== undefined ) {
|
|
389
|
+
if ( typeof rawConfig.testsEnvironment !== 'boolean' ) {
|
|
390
|
+
throw new ValidationError(
|
|
391
|
+
`Invalid ${ configFile }: "testsEnvironment" must be a boolean.`
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
parsedConfig.testsEnvironment = rawConfig.testsEnvironment;
|
|
395
|
+
}
|
|
385
396
|
parsedConfig.lifecycleScripts = {};
|
|
386
397
|
if ( rawConfig.lifecycleScripts ) {
|
|
387
398
|
checkObjectWithValues(
|
|
@@ -459,6 +470,7 @@ async function parseEnvironmentConfig(
|
|
|
459
470
|
// configuration options that we will parse.
|
|
460
471
|
switch ( key ) {
|
|
461
472
|
case 'testsPort':
|
|
473
|
+
case 'testsEnvironment':
|
|
462
474
|
case 'lifecycleScripts':
|
|
463
475
|
case 'env': {
|
|
464
476
|
if ( options.rootConfig ) {
|
|
@@ -487,8 +499,17 @@ async function parseEnvironmentConfig(
|
|
|
487
499
|
parsedConfig.mysqlPort = config.mysqlPort;
|
|
488
500
|
}
|
|
489
501
|
|
|
502
|
+
if ( config.phpmyadmin !== undefined ) {
|
|
503
|
+
parsedConfig.phpmyadmin = config.phpmyadmin;
|
|
504
|
+
}
|
|
505
|
+
|
|
490
506
|
if ( config.phpmyadminPort !== undefined ) {
|
|
491
507
|
parsedConfig.phpmyadminPort = config.phpmyadminPort;
|
|
508
|
+
// Backward compat: setting phpmyadminPort implies phpmyadmin: true
|
|
509
|
+
// unless phpmyadmin was explicitly set.
|
|
510
|
+
if ( config.phpmyadmin === undefined ) {
|
|
511
|
+
parsedConfig.phpmyadmin = true;
|
|
512
|
+
}
|
|
492
513
|
}
|
|
493
514
|
|
|
494
515
|
if ( config.multisite !== undefined ) {
|
|
@@ -39,25 +39,32 @@ module.exports = function postProcessConfig( config ) {
|
|
|
39
39
|
* @return {WPRootConfig} The config object with the root options merged together with the environment-specific options.
|
|
40
40
|
*/
|
|
41
41
|
function mergeRootToEnvironments( config ) {
|
|
42
|
+
const testsDisabled = config.testsEnvironment === false;
|
|
43
|
+
|
|
42
44
|
// Some root-level options need to be handled early because they have a special
|
|
43
45
|
// cascade behavior that would break the normal merge. After merging we then
|
|
44
46
|
// delete them to avoid that breakage and add them back before we return.
|
|
45
47
|
const removedRootOptions = {};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
|
|
49
|
+
// When tests are disabled, the env key is ignored entirely since there
|
|
50
|
+
// is only one environment. All config should be at the root level.
|
|
51
|
+
if ( ! testsDisabled ) {
|
|
52
|
+
if (
|
|
53
|
+
config.port !== undefined &&
|
|
54
|
+
config.env.development.port === undefined
|
|
55
|
+
) {
|
|
56
|
+
removedRootOptions.port = config.port;
|
|
57
|
+
config.env.development.port = config.port;
|
|
58
|
+
delete config.port;
|
|
59
|
+
}
|
|
60
|
+
if (
|
|
61
|
+
config.testsPort !== undefined &&
|
|
62
|
+
config.env.tests.port === undefined
|
|
63
|
+
) {
|
|
64
|
+
removedRootOptions.testsPort = config.testsPort;
|
|
65
|
+
config.env.tests.port = config.testsPort;
|
|
66
|
+
delete config.testsPort;
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
if ( config.lifecycleScripts !== undefined ) {
|
|
63
70
|
removedRootOptions.lifecycleScripts = config.lifecycleScripts;
|
|
@@ -67,9 +74,15 @@ function mergeRootToEnvironments( config ) {
|
|
|
67
74
|
// Merge the root config and the environment configs together so that
|
|
68
75
|
// we can ignore the root config and have full environment configs.
|
|
69
76
|
for ( const env in config.env ) {
|
|
77
|
+
// Skip merging root options into the tests environment when it's disabled.
|
|
78
|
+
if ( env === 'tests' && testsDisabled ) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
70
81
|
config.env[ env ] = mergeConfigs(
|
|
71
82
|
deepCopyRootOptions( config ),
|
|
72
|
-
|
|
83
|
+
// When tests are disabled, ignore env overrides — all config
|
|
84
|
+
// should be specified at the root level.
|
|
85
|
+
testsDisabled ? {} : config.env[ env ]
|
|
73
86
|
);
|
|
74
87
|
}
|
|
75
88
|
|
|
@@ -89,12 +102,16 @@ function mergeRootToEnvironments( config ) {
|
|
|
89
102
|
* @return {WPRootConfig} The config after post-processing.
|
|
90
103
|
*/
|
|
91
104
|
function appendPortToWPConfigs( config ) {
|
|
105
|
+
const testsDisabled = config.testsEnvironment === false;
|
|
92
106
|
const options = [ 'WP_TESTS_DOMAIN', 'WP_SITEURL', 'WP_HOME' ];
|
|
93
107
|
|
|
94
108
|
// We are only interested in editing the config options for environment-specific configs.
|
|
95
109
|
// If we made this change to the root config it would cause problems since they would
|
|
96
110
|
// be mapped to all environments even though the ports will be different.
|
|
97
111
|
for ( const env in config.env ) {
|
|
112
|
+
if ( env === 'tests' && testsDisabled ) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
98
115
|
// There's nothing to do without any wp-config options set.
|
|
99
116
|
if ( config.env[ env ].config === undefined ) {
|
|
100
117
|
continue;
|
|
@@ -128,6 +145,8 @@ function appendPortToWPConfigs( config ) {
|
|
|
128
145
|
* @param {WPRootConfig} config The config to process.
|
|
129
146
|
*/
|
|
130
147
|
function validatePortUniqueness( config ) {
|
|
148
|
+
const testsDisabled = config.testsEnvironment === false;
|
|
149
|
+
|
|
131
150
|
// We're going to build a map of the environments and their port
|
|
132
151
|
// so we can accommodate root-level config options more easily.
|
|
133
152
|
const environmentPorts = {};
|
|
@@ -135,6 +154,9 @@ function validatePortUniqueness( config ) {
|
|
|
135
154
|
// Add all of the environments to the map. This will
|
|
136
155
|
// overwrite any root-level options if necessary.
|
|
137
156
|
for ( const env in config.env ) {
|
|
157
|
+
if ( env === 'tests' && testsDisabled ) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
138
160
|
if ( config.env[ env ].port === undefined ) {
|
|
139
161
|
throw new ValidationError(
|
|
140
162
|
`The "${ env }" environment has an invalid port.`
|
|
@@ -33,6 +33,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
33
33
|
"multisite": false,
|
|
34
34
|
"mysqlPort": 23306,
|
|
35
35
|
"phpVersion": null,
|
|
36
|
+
"phpmyadmin": false,
|
|
36
37
|
"phpmyadminPort": null,
|
|
37
38
|
"pluginSources": [],
|
|
38
39
|
"port": 999,
|
|
@@ -64,6 +65,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
64
65
|
"multisite": false,
|
|
65
66
|
"mysqlPort": 23307,
|
|
66
67
|
"phpVersion": null,
|
|
68
|
+
"phpmyadmin": false,
|
|
67
69
|
"phpmyadminPort": null,
|
|
68
70
|
"pluginSources": [],
|
|
69
71
|
"port": 456,
|
|
@@ -78,6 +80,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
78
80
|
"afterStart": null,
|
|
79
81
|
},
|
|
80
82
|
"name": "gutenberg",
|
|
83
|
+
"testsEnvironment": true,
|
|
81
84
|
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
82
85
|
}
|
|
83
86
|
`;
|
|
@@ -115,6 +118,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
115
118
|
"multisite": false,
|
|
116
119
|
"mysqlPort": 13306,
|
|
117
120
|
"phpVersion": null,
|
|
121
|
+
"phpmyadmin": false,
|
|
118
122
|
"phpmyadminPort": null,
|
|
119
123
|
"pluginSources": [],
|
|
120
124
|
"port": 123,
|
|
@@ -146,6 +150,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
146
150
|
"multisite": false,
|
|
147
151
|
"mysqlPort": 23307,
|
|
148
152
|
"phpVersion": null,
|
|
153
|
+
"phpmyadmin": false,
|
|
149
154
|
"phpmyadminPort": null,
|
|
150
155
|
"pluginSources": [],
|
|
151
156
|
"port": 8889,
|
|
@@ -160,6 +165,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
160
165
|
"afterStart": "test",
|
|
161
166
|
},
|
|
162
167
|
"name": "gutenberg",
|
|
168
|
+
"testsEnvironment": true,
|
|
163
169
|
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
164
170
|
}
|
|
165
171
|
`;
|
|
@@ -197,6 +203,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
197
203
|
"multisite": false,
|
|
198
204
|
"mysqlPort": null,
|
|
199
205
|
"phpVersion": null,
|
|
206
|
+
"phpmyadmin": false,
|
|
200
207
|
"phpmyadminPort": null,
|
|
201
208
|
"pluginSources": [],
|
|
202
209
|
"port": 8888,
|
|
@@ -228,6 +235,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
228
235
|
"multisite": false,
|
|
229
236
|
"mysqlPort": null,
|
|
230
237
|
"phpVersion": null,
|
|
238
|
+
"phpmyadmin": false,
|
|
231
239
|
"phpmyadminPort": null,
|
|
232
240
|
"pluginSources": [],
|
|
233
241
|
"port": 8889,
|
|
@@ -242,6 +250,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
242
250
|
"afterStart": null,
|
|
243
251
|
},
|
|
244
252
|
"name": "gutenberg",
|
|
253
|
+
"testsEnvironment": true,
|
|
245
254
|
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
246
255
|
}
|
|
247
256
|
`;
|
|
@@ -279,6 +288,7 @@ exports[`Config Integration should use environment variables over local and over
|
|
|
279
288
|
"multisite": false,
|
|
280
289
|
"mysqlPort": 23306,
|
|
281
290
|
"phpVersion": null,
|
|
291
|
+
"phpmyadmin": false,
|
|
282
292
|
"phpmyadminPort": null,
|
|
283
293
|
"pluginSources": [],
|
|
284
294
|
"port": 12345,
|
|
@@ -311,6 +321,7 @@ exports[`Config Integration should use environment variables over local and over
|
|
|
311
321
|
"multisite": false,
|
|
312
322
|
"mysqlPort": 23307,
|
|
313
323
|
"phpVersion": null,
|
|
324
|
+
"phpmyadmin": false,
|
|
314
325
|
"phpmyadminPort": null,
|
|
315
326
|
"pluginSources": [],
|
|
316
327
|
"port": 61234,
|
|
@@ -326,6 +337,7 @@ exports[`Config Integration should use environment variables over local and over
|
|
|
326
337
|
"afterStart": "test",
|
|
327
338
|
},
|
|
328
339
|
"name": "gutenberg",
|
|
340
|
+
"testsEnvironment": true,
|
|
329
341
|
"workDirectoryPath": "/cache/5fea4c5689ef6cc4a4e6eaaa39323338",
|
|
330
342
|
}
|
|
331
343
|
`;
|