@wordpress/env 4.1.1 → 4.2.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/CHANGELOG.md +15 -0
- package/LICENSE.md +1 -1
- package/README.md +47 -1
- package/bin/wp-env +2 -1
- package/lib/cli.js +6 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/install-path.js +20 -0
- package/lib/config/test/config.js +2 -2
- package/lib/init-config.js +44 -14
- package/lib/parse-xdebug-mode.js +10 -9
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.2.0 (2022-01-27)
|
|
6
|
+
|
|
7
|
+
### Enhancement
|
|
8
|
+
- Added command `wp-env install-path` to list the directory used for the environment.
|
|
9
|
+
- The help entry is now shown when no subcommand is passed to `wp-env`.
|
|
10
|
+
|
|
11
|
+
### Bug Fix
|
|
12
|
+
- Updated `yargs` to fix [CVE-2021-3807](https://nvd.nist.gov/vuln/detail/CVE-2021-3807).
|
|
13
|
+
|
|
14
|
+
## 4.1.3 (2021-11-07)
|
|
15
|
+
|
|
16
|
+
### Bug Fix
|
|
17
|
+
|
|
18
|
+
- Fix Xdebug installation code to ensure it would fail gracefully
|
|
19
|
+
|
|
5
20
|
## 4.0.3 (2021-04-29)
|
|
6
21
|
|
|
7
22
|
### Bug Fix
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -220,7 +220,7 @@ You should only have to translate `port` and `pathMappings` to the format used b
|
|
|
220
220
|
"request": "launch",
|
|
221
221
|
"port": 9003,
|
|
222
222
|
"pathMappings": {
|
|
223
|
-
"/var/www/html/wp-content/plugins/gutenberg": "${
|
|
223
|
+
"/var/www/html/wp-content/plugins/gutenberg": "${workspaceFolder}/"
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
```
|
|
@@ -350,6 +350,29 @@ wp> ^C
|
|
|
350
350
|
✔ Ran `wp shell` in 'tests-cli'. (in 16s 400ms)
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
+
#### Installing a plugin or theme on the development instance
|
|
354
|
+
|
|
355
|
+
```sh
|
|
356
|
+
wp-env run cli plugin install custom-post-type-ui
|
|
357
|
+
|
|
358
|
+
Creating 500cd328b649d63e882d5c4695871d04_cli_run ... done
|
|
359
|
+
Installing Custom Post Type UI (1.9.2)
|
|
360
|
+
Downloading installation package from https://downloads.wordpress.org/plugin/custom-post-type-ui.zip...
|
|
361
|
+
The authenticity of custom-post-type-ui.zip could not be verified as no signature was found.
|
|
362
|
+
Unpacking the package...
|
|
363
|
+
Installing the plugin...
|
|
364
|
+
Plugin installed successfully.
|
|
365
|
+
Success: Installed 1 of 1 plugins.
|
|
366
|
+
✔ Ran `plugin install custom-post-type-ui` in 'cli'. (in 6s 483ms)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
**NOTE**: Depending on your host OS, you may experience errors when trying to install plugins or themes (e.g. `Warning: Could not create directory.`). This is typically because the user ID used within the container does not have write access to the mounted directories created by `wp-env`. To resolve this, run the `docker-compose` command directly from the directory created by `wp-env` and add `-u $(id -u)` and `-e HOME=/tmp` the `run` command as options:
|
|
370
|
+
|
|
371
|
+
```sh
|
|
372
|
+
$ cd ~/wp-env/500cd328b649d63e882d5c4695871d04
|
|
373
|
+
$ docker-compose run --rm -u $(id -u) -e HOME=/tmp cli [plugin|theme] install <plugin|theme>
|
|
374
|
+
```
|
|
375
|
+
|
|
353
376
|
### `wp-env destroy`
|
|
354
377
|
|
|
355
378
|
```sh
|
|
@@ -377,6 +400,18 @@ Options:
|
|
|
377
400
|
--watch Watch for logs as they happen. [boolean] [default: true]
|
|
378
401
|
```
|
|
379
402
|
|
|
403
|
+
### `wp-env install-path`
|
|
404
|
+
|
|
405
|
+
Outputs the absolute path to the WordPress environment files.
|
|
406
|
+
|
|
407
|
+
Example:
|
|
408
|
+
|
|
409
|
+
```sh
|
|
410
|
+
$ wp-env install-path
|
|
411
|
+
|
|
412
|
+
/home/user/.wp-env/63263e6506becb7b8613b02d42280a49
|
|
413
|
+
```
|
|
414
|
+
|
|
380
415
|
## .wp-env.json
|
|
381
416
|
|
|
382
417
|
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.
|
|
@@ -486,6 +521,8 @@ This is useful for plugin development when upstream Core changes need to be test
|
|
|
486
521
|
|
|
487
522
|
This is useful for working on plugins and WordPress Core at the same time.
|
|
488
523
|
|
|
524
|
+
If you are running a _build_ of `wordpress-develop`, point `core` to the `build` directory.
|
|
525
|
+
|
|
489
526
|
```json
|
|
490
527
|
{
|
|
491
528
|
"core": "../wordpress-develop/build",
|
|
@@ -493,6 +530,15 @@ This is useful for working on plugins and WordPress Core at the same time.
|
|
|
493
530
|
}
|
|
494
531
|
```
|
|
495
532
|
|
|
533
|
+
If you are running `wordpress-develop` in a dev mode (e.g. the watch command `dev` or the dev build `build:dev`), then point `core` to the `src` directory.
|
|
534
|
+
|
|
535
|
+
```json
|
|
536
|
+
{
|
|
537
|
+
"core": "../wordpress-develop/src",
|
|
538
|
+
"plugins": [ "." ]
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
496
542
|
#### A complete testing environment
|
|
497
543
|
|
|
498
544
|
This is useful for integration testing: that is, testing how old versions of WordPress and different combinations of plugins and themes impact each other.
|
package/bin/wp-env
CHANGED
package/lib/cli.js
CHANGED
|
@@ -197,6 +197,12 @@ module.exports = function cli() {
|
|
|
197
197
|
() => {},
|
|
198
198
|
withSpinner( env.destroy )
|
|
199
199
|
);
|
|
200
|
+
yargs.command(
|
|
201
|
+
'install-path',
|
|
202
|
+
'Get the path where environment files are located.',
|
|
203
|
+
() => {},
|
|
204
|
+
withSpinner( env.installPath )
|
|
205
|
+
);
|
|
200
206
|
|
|
201
207
|
return yargs;
|
|
202
208
|
};
|
package/lib/commands/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const clean = require( './clean' );
|
|
|
7
7
|
const run = require( './run' );
|
|
8
8
|
const destroy = require( './destroy' );
|
|
9
9
|
const logs = require( './logs' );
|
|
10
|
+
const installPath = require( './install-path' );
|
|
10
11
|
|
|
11
12
|
module.exports = {
|
|
12
13
|
start,
|
|
@@ -15,4 +16,5 @@ module.exports = {
|
|
|
15
16
|
run,
|
|
16
17
|
destroy,
|
|
17
18
|
logs,
|
|
19
|
+
installPath,
|
|
18
20
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
const initConfig = require( '../init-config' );
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Logs the path to where wp-env files are installed.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} options
|
|
10
|
+
* @param {Object} options.spinner
|
|
11
|
+
* @param {boolean} options.debug
|
|
12
|
+
*/
|
|
13
|
+
module.exports = async function installPath( { spinner, debug } ) {
|
|
14
|
+
// Stop the spinner so that stdout is not polluted.
|
|
15
|
+
spinner.stop();
|
|
16
|
+
// initConfig will fail if wp-env start has not yet been called, so that
|
|
17
|
+
// edge case is handled.
|
|
18
|
+
const { workDirectoryPath } = await initConfig( { spinner, debug } );
|
|
19
|
+
console.log( workDirectoryPath );
|
|
20
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable jest/no-
|
|
1
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
@@ -1128,4 +1128,4 @@ async function testPortNumberValidation( portName, value, envText = '' ) {
|
|
|
1128
1128
|
}
|
|
1129
1129
|
jest.clearAllMocks();
|
|
1130
1130
|
}
|
|
1131
|
-
/* eslint-enable jest/no-
|
|
1131
|
+
/* eslint-enable jest/no-conditional-expect */
|
package/lib/init-config.js
CHANGED
|
@@ -98,6 +98,41 @@ module.exports = async function initConfig( {
|
|
|
98
98
|
return config;
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Checks the configured PHP version
|
|
103
|
+
* against the minimum version supported by Xdebug
|
|
104
|
+
*
|
|
105
|
+
* @param {WPConfig} config
|
|
106
|
+
* @return {boolean} Whether the PHP version is supported by Xdebug
|
|
107
|
+
*/
|
|
108
|
+
function checkXdebugPhpCompatibility( config ) {
|
|
109
|
+
// By default, an undefined phpVersion uses the version on the docker image,
|
|
110
|
+
// which is supported by Xdebug 3.
|
|
111
|
+
const phpCompatibility = true;
|
|
112
|
+
|
|
113
|
+
// If PHP version is defined
|
|
114
|
+
// ensure it meets the Xdebug minimum compatibility requirment
|
|
115
|
+
if ( config.env.development.phpVersion ) {
|
|
116
|
+
const versionTokens = config.env.development.phpVersion.split( '.' );
|
|
117
|
+
const majorVer = parseInt( versionTokens[ 0 ] );
|
|
118
|
+
const minorVer = parseInt( versionTokens[ 1 ] );
|
|
119
|
+
|
|
120
|
+
if ( isNaN( majorVer ) || isNaN( minorVer ) ) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
'Something went wrong when parsing the PHP version.'
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Xdebug 3 supports 7.2 and higher
|
|
127
|
+
// Ensure user has specified a compatible PHP version
|
|
128
|
+
if ( majorVer < 7 || ( majorVer === 7 && minorVer < 2 ) ) {
|
|
129
|
+
throw new Error( 'Cannot use XDebug 3 on PHP < 7.2.' );
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return phpCompatibility;
|
|
134
|
+
}
|
|
135
|
+
|
|
101
136
|
/**
|
|
102
137
|
* Generates the Dockerfile used by wp-env's development instance.
|
|
103
138
|
*
|
|
@@ -107,20 +142,14 @@ module.exports = async function initConfig( {
|
|
|
107
142
|
* @return {string} The dockerfile contents.
|
|
108
143
|
*/
|
|
109
144
|
function dockerFileContents( image, config ) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if ( config.
|
|
114
|
-
const
|
|
115
|
-
const majorVersion = parseInt( versionTokens[ 0 ] );
|
|
116
|
-
const minorVersion = parseInt( versionTokens[ 1 ] );
|
|
117
|
-
if ( isNaN( majorVersion ) || isNaN( minorVersion ) ) {
|
|
118
|
-
throw new Error( 'Something went wrong parsing the php version.' );
|
|
119
|
-
}
|
|
145
|
+
// Don't install XDebug unless it is explicitly required
|
|
146
|
+
let shouldInstallXdebug = false;
|
|
147
|
+
|
|
148
|
+
if ( config.xdebug !== 'off' ) {
|
|
149
|
+
const usingCompatiblePhp = checkXdebugPhpCompatibility( config );
|
|
120
150
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
shouldInstallXdebug = false;
|
|
151
|
+
if ( usingCompatiblePhp ) {
|
|
152
|
+
shouldInstallXdebug = true;
|
|
124
153
|
}
|
|
125
154
|
}
|
|
126
155
|
|
|
@@ -140,7 +169,8 @@ function installXdebug( enableXdebug ) {
|
|
|
140
169
|
|
|
141
170
|
return `
|
|
142
171
|
# Install Xdebug:
|
|
143
|
-
RUN pecl
|
|
172
|
+
RUN if [ -z "$(pecl list | grep xdebug)" ] ; then pecl install xdebug ; fi
|
|
173
|
+
RUN docker-php-ext-enable xdebug
|
|
144
174
|
RUN echo 'xdebug.start_with_request=yes' >> /usr/local/etc/php/php.ini
|
|
145
175
|
RUN echo 'xdebug.mode=${ enableXdebug }' >> /usr/local/etc/php/php.ini
|
|
146
176
|
RUN echo '${ clientDetectSettings }' >> /usr/local/etc/php/php.ini
|
package/lib/parse-xdebug-mode.js
CHANGED
|
@@ -4,28 +4,29 @@ const XDEBUG_MODES = [
|
|
|
4
4
|
'coverage',
|
|
5
5
|
'debug',
|
|
6
6
|
'gcstats',
|
|
7
|
+
'off',
|
|
7
8
|
'profile',
|
|
8
9
|
'trace',
|
|
9
10
|
];
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Custom parsing for the Xdebug mode set via yargs. This function ensures
|
|
13
|
-
* 1. If the --xdebug flag was set
|
|
14
|
-
* 2. If the --xdebug flag
|
|
13
|
+
* Custom parsing for the Xdebug mode set via yargs. This function ensures three things:
|
|
14
|
+
* 1. If the --xdebug flag was not set, set it to 'off'.
|
|
15
|
+
* 2. If the --xdebug flag was set by itself, default to 'debug'.
|
|
16
|
+
* 3. If the --xdebug flag includes modes, make sure they are accepted by Xdebug.
|
|
15
17
|
*
|
|
16
|
-
*
|
|
17
|
-
* is set (and then turn Xdebug off). However, yargs does not pass 'undefined'
|
|
18
|
-
* to the coerce callback, so we cannot handle that case here.
|
|
19
|
-
*
|
|
20
|
-
* @param {string} value The user-set mode of Xdebug
|
|
18
|
+
* @param {string|undefined} value The user-set mode of Xdebug; undefined if there is no --xdebug flag.
|
|
21
19
|
* @return {string} The Xdebug mode to use with defaults applied.
|
|
22
20
|
*/
|
|
23
21
|
module.exports = function parseXdebugMode( value ) {
|
|
22
|
+
if ( value === undefined ) {
|
|
23
|
+
return 'off';
|
|
24
|
+
}
|
|
24
25
|
if ( typeof value !== 'string' ) {
|
|
25
26
|
throwXdebugModeError( value );
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
if ( value.length === 0 ) {
|
|
29
|
+
if ( value.length === 0 || value === 'undefined' ) {
|
|
29
30
|
return 'debug';
|
|
30
31
|
}
|
|
31
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
44
|
"simple-git": "^2.35.0",
|
|
45
45
|
"terminal-link": "^2.0.0",
|
|
46
|
-
"yargs": "^
|
|
46
|
+
"yargs": "^17.3.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"scripts": {
|
|
52
52
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
|
|
55
55
|
}
|