@wordpress/env 10.0.0 → 10.1.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 +6 -2
- package/lib/build-docker-compose-config.js +8 -2
- package/lib/config/get-config-from-environment-vars.js +6 -0
- package/lib/config/parse-config.js +14 -0
- package/lib/config/test/__snapshots__/config-integration.js.snap +8 -0
- package/lib/config/test/config-integration.js +38 -0
- package/lib/config/test/parse-config.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -480,7 +480,7 @@ You can customize the WordPress installation, plugins and themes that the develo
|
|
|
480
480
|
`.wp-env.json` supports fields for options applicable to both the tests and development instances.
|
|
481
481
|
|
|
482
482
|
| Field | Type | Default | Description |
|
|
483
|
-
|
|
483
|
+
|----------------|----------------|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
|
484
484
|
| `"core"` | `string\|null` | `null` | The WordPress installation to use. If `null` is specified, `wp-env` will use the latest production release of WordPress. |
|
|
485
485
|
| `"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. |
|
|
486
486
|
| `"plugins"` | `string[]` | `[]` | A list of plugins to install and activate in the environment. |
|
|
@@ -489,6 +489,7 @@ You can customize the WordPress installation, plugins and themes that the develo
|
|
|
489
489
|
| `"testsPort"` | `integer` | `8889` | The port number for the test site. You'll access the instance through the port: 'http://localhost:8889'. |
|
|
490
490
|
| `"config"` | `Object` | See below. | Mapping of wp-config.php constants to their desired values. |
|
|
491
491
|
| `"mappings"` | `Object` | `"{}"` | Mapping of WordPress directories to local directories to be mounted in the WordPress instance. |
|
|
492
|
+
| `"mysqlPort"` | `integer` | `null` (randomly assigned) | The MySQL port number to expose. The setting is only available in the `env.development` and `env.tests` objects. |
|
|
492
493
|
|
|
493
494
|
_Note: the port number environment variables (`WP_ENV_PORT` and `WP_ENV_TESTS_PORT`) take precedent over the .wp-env.json values._
|
|
494
495
|
|
|
@@ -521,7 +522,8 @@ Additionally, the key `env` is available to override any of the above options on
|
|
|
521
522
|
"config": {
|
|
522
523
|
"KEY_1": false
|
|
523
524
|
},
|
|
524
|
-
"port": 3000
|
|
525
|
+
"port": 3000,
|
|
526
|
+
"mysqlPort": 13306
|
|
525
527
|
}
|
|
526
528
|
}
|
|
527
529
|
}
|
|
@@ -686,6 +688,8 @@ You can tell `wp-env` to use a custom port number so that your instance does not
|
|
|
686
688
|
}
|
|
687
689
|
```
|
|
688
690
|
|
|
691
|
+
These can also be set via the environment variables `WP_ENV_PORT`, `WP_ENV_TESTS_PORT`, `WP_ENV_MYSQL_PORT` and `WP_ENV_TESTS_MYSQL_PORT`.
|
|
692
|
+
|
|
689
693
|
### Specific PHP Version
|
|
690
694
|
|
|
691
695
|
You can tell `wp-env` to use a specific PHP version for compatibility and testing. This can also be set via the environment variable `WP_ENV_PHP_VERSION`.
|
|
@@ -166,14 +166,20 @@ module.exports = function buildDockerComposeConfig( config ) {
|
|
|
166
166
|
|
|
167
167
|
// Set the default ports based on the config values.
|
|
168
168
|
const developmentPorts = `\${WP_ENV_PORT:-${ config.env.development.port }}:80`;
|
|
169
|
+
const developmentMysqlPorts = `\${WP_ENV_MYSQL_PORT:-${
|
|
170
|
+
config.env.development.mysqlPort ?? ''
|
|
171
|
+
}}:3306`;
|
|
169
172
|
const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`;
|
|
173
|
+
const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${
|
|
174
|
+
config.env.tests.mysqlPort ?? ''
|
|
175
|
+
}}:3306`;
|
|
170
176
|
|
|
171
177
|
return {
|
|
172
178
|
version: '3.7',
|
|
173
179
|
services: {
|
|
174
180
|
mysql: {
|
|
175
181
|
image: 'mariadb:lts',
|
|
176
|
-
ports: [
|
|
182
|
+
ports: [ developmentMysqlPorts ],
|
|
177
183
|
environment: {
|
|
178
184
|
MYSQL_ROOT_HOST: '%',
|
|
179
185
|
MYSQL_ROOT_PASSWORD:
|
|
@@ -184,7 +190,7 @@ module.exports = function buildDockerComposeConfig( config ) {
|
|
|
184
190
|
},
|
|
185
191
|
'tests-mysql': {
|
|
186
192
|
image: 'mariadb:lts',
|
|
187
|
-
ports: [
|
|
193
|
+
ports: [ testsMysqlPorts ],
|
|
188
194
|
environment: {
|
|
189
195
|
MYSQL_ROOT_HOST: '%',
|
|
190
196
|
MYSQL_ROOT_PASSWORD:
|
|
@@ -17,7 +17,9 @@ const { checkPort, checkVersion, checkString } = require( './validate-config' );
|
|
|
17
17
|
*
|
|
18
18
|
* @typedef WPEnvironmentVariableConfig
|
|
19
19
|
* @property {?number} port An override for the development environment's port.
|
|
20
|
+
* @property {?number} mysqlPort An override for the development environment's MySQL port.
|
|
20
21
|
* @property {?number} testsPort An override for the testing environment's port.
|
|
22
|
+
* @property {?number} testsMysqlPort An override for the testing environment's MySQL port.
|
|
21
23
|
* @property {?WPSource} coreSource An override for all environment's coreSource.
|
|
22
24
|
* @property {?string} phpVersion An override for all environment's PHP version.
|
|
23
25
|
* @property {?Object.<string, string>} lifecycleScripts An override for various lifecycle scripts.
|
|
@@ -33,7 +35,11 @@ const { checkPort, checkVersion, checkString } = require( './validate-config' );
|
|
|
33
35
|
module.exports = function getConfigFromEnvironmentVars( cacheDirectoryPath ) {
|
|
34
36
|
const environmentConfig = {
|
|
35
37
|
port: getPortFromEnvironmentVariable( 'WP_ENV_PORT' ),
|
|
38
|
+
mysqlPort: getPortFromEnvironmentVariable( 'WP_ENV_MYSQL_PORT' ),
|
|
36
39
|
testsPort: getPortFromEnvironmentVariable( 'WP_ENV_TESTS_PORT' ),
|
|
40
|
+
testsMysqlPort: getPortFromEnvironmentVariable(
|
|
41
|
+
'WP_ENV_TESTS_MYSQL_PORT'
|
|
42
|
+
),
|
|
37
43
|
lifecycleScripts: getLifecycleScriptOverrides(),
|
|
38
44
|
};
|
|
39
45
|
|
|
@@ -50,6 +50,7 @@ const mergeConfigs = require( './merge-configs' );
|
|
|
50
50
|
* @property {WPSource[]} pluginSources Plugins to load in the environment.
|
|
51
51
|
* @property {WPSource[]} themeSources Themes to load in the environment.
|
|
52
52
|
* @property {number} port The port to use.
|
|
53
|
+
* @property {number} mysqlPort The port to use for MySQL. Random if empty.
|
|
53
54
|
* @property {Object} config Mapping of wp-config.php constants to their desired values.
|
|
54
55
|
* @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
|
|
55
56
|
* @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0.
|
|
@@ -85,6 +86,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
|
|
|
85
86
|
themes: [],
|
|
86
87
|
port: 8888,
|
|
87
88
|
testsPort: 8889,
|
|
89
|
+
mysqlPort: null,
|
|
88
90
|
mappings: {},
|
|
89
91
|
config: {
|
|
90
92
|
FS_METHOD: 'direct',
|
|
@@ -276,11 +278,19 @@ function getEnvironmentVarOverrides( cacheDirectoryPath ) {
|
|
|
276
278
|
overrideConfig.env.development.port = overrides.port;
|
|
277
279
|
}
|
|
278
280
|
|
|
281
|
+
if ( overrides.mysqlPort ) {
|
|
282
|
+
overrideConfig.env.development.mysqlPort = overrides.mysqlPort;
|
|
283
|
+
}
|
|
284
|
+
|
|
279
285
|
if ( overrides.testsPort ) {
|
|
280
286
|
overrideConfig.testsPort = overrides.testsPort;
|
|
281
287
|
overrideConfig.env.tests.port = overrides.testsPort;
|
|
282
288
|
}
|
|
283
289
|
|
|
290
|
+
if ( overrides.testsMysqlPort ) {
|
|
291
|
+
overrideConfig.env.tests.mysqlPort = overrides.testsMysqlPort;
|
|
292
|
+
}
|
|
293
|
+
|
|
284
294
|
if ( overrides.coreSource ) {
|
|
285
295
|
overrideConfig.coreSource = overrides.coreSource;
|
|
286
296
|
overrideConfig.env.development.coreSource = overrides.coreSource;
|
|
@@ -436,6 +446,10 @@ async function parseEnvironmentConfig(
|
|
|
436
446
|
parsedConfig.port = config.port;
|
|
437
447
|
}
|
|
438
448
|
|
|
449
|
+
if ( config.mysqlPort !== undefined ) {
|
|
450
|
+
parsedConfig.mysqlPort = config.mysqlPort;
|
|
451
|
+
}
|
|
452
|
+
|
|
439
453
|
if ( config.phpVersion !== undefined ) {
|
|
440
454
|
// Support null as a valid input.
|
|
441
455
|
if ( config.phpVersion !== null ) {
|
|
@@ -29,6 +29,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
29
29
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
30
30
|
},
|
|
31
31
|
"mappings": {},
|
|
32
|
+
"mysqlPort": 23306,
|
|
32
33
|
"phpVersion": null,
|
|
33
34
|
"pluginSources": [],
|
|
34
35
|
"port": 999,
|
|
@@ -57,6 +58,7 @@ exports[`Config Integration should load local and override configuration files 1
|
|
|
57
58
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
58
59
|
},
|
|
59
60
|
"mappings": {},
|
|
61
|
+
"mysqlPort": 23307,
|
|
60
62
|
"phpVersion": null,
|
|
61
63
|
"pluginSources": [],
|
|
62
64
|
"port": 456,
|
|
@@ -102,6 +104,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
102
104
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
103
105
|
},
|
|
104
106
|
"mappings": {},
|
|
107
|
+
"mysqlPort": 13306,
|
|
105
108
|
"phpVersion": null,
|
|
106
109
|
"pluginSources": [],
|
|
107
110
|
"port": 123,
|
|
@@ -130,6 +133,7 @@ exports[`Config Integration should load local configuration file 1`] = `
|
|
|
130
133
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
131
134
|
},
|
|
132
135
|
"mappings": {},
|
|
136
|
+
"mysqlPort": 23307,
|
|
133
137
|
"phpVersion": null,
|
|
134
138
|
"pluginSources": [],
|
|
135
139
|
"port": 8889,
|
|
@@ -175,6 +179,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
175
179
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
176
180
|
},
|
|
177
181
|
"mappings": {},
|
|
182
|
+
"mysqlPort": null,
|
|
178
183
|
"phpVersion": null,
|
|
179
184
|
"pluginSources": [],
|
|
180
185
|
"port": 8888,
|
|
@@ -203,6 +208,7 @@ exports[`Config Integration should use default configuration 1`] = `
|
|
|
203
208
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
204
209
|
},
|
|
205
210
|
"mappings": {},
|
|
211
|
+
"mysqlPort": null,
|
|
206
212
|
"phpVersion": null,
|
|
207
213
|
"pluginSources": [],
|
|
208
214
|
"port": 8889,
|
|
@@ -248,6 +254,7 @@ exports[`Config Integration should use environment variables over local and over
|
|
|
248
254
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
249
255
|
},
|
|
250
256
|
"mappings": {},
|
|
257
|
+
"mysqlPort": 23306,
|
|
251
258
|
"phpVersion": null,
|
|
252
259
|
"pluginSources": [],
|
|
253
260
|
"port": 12345,
|
|
@@ -277,6 +284,7 @@ exports[`Config Integration should use environment variables over local and over
|
|
|
277
284
|
"url": "https://github.com/WordPress/WordPress.git",
|
|
278
285
|
},
|
|
279
286
|
"mappings": {},
|
|
287
|
+
"mysqlPort": 23307,
|
|
280
288
|
"phpVersion": null,
|
|
281
289
|
"pluginSources": [],
|
|
282
290
|
"port": 61234,
|
|
@@ -48,7 +48,9 @@ describe( 'Config Integration', () => {
|
|
|
48
48
|
afterEach( () => {
|
|
49
49
|
delete process.env.WP_ENV_HOME;
|
|
50
50
|
delete process.env.WP_ENV_PORT;
|
|
51
|
+
delete process.env.WP_ENV_MYSQL_PORT;
|
|
51
52
|
delete process.env.WP_ENV_TESTS_PORT;
|
|
53
|
+
delete process.env.WP_ENV_TESTS_MYSQL_PORT;
|
|
52
54
|
delete process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START;
|
|
53
55
|
} );
|
|
54
56
|
|
|
@@ -61,6 +63,8 @@ describe( 'Config Integration', () => {
|
|
|
61
63
|
|
|
62
64
|
expect( config.env.development.port ).toEqual( 8888 );
|
|
63
65
|
expect( config.env.tests.port ).toEqual( 8889 );
|
|
66
|
+
expect( config.env.development.mysqlPort ).toEqual( null );
|
|
67
|
+
expect( config.env.tests.mysqlPort ).toEqual( null );
|
|
64
68
|
expect( config ).toMatchSnapshot();
|
|
65
69
|
} );
|
|
66
70
|
|
|
@@ -75,6 +79,14 @@ describe( 'Config Integration', () => {
|
|
|
75
79
|
afterClean: null,
|
|
76
80
|
afterDestroy: null,
|
|
77
81
|
},
|
|
82
|
+
env: {
|
|
83
|
+
development: {
|
|
84
|
+
mysqlPort: 13306,
|
|
85
|
+
},
|
|
86
|
+
tests: {
|
|
87
|
+
mysqlPort: 23307,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
78
90
|
} );
|
|
79
91
|
}
|
|
80
92
|
|
|
@@ -85,6 +97,8 @@ describe( 'Config Integration', () => {
|
|
|
85
97
|
|
|
86
98
|
expect( config.env.development.port ).toEqual( 123 );
|
|
87
99
|
expect( config.env.tests.port ).toEqual( 8889 );
|
|
100
|
+
expect( config.env.development.mysqlPort ).toEqual( 13306 );
|
|
101
|
+
expect( config.env.tests.mysqlPort ).toEqual( 23307 );
|
|
88
102
|
expect( config ).toMatchSnapshot();
|
|
89
103
|
} );
|
|
90
104
|
|
|
@@ -100,6 +114,11 @@ describe( 'Config Integration', () => {
|
|
|
100
114
|
afterClean: null,
|
|
101
115
|
afterDestroy: null,
|
|
102
116
|
},
|
|
117
|
+
env: {
|
|
118
|
+
tests: {
|
|
119
|
+
mysqlPort: 13306,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
103
122
|
} );
|
|
104
123
|
}
|
|
105
124
|
|
|
@@ -111,6 +130,14 @@ describe( 'Config Integration', () => {
|
|
|
111
130
|
afterClean: null,
|
|
112
131
|
afterDestroy: 'test',
|
|
113
132
|
},
|
|
133
|
+
env: {
|
|
134
|
+
development: {
|
|
135
|
+
mysqlPort: 23306,
|
|
136
|
+
},
|
|
137
|
+
tests: {
|
|
138
|
+
mysqlPort: 23307,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
114
141
|
} );
|
|
115
142
|
}
|
|
116
143
|
|
|
@@ -121,12 +148,16 @@ describe( 'Config Integration', () => {
|
|
|
121
148
|
|
|
122
149
|
expect( config.env.development.port ).toEqual( 999 );
|
|
123
150
|
expect( config.env.tests.port ).toEqual( 456 );
|
|
151
|
+
expect( config.env.development.mysqlPort ).toEqual( 23306 );
|
|
152
|
+
expect( config.env.tests.mysqlPort ).toEqual( 23307 );
|
|
124
153
|
expect( config ).toMatchSnapshot();
|
|
125
154
|
} );
|
|
126
155
|
|
|
127
156
|
it( 'should use environment variables over local and override configuration files', async () => {
|
|
128
157
|
process.env.WP_ENV_PORT = 12345;
|
|
158
|
+
process.env.WP_ENV_MYSQL_PORT = 23306;
|
|
129
159
|
process.env.WP_ENV_TESTS_PORT = 61234;
|
|
160
|
+
process.env.WP_ENV_TESTS_MYSQL_PORT = 23307;
|
|
130
161
|
process.env.WP_ENV_LIFECYCLE_SCRIPT_AFTER_START = 'test';
|
|
131
162
|
|
|
132
163
|
readFile.mockImplementation( async ( fileName ) => {
|
|
@@ -140,6 +171,11 @@ describe( 'Config Integration', () => {
|
|
|
140
171
|
afterClean: null,
|
|
141
172
|
afterDestroy: null,
|
|
142
173
|
},
|
|
174
|
+
env: {
|
|
175
|
+
tests: {
|
|
176
|
+
mysqlPort: 13306,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
143
179
|
} );
|
|
144
180
|
}
|
|
145
181
|
|
|
@@ -156,6 +192,8 @@ describe( 'Config Integration', () => {
|
|
|
156
192
|
|
|
157
193
|
expect( config.env.development.port ).toEqual( 12345 );
|
|
158
194
|
expect( config.env.tests.port ).toEqual( 61234 );
|
|
195
|
+
expect( config.env.development.mysqlPort ).toEqual( 23306 );
|
|
196
|
+
expect( config.env.tests.mysqlPort ).toEqual( 23307 );
|
|
159
197
|
expect( config.lifecycleScripts ).toHaveProperty(
|
|
160
198
|
'afterStart',
|
|
161
199
|
'test'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.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",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"scripts": {
|
|
56
56
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "66d3bf12e67d16deddc4b4a9ec42e1d0bed3479a"
|
|
59
59
|
}
|