@wordpress/env 10.38.1-next.v.0 → 11.0.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 +158 -75
- package/lib/cli.js +85 -24
- package/lib/commands/clean.js +16 -38
- package/lib/commands/cleanup.js +79 -0
- package/lib/commands/destroy.js +33 -41
- package/lib/commands/index.js +6 -2
- package/lib/commands/logs.js +20 -62
- package/lib/commands/reset.js +46 -0
- package/lib/commands/run.js +16 -117
- package/lib/commands/start.js +78 -243
- package/lib/commands/status.js +160 -0
- package/lib/commands/stop.js +17 -19
- package/lib/config/get-config-from-environment-vars.js +2 -5
- package/lib/config/load-config.js +35 -5
- package/lib/config/parse-config.js +53 -21
- package/lib/config/post-process-config.js +38 -16
- package/lib/config/test/__snapshots__/config-integration.js.snap +16 -0
- package/lib/config/test/parse-config.js +33 -0
- package/lib/config/test/post-process-config.js +52 -0
- package/lib/download-sources.js +9 -53
- package/lib/{build-docker-compose-config.js → runtime/docker/build-docker-compose-config.js} +167 -128
- package/lib/runtime/docker/download-sources.js +63 -0
- package/lib/{download-wp-phpunit.js → runtime/docker/download-wp-phpunit.js} +4 -1
- package/lib/runtime/docker/index.js +863 -0
- package/lib/{init-config.js → runtime/docker/init-config.js} +22 -14
- package/lib/runtime/docker/wordpress.js +309 -0
- package/lib/runtime/errors.js +28 -0
- package/lib/runtime/index.js +91 -0
- package/lib/runtime/playground/blueprint-builder.js +158 -0
- package/lib/runtime/playground/index.js +530 -0
- package/lib/test/build-docker-compose-config.js +150 -3
- package/lib/test/cli.js +49 -13
- package/lib/wordpress.js +1 -297
- package/package.json +6 -3
- package/lib/commands/install-path.js +0 -21
- /package/lib/{get-host-user.js → runtime/docker/get-host-user.js} +0 -0
- /package/lib/{validate-run-container.js → runtime/docker/validate-run-container.js} +0 -0
package/README.md
CHANGED
|
@@ -20,10 +20,38 @@ The database credentials are: user `root`, password `password`. For a comprehens
|
|
|
20
20
|
|
|
21
21
|
`wp-env` relies on a few commonly used developer tools:
|
|
22
22
|
|
|
23
|
-
- **Docker**. `wp-env` is powered by Docker. There are instructions available for installing Docker on [Windows](https://docs.docker.com/desktop/install/windows-install/) (we recommend the WSL2 backend), [macOS](https://docs.docker.com/docker-for-mac/install/), and [Linux](https://docs.docker.com/desktop/install/linux-install/).
|
|
23
|
+
- **Docker**. `wp-env` is powered by Docker by default. There are instructions available for installing Docker on [Windows](https://docs.docker.com/desktop/install/windows-install/) (we recommend the WSL2 backend), [macOS](https://docs.docker.com/docker-for-mac/install/), and [Linux](https://docs.docker.com/desktop/install/linux-install/).
|
|
24
24
|
- **Node.js**. `wp-env` is written as a Node script. We recommend using a Node version manager like [nvm](https://github.com/nvm-sh/nvm) to install the latest LTS version. Alternatively, you can [download it directly here](https://nodejs.org/en/download).
|
|
25
25
|
- **git**. Git is used for downloading software from source control, such as WordPress, plugins, and themes. [You can find the installation instructions here.](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
|
|
26
26
|
|
|
27
|
+
## Experimental: WordPress Playground Runtime
|
|
28
|
+
|
|
29
|
+
`wp-env` now supports an experimental alternative runtime using [WordPress Playground](https://wordpress.github.io/wordpress-playground/). Playground runs WordPress entirely in WebAssembly, eliminating the need for Docker.
|
|
30
|
+
|
|
31
|
+
To use the Playground runtime:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
$ wp-env start --runtime=playground
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Playground vs Docker
|
|
38
|
+
|
|
39
|
+
| Feature | Docker | Playground |
|
|
40
|
+
|---------|--------|------------|
|
|
41
|
+
| Requires Docker | Yes | No |
|
|
42
|
+
| Xdebug | Yes | Yes |
|
|
43
|
+
| SPX profiling | Yes | No |
|
|
44
|
+
| phpMyAdmin | Yes | No |
|
|
45
|
+
| MySQL database | Yes | No (SQLite) |
|
|
46
|
+
| Multisite | Yes | Yes |
|
|
47
|
+
| Custom PHP version | Yes | Yes |
|
|
48
|
+
| Plugin/theme mounting | Yes | Yes |
|
|
49
|
+
| `wp-env run` command | Yes | No |
|
|
50
|
+
|
|
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.
|
|
52
|
+
|
|
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.
|
|
54
|
+
|
|
27
55
|
## Installation
|
|
28
56
|
|
|
29
57
|
### Installation as a global package
|
|
@@ -107,7 +135,7 @@ First, check that `wp-env` is running. One way to do this is to have Docker prin
|
|
|
107
135
|
$ docker ps
|
|
108
136
|
```
|
|
109
137
|
|
|
110
|
-
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`.
|
|
111
139
|
|
|
112
140
|
### 2. Check the port number
|
|
113
141
|
|
|
@@ -157,7 +185,7 @@ To reset the database:
|
|
|
157
185
|
**⚠️ WARNING: This will permanently delete any posts, pages, media, etc. in the local WordPress installation.**
|
|
158
186
|
|
|
159
187
|
```sh
|
|
160
|
-
$ wp-env
|
|
188
|
+
$ wp-env reset all
|
|
161
189
|
$ wp-env start
|
|
162
190
|
```
|
|
163
191
|
|
|
@@ -185,9 +213,9 @@ While we do provide a default `wp-tests-config.php` file within the environment,
|
|
|
185
213
|
|
|
186
214
|
## Using `composer`, `phpunit`, and `wp-cli` tools.
|
|
187
215
|
|
|
188
|
-
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`.
|
|
189
217
|
|
|
190
|
-
|
|
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)).
|
|
191
219
|
|
|
192
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`.
|
|
193
221
|
|
|
@@ -266,6 +294,45 @@ Here is a summary:
|
|
|
266
294
|
|
|
267
295
|
`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).
|
|
268
296
|
|
|
297
|
+
### Global options
|
|
298
|
+
|
|
299
|
+
These options apply to all `wp-env` commands:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
303
|
+
--config Path to a custom .wp-env.json configuration file. [string]
|
|
304
|
+
```
|
|
305
|
+
|
|
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.
|
|
307
|
+
|
|
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
|
+
- `--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
|
+
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
|
+
|
|
315
|
+
#### Running parallel environments
|
|
316
|
+
|
|
317
|
+
You can run multiple wp-env environments from the same folder by using different config files and ports:
|
|
318
|
+
|
|
319
|
+
```sh
|
|
320
|
+
# Start first environment with default config
|
|
321
|
+
wp-env start
|
|
322
|
+
|
|
323
|
+
# Start second environment with custom config on different ports
|
|
324
|
+
WP_ENV_PORT=8890 wp-env start --config=./staging.json
|
|
325
|
+
|
|
326
|
+
# Check status of each environment
|
|
327
|
+
wp-env status
|
|
328
|
+
wp-env status --config=./staging.json
|
|
329
|
+
|
|
330
|
+
# Stop specific environment
|
|
331
|
+
wp-env stop --config=./staging.json
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Each config file gets its own isolated Docker containers and data, so changes in one environment don't affect the other.
|
|
335
|
+
|
|
269
336
|
### `wp-env start`
|
|
270
337
|
|
|
271
338
|
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.
|
|
@@ -274,8 +341,7 @@ The start command installs and initializes the WordPress environment, which incl
|
|
|
274
341
|
wp-env start
|
|
275
342
|
|
|
276
343
|
Starts WordPress for development on port 8888 (http://localhost:8888)
|
|
277
|
-
(override with WP_ENV_PORT)
|
|
278
|
-
(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
|
|
279
345
|
WordPress installation, a plugin, a theme, or contain a .wp-env.json file. After
|
|
280
346
|
first install, use the '--update' flag to download updates to mapped sources and
|
|
281
347
|
to re-apply WordPress configuration options.
|
|
@@ -284,6 +350,9 @@ Options:
|
|
|
284
350
|
--debug Enable debug output. [boolean] [default: false]
|
|
285
351
|
--update Download source updates and apply WordPress configuration.
|
|
286
352
|
[boolean] [default: false]
|
|
353
|
+
--runtime Select the runtime to use. "docker" uses Docker containers,
|
|
354
|
+
"playground" uses WordPress Playground (experimental).
|
|
355
|
+
[string] [choices: "docker", "playground"]
|
|
287
356
|
--xdebug Enables Xdebug. If not passed, Xdebug is turned off. If no modes
|
|
288
357
|
are set, uses "debug". You may set multiple Xdebug modes by passing
|
|
289
358
|
them in a comma-separated list: `--xdebug=develop,coverage`. See
|
|
@@ -302,22 +371,22 @@ Options:
|
|
|
302
371
|
```sh
|
|
303
372
|
wp-env stop
|
|
304
373
|
|
|
305
|
-
Stops running WordPress for development and
|
|
374
|
+
Stops running WordPress for development and frees the ports.
|
|
306
375
|
|
|
307
376
|
Options:
|
|
308
377
|
--debug Enable debug output. [boolean] [default: false]
|
|
309
378
|
```
|
|
310
379
|
|
|
311
|
-
### `wp-env
|
|
380
|
+
### `wp-env reset [environment]`
|
|
312
381
|
|
|
313
382
|
```sh
|
|
314
|
-
wp-env
|
|
383
|
+
wp-env reset [environment]
|
|
315
384
|
|
|
316
|
-
|
|
385
|
+
Resets the WordPress databases.
|
|
317
386
|
|
|
318
387
|
Positionals:
|
|
319
|
-
environment Which environments' databases to
|
|
320
|
-
|
|
388
|
+
environment Which environments' databases to reset.
|
|
389
|
+
[string] [choices: "all", "development", "tests"] [default: "development"]
|
|
321
390
|
|
|
322
391
|
Options:
|
|
323
392
|
--debug Enable debug output. [boolean] [default: false]
|
|
@@ -353,8 +422,8 @@ containers.
|
|
|
353
422
|
|
|
354
423
|
Positionals:
|
|
355
424
|
container The Docker service to run the command on.
|
|
356
|
-
|
|
357
|
-
|
|
425
|
+
[string] [required] [choices: "mysql", "wordpress", "cli", "composer",
|
|
426
|
+
"phpmyadmin"]
|
|
358
427
|
command The command to run. [required]
|
|
359
428
|
|
|
360
429
|
Options:
|
|
@@ -378,29 +447,27 @@ ID user_login display_name user_email user_registered roles
|
|
|
378
447
|
✔ Ran `wp user list` in 'cli'. (in 2s 374ms)
|
|
379
448
|
```
|
|
380
449
|
|
|
381
|
-
#### Creating a post on the
|
|
450
|
+
#### Creating a post on the development instance:
|
|
382
451
|
|
|
383
452
|
```sh
|
|
384
|
-
wp-env run
|
|
453
|
+
wp-env run cli "wp post create --post_type=page --post_title='Ready'"
|
|
385
454
|
|
|
386
|
-
ℹ 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.
|
|
387
456
|
|
|
388
457
|
Success: Created post 5.
|
|
389
|
-
✔ 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)
|
|
390
459
|
```
|
|
391
460
|
|
|
392
|
-
#### Opening the WordPress shell
|
|
461
|
+
#### Opening the WordPress shell and running PHP commands:
|
|
393
462
|
|
|
394
463
|
```sh
|
|
395
|
-
wp-env run
|
|
396
|
-
ℹ 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.
|
|
397
466
|
|
|
398
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_mysql_1 ... done
|
|
399
|
-
Starting 31911d623e75f345e9ed328b9f48cff6_tests-wordpress_1 ... done
|
|
400
467
|
wp> echo( 'hello world!' );
|
|
401
468
|
hello world!
|
|
402
469
|
wp> ^C
|
|
403
|
-
✔ Ran `wp shell` in '
|
|
470
|
+
✔ Ran `wp shell` in 'cli'. (in 16s 400ms)
|
|
404
471
|
```
|
|
405
472
|
|
|
406
473
|
#### Installing a plugin or theme on the development instance
|
|
@@ -437,17 +504,32 @@ To set the permalink to the year, month, and post name:
|
|
|
437
504
|
wp-env run cli "wp rewrite structure /%year%/%monthnum%/%postname%/"
|
|
438
505
|
```
|
|
439
506
|
|
|
507
|
+
### `wp-env cleanup`
|
|
508
|
+
|
|
509
|
+
```sh
|
|
510
|
+
wp-env cleanup
|
|
511
|
+
|
|
512
|
+
Cleanup the WordPress environment. Removes docker containers, volumes, networks,
|
|
513
|
+
and local files, but preserves docker images for faster re-starts.
|
|
514
|
+
|
|
515
|
+
Options:
|
|
516
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
517
|
+
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
518
|
+
--force Skip the confirmation prompt. [boolean] [default: false]
|
|
519
|
+
```
|
|
520
|
+
|
|
440
521
|
### `wp-env destroy`
|
|
441
522
|
|
|
442
523
|
```sh
|
|
443
524
|
wp-env destroy
|
|
444
525
|
|
|
445
|
-
Destroy the WordPress environment. Deletes docker containers, volumes,
|
|
446
|
-
|
|
526
|
+
Destroy the WordPress environment. Deletes docker containers, volumes, networks,
|
|
527
|
+
and images associated with the WordPress environment and removes local files.
|
|
447
528
|
|
|
448
529
|
Options:
|
|
449
530
|
--debug Enable debug output. [boolean] [default: false]
|
|
450
531
|
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
532
|
+
--force Skip the confirmation prompt. [boolean] [default: false]
|
|
451
533
|
```
|
|
452
534
|
|
|
453
535
|
### `wp-env logs [environment]`
|
|
@@ -459,30 +541,49 @@ displays PHP and Docker logs for given WordPress environment.
|
|
|
459
541
|
|
|
460
542
|
Positionals:
|
|
461
543
|
environment Which environment to display the logs from.
|
|
462
|
-
|
|
544
|
+
[string] [choices: "development"] [default: "development"]
|
|
463
545
|
|
|
464
546
|
Options:
|
|
465
547
|
--debug Enable debug output. [boolean] [default: false]
|
|
466
548
|
--watch Watch for logs as they happen. [boolean] [default: true]
|
|
467
549
|
```
|
|
468
550
|
|
|
469
|
-
### `wp-env
|
|
551
|
+
### `wp-env status`
|
|
470
552
|
|
|
471
|
-
Get the
|
|
553
|
+
Get the status of the wp-env environment including whether it's running, URLs, ports, and configuration.
|
|
472
554
|
|
|
473
555
|
Example:
|
|
474
556
|
|
|
475
557
|
```sh
|
|
476
|
-
$ wp-env
|
|
558
|
+
$ wp-env status
|
|
559
|
+
|
|
560
|
+
status: running
|
|
561
|
+
- runtime: docker
|
|
562
|
+
- install path: /home/user/.wp-env/63263e6506becb7b8613b02d42280a49
|
|
563
|
+
- config: /home/user/my-plugin
|
|
477
564
|
|
|
478
|
-
|
|
565
|
+
environment:
|
|
566
|
+
- url: http://localhost:8888
|
|
567
|
+
- multisite: no
|
|
568
|
+
- xdebug: off
|
|
569
|
+
- http port: 8888
|
|
570
|
+
- mysql port: 13306
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
```sh
|
|
574
|
+
$ wp-env status --help
|
|
575
|
+
Get the status of the wp-env environment including URLs, ports, and configuration.
|
|
576
|
+
|
|
577
|
+
Options:
|
|
578
|
+
--debug Enable debug output. [boolean] [default: false]
|
|
579
|
+
--json Output status as JSON. [boolean] [default: false]
|
|
479
580
|
```
|
|
480
581
|
|
|
481
582
|
## .wp-env.json
|
|
482
583
|
|
|
483
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.
|
|
484
585
|
|
|
485
|
-
`.wp-env.json` supports
|
|
586
|
+
`.wp-env.json` supports the following fields:
|
|
486
587
|
|
|
487
588
|
| Field | Type | Default | Description |
|
|
488
589
|
|----------------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
|
@@ -490,16 +591,16 @@ You can customize the WordPress installation, plugins and themes that the develo
|
|
|
490
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. |
|
|
491
592
|
| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. |
|
|
492
593
|
| `"themes"` | `string[]` | `[]` | A list of themes to install in the environment. |
|
|
493
|
-
| `"port"` | `integer` | `8888`
|
|
494
|
-
| `"
|
|
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. |
|
|
495
596
|
| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. |
|
|
496
597
|
| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. |
|
|
497
|
-
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose.
|
|
598
|
+
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. |
|
|
498
599
|
| `"phpmyadminPort"` | `integer` | `null` | The port number for phpMyAdmin. If provided, you'll access phpMyAdmin through: http://localhost:<port> |
|
|
499
600
|
| `"multisite"` | `boolean` | `false` | Whether to set up a multisite installation. |
|
|
500
601
|
| `"lifecycleScripts"` | `Object` | `"{}"` | Mapping of commands that should be executed at certain points in the lifecycle. |
|
|
501
602
|
|
|
502
|
-
_Note: the port number environment
|
|
603
|
+
_Note: the port number environment variable (`WP_ENV_PORT`) takes precedence over the .wp-env.json value._
|
|
503
604
|
|
|
504
605
|
Several types of strings can be passed into the `core`, `plugins`, `themes`, and `mappings` fields.
|
|
505
606
|
|
|
@@ -513,7 +614,7 @@ Several types of strings can be passed into the `core`, `plugins`, `themes`, and
|
|
|
513
614
|
|
|
514
615
|
Remote sources will be downloaded into a temporary directory located in `~/.wp-env`.
|
|
515
616
|
|
|
516
|
-
Additionally, the key `env` is available to override any of the above options on
|
|
617
|
+
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:
|
|
517
618
|
|
|
518
619
|
```json
|
|
519
620
|
{
|
|
@@ -525,29 +626,21 @@ Additionally, the key `env` is available to override any of the above options on
|
|
|
525
626
|
"env": {
|
|
526
627
|
"development": {
|
|
527
628
|
"themes": [ "./one-theme" ]
|
|
528
|
-
},
|
|
529
|
-
"tests": {
|
|
530
|
-
"config": {
|
|
531
|
-
"KEY_1": false
|
|
532
|
-
},
|
|
533
|
-
"port": 3000,
|
|
534
|
-
"mysqlPort": 13306,
|
|
535
|
-
"phpmyadminPort": 9001
|
|
536
629
|
}
|
|
537
630
|
}
|
|
538
631
|
}
|
|
539
632
|
```
|
|
540
633
|
|
|
541
|
-
|
|
634
|
+
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.
|
|
542
635
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
This gives you a lot of power to change the options applicable to each environment.
|
|
636
|
+
For running a separate test environment, use `--config` with a separate config file instead of `env.tests` (see [Running parallel environments](#running-parallel-environments)).
|
|
546
637
|
|
|
547
638
|
## .wp-env.override.json
|
|
548
639
|
|
|
549
640
|
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.
|
|
550
641
|
|
|
642
|
+
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`.
|
|
643
|
+
|
|
551
644
|
## Default wp-config values.
|
|
552
645
|
|
|
553
646
|
On the development instance, these wp-config values are defined by default:
|
|
@@ -563,11 +656,9 @@ WP_SITEURL: 'http://localhost',
|
|
|
563
656
|
WP_HOME: 'http://localhost',
|
|
564
657
|
```
|
|
565
658
|
|
|
566
|
-
On the test instance, all of the above are still defined, but `WP_DEBUG` and `SCRIPT_DEBUG` are set to false.
|
|
567
|
-
|
|
568
659
|
These can be overridden by setting a value within the `config` configuration. Setting it to `null` will prevent the constant being defined entirely.
|
|
569
660
|
|
|
570
|
-
|
|
661
|
+
The values referencing a URL include the specified port. So if you set `port: 2000`, `WP_HOME` (for example) will be `http://localhost:2000`.
|
|
571
662
|
|
|
572
663
|
## Lifecycle Scripts
|
|
573
664
|
|
|
@@ -577,7 +668,8 @@ example, `WP_ENV_LIFECYCLE_SCRIPT_AFTER_START`. Keep in mind that these will be
|
|
|
577
668
|
build won't break on subsequent executions.
|
|
578
669
|
|
|
579
670
|
* `afterStart`: Runs after `wp-env start` has finished setting up the environment.
|
|
580
|
-
* `
|
|
671
|
+
* `afterReset`: Runs after `wp-env reset` has finished resetting the environment.
|
|
672
|
+
* `afterCleanup`: Runs after `wp-env cleanup` has cleaned up the environment.
|
|
581
673
|
* `afterDestroy`: Runs after `wp-env destroy` has destroyed the environment.
|
|
582
674
|
|
|
583
675
|
## Examples
|
|
@@ -666,21 +758,19 @@ Since all plugins in the `plugins` key are activated by default, you should use
|
|
|
666
758
|
}
|
|
667
759
|
```
|
|
668
760
|
|
|
669
|
-
### Map a plugin only in
|
|
761
|
+
### Map a plugin only in a specific environment
|
|
670
762
|
|
|
671
|
-
If you need a plugin active in one environment but not
|
|
763
|
+
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:
|
|
672
764
|
|
|
673
765
|
```json
|
|
674
766
|
{
|
|
675
|
-
"plugins": [ "." ],
|
|
676
|
-
"
|
|
677
|
-
"tests": {
|
|
678
|
-
"plugins": [ ".", "path/to/test/plugin" ]
|
|
679
|
-
}
|
|
680
|
-
}
|
|
767
|
+
"plugins": [ ".", "path/to/test/plugin" ],
|
|
768
|
+
"port": 8889
|
|
681
769
|
}
|
|
682
770
|
```
|
|
683
771
|
|
|
772
|
+
Then start it with `wp-env start --config=test.wp-env.json`.
|
|
773
|
+
|
|
684
774
|
### Custom Port Numbers
|
|
685
775
|
|
|
686
776
|
You can tell `wp-env` to use a custom port number so that your instance does not conflict with other `wp-env` instances.
|
|
@@ -688,21 +778,15 @@ You can tell `wp-env` to use a custom port number so that your instance does not
|
|
|
688
778
|
```json
|
|
689
779
|
{
|
|
690
780
|
"plugins": [ "." ],
|
|
691
|
-
"port": 4013
|
|
692
|
-
"env": {
|
|
693
|
-
"tests": {
|
|
694
|
-
"port": 4012
|
|
695
|
-
}
|
|
696
|
-
}
|
|
781
|
+
"port": 4013
|
|
697
782
|
}
|
|
698
783
|
```
|
|
699
784
|
|
|
700
785
|
These can also be set via environment variables:
|
|
701
786
|
|
|
702
|
-
- `WP_ENV_PORT` to override the
|
|
703
|
-
-
|
|
704
|
-
-
|
|
705
|
-
- 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.
|
|
787
|
+
- `WP_ENV_PORT` to override the web server's port.
|
|
788
|
+
- phpMyAdmin is not enabled by default, but its port can also be overridden via `WP_ENV_PHPMYADMIN_PORT`.
|
|
789
|
+
- 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`.
|
|
706
790
|
|
|
707
791
|
### Specific PHP Version
|
|
708
792
|
|
|
@@ -717,7 +801,7 @@ You can tell `wp-env` to use a specific PHP version for compatibility and testin
|
|
|
717
801
|
|
|
718
802
|
### Multisite support
|
|
719
803
|
|
|
720
|
-
You can tell `wp-env`
|
|
804
|
+
You can tell `wp-env` if the site should be multisite enabled.
|
|
721
805
|
|
|
722
806
|
```json
|
|
723
807
|
{
|
|
@@ -773,8 +857,7 @@ wp-env start --spx
|
|
|
773
857
|
|
|
774
858
|
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:
|
|
775
859
|
|
|
776
|
-
-
|
|
777
|
-
- Test site: `http://localhost:8889/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
860
|
+
- `http://localhost:8888/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
778
861
|
|
|
779
862
|
From the SPX interface, you can:
|
|
780
863
|
- Enable profiling for subsequent requests
|
package/lib/cli.js
CHANGED
|
@@ -6,7 +6,6 @@ const chalk = require( 'chalk' );
|
|
|
6
6
|
const ora = require( 'ora' );
|
|
7
7
|
const yargs = require( 'yargs' );
|
|
8
8
|
const terminalLink = require( 'terminal-link' );
|
|
9
|
-
const { execSync } = require( 'child_process' );
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Internal dependencies
|
|
@@ -16,9 +15,11 @@ const env = require( './env' );
|
|
|
16
15
|
const parseXdebugMode = require( './parse-xdebug-mode' );
|
|
17
16
|
const parseSpxMode = require( './parse-spx-mode' );
|
|
18
17
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
getAvailableRuntimes,
|
|
19
|
+
getRuntime,
|
|
20
|
+
UnsupportedCommandError,
|
|
21
|
+
EnvironmentNotInitializedError,
|
|
22
|
+
} = require( './runtime' );
|
|
22
23
|
|
|
23
24
|
// Colors.
|
|
24
25
|
const boldWhite = chalk.bold.white;
|
|
@@ -46,6 +47,13 @@ const withSpinner =
|
|
|
46
47
|
},
|
|
47
48
|
( error ) => {
|
|
48
49
|
if (
|
|
50
|
+
error instanceof UnsupportedCommandError ||
|
|
51
|
+
error instanceof EnvironmentNotInitializedError
|
|
52
|
+
) {
|
|
53
|
+
// Error is a known user-facing error.
|
|
54
|
+
spinner.fail( error.message );
|
|
55
|
+
process.exit( 1 );
|
|
56
|
+
} else if (
|
|
49
57
|
error instanceof env.ValidationError ||
|
|
50
58
|
error instanceof env.LifecycleScriptError
|
|
51
59
|
) {
|
|
@@ -87,22 +95,17 @@ const withSpinner =
|
|
|
87
95
|
};
|
|
88
96
|
|
|
89
97
|
module.exports = function cli() {
|
|
90
|
-
// Do nothing if Docker is unavailable.
|
|
91
|
-
try {
|
|
92
|
-
execSync( 'docker info', { stdio: 'ignore' } );
|
|
93
|
-
} catch {
|
|
94
|
-
console.error(
|
|
95
|
-
chalk.red( 'Could not connect to Docker. Is it running?' )
|
|
96
|
-
);
|
|
97
|
-
process.exit( 1 );
|
|
98
|
-
}
|
|
99
|
-
|
|
100
98
|
yargs.usage( wpPrimary( '$0 <command>' ) );
|
|
101
99
|
yargs.option( 'debug', {
|
|
102
100
|
type: 'boolean',
|
|
103
101
|
describe: 'Enable debug output.',
|
|
104
102
|
default: false,
|
|
105
103
|
} );
|
|
104
|
+
yargs.option( 'config', {
|
|
105
|
+
type: 'string',
|
|
106
|
+
describe: 'Path to a custom .wp-env.json configuration file.',
|
|
107
|
+
requiresArg: true,
|
|
108
|
+
} );
|
|
106
109
|
|
|
107
110
|
yargs.parserConfiguration( {
|
|
108
111
|
// Treats unknown options as arguments for commands to deal with instead of discarding them.
|
|
@@ -150,6 +153,13 @@ module.exports = function cli() {
|
|
|
150
153
|
describe: 'Execute any configured lifecycle scripts.',
|
|
151
154
|
default: true,
|
|
152
155
|
} );
|
|
156
|
+
args.option( 'runtime', {
|
|
157
|
+
type: 'string',
|
|
158
|
+
describe:
|
|
159
|
+
'The runtime environment to use. "docker" uses Docker containers, "playground" uses WordPress Playground (experimental).',
|
|
160
|
+
choices: getAvailableRuntimes(),
|
|
161
|
+
default: 'docker',
|
|
162
|
+
} );
|
|
153
163
|
},
|
|
154
164
|
withSpinner( env.start )
|
|
155
165
|
);
|
|
@@ -161,15 +171,33 @@ module.exports = function cli() {
|
|
|
161
171
|
() => {},
|
|
162
172
|
withSpinner( env.stop )
|
|
163
173
|
);
|
|
174
|
+
yargs.command(
|
|
175
|
+
'reset [environment]',
|
|
176
|
+
wpYellow( 'Resets the WordPress databases.' ),
|
|
177
|
+
( args ) => {
|
|
178
|
+
args.positional( 'environment', {
|
|
179
|
+
type: 'string',
|
|
180
|
+
describe: "Which environments' databases to reset.",
|
|
181
|
+
choices: [ 'all', 'development', 'tests' ],
|
|
182
|
+
default: 'development',
|
|
183
|
+
} );
|
|
184
|
+
args.option( 'scripts', {
|
|
185
|
+
type: 'boolean',
|
|
186
|
+
describe: 'Execute any configured lifecycle scripts.',
|
|
187
|
+
default: true,
|
|
188
|
+
} );
|
|
189
|
+
},
|
|
190
|
+
withSpinner( env.reset )
|
|
191
|
+
);
|
|
164
192
|
yargs.command(
|
|
165
193
|
'clean [environment]',
|
|
166
|
-
|
|
194
|
+
chalk.gray( '[Deprecated: use reset] Resets the WordPress databases.' ),
|
|
167
195
|
( args ) => {
|
|
168
196
|
args.positional( 'environment', {
|
|
169
197
|
type: 'string',
|
|
170
|
-
describe: "Which environments' databases to
|
|
198
|
+
describe: "Which environments' databases to reset.",
|
|
171
199
|
choices: [ 'all', 'development', 'tests' ],
|
|
172
|
-
default: '
|
|
200
|
+
default: 'development',
|
|
173
201
|
} );
|
|
174
202
|
args.option( 'scripts', {
|
|
175
203
|
type: 'boolean',
|
|
@@ -201,6 +229,10 @@ module.exports = function cli() {
|
|
|
201
229
|
'$0 logs --no-watch --environment=tests',
|
|
202
230
|
'Displays the latest logs for the e2e test environment without watching.'
|
|
203
231
|
);
|
|
232
|
+
// Get run containers from Docker runtime (run command is Docker-only for now)
|
|
233
|
+
const dockerRuntime = getRuntime( 'docker' );
|
|
234
|
+
const runContainers = dockerRuntime.getRunContainers();
|
|
235
|
+
|
|
204
236
|
yargs.command(
|
|
205
237
|
'run <container> [command...]',
|
|
206
238
|
'Runs an arbitrary command in one of the underlying Docker containers. A double dash can be used to pass arguments to the container without parsing them. This is necessary if you are using an option that is defined below. You can use `bash` to open a shell session and both `composer` and `phpunit` are available in all WordPress and CLI containers. WP-CLI is also available in the CLI containers.',
|
|
@@ -216,8 +248,7 @@ module.exports = function cli() {
|
|
|
216
248
|
type: 'string',
|
|
217
249
|
describe:
|
|
218
250
|
'The underlying Docker service to run the command on.',
|
|
219
|
-
choices:
|
|
220
|
-
coerce: validateRunContainer,
|
|
251
|
+
choices: runContainers,
|
|
221
252
|
} );
|
|
222
253
|
args.positional( 'command', {
|
|
223
254
|
type: 'array',
|
|
@@ -242,7 +273,7 @@ module.exports = function cli() {
|
|
|
242
273
|
yargs.command(
|
|
243
274
|
'destroy',
|
|
244
275
|
wpRed(
|
|
245
|
-
'Destroy the WordPress environment. Deletes docker containers, volumes, and
|
|
276
|
+
'Destroy the WordPress environment. Deletes docker containers, volumes, networks, and images associated with the WordPress environment and removes local files.'
|
|
246
277
|
),
|
|
247
278
|
( args ) => {
|
|
248
279
|
args.option( 'scripts', {
|
|
@@ -250,14 +281,44 @@ module.exports = function cli() {
|
|
|
250
281
|
describe: 'Execute any configured lifecycle scripts.',
|
|
251
282
|
default: true,
|
|
252
283
|
} );
|
|
284
|
+
args.option( 'force', {
|
|
285
|
+
type: 'boolean',
|
|
286
|
+
describe: 'Skip the confirmation prompt.',
|
|
287
|
+
default: false,
|
|
288
|
+
} );
|
|
253
289
|
},
|
|
254
290
|
withSpinner( env.destroy )
|
|
255
291
|
);
|
|
256
292
|
yargs.command(
|
|
257
|
-
'
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
293
|
+
'cleanup',
|
|
294
|
+
wpYellow(
|
|
295
|
+
'Cleanup the WordPress environment. Removes docker containers, volumes, networks, and local files, but preserves docker images for faster re-starts.'
|
|
296
|
+
),
|
|
297
|
+
( args ) => {
|
|
298
|
+
args.option( 'scripts', {
|
|
299
|
+
type: 'boolean',
|
|
300
|
+
describe: 'Execute any configured lifecycle scripts.',
|
|
301
|
+
default: true,
|
|
302
|
+
} );
|
|
303
|
+
args.option( 'force', {
|
|
304
|
+
type: 'boolean',
|
|
305
|
+
describe: 'Skip the confirmation prompt.',
|
|
306
|
+
default: false,
|
|
307
|
+
} );
|
|
308
|
+
},
|
|
309
|
+
withSpinner( env.cleanup )
|
|
310
|
+
);
|
|
311
|
+
yargs.command(
|
|
312
|
+
'status',
|
|
313
|
+
'Get the status of the wp-env environment including URLs, ports, and configuration.',
|
|
314
|
+
( args ) => {
|
|
315
|
+
args.option( 'json', {
|
|
316
|
+
type: 'boolean',
|
|
317
|
+
describe: 'Output status as JSON.',
|
|
318
|
+
default: false,
|
|
319
|
+
} );
|
|
320
|
+
},
|
|
321
|
+
withSpinner( env.status )
|
|
261
322
|
);
|
|
262
323
|
|
|
263
324
|
return yargs;
|