@wordpress/env 10.13.1-next.a9f418477.0 → 10.14.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 CHANGED
@@ -349,7 +349,7 @@ containers.
349
349
  Positionals:
350
350
  container The Docker service to run the command on.
351
351
  [string] [required] [choices: "mysql", "tests-mysql", "wordpress",
352
- "tests-wordpress", "cli", "tests-cli", "composer", "phpunit"]
352
+ "tests-wordpress", "cli", "tests-cli", "composer", "phpmyadmin"]
353
353
  command The command to run. [required]
354
354
 
355
355
  Options:
@@ -174,6 +174,13 @@ module.exports = function buildDockerComposeConfig( config ) {
174
174
  config.env.tests.mysqlPort ?? ''
175
175
  }}:3306`;
176
176
 
177
+ const developmentPhpmyadminPorts = `\${WP_ENV_PHPMYADMIN_PORT:-${
178
+ config.env.development.phpmyadminPort ?? ''
179
+ }}:80`;
180
+ const testsPhpmyadminPorts = `\${WP_ENV_TESTS_PHPMYADMIN_PORT:-${
181
+ config.env.tests.phpmyadminPort ?? ''
182
+ }}:80`;
183
+
177
184
  return {
178
185
  services: {
179
186
  mysql: {
@@ -266,6 +273,26 @@ module.exports = function buildDockerComposeConfig( config ) {
266
273
  },
267
274
  extra_hosts: [ 'host.docker.internal:host-gateway' ],
268
275
  },
276
+ phpmyadmin: {
277
+ image: 'phpmyadmin',
278
+ ports: [ developmentPhpmyadminPorts ],
279
+ environment: {
280
+ PMA_PORT: 3306,
281
+ PMA_HOST: 'mysql',
282
+ PMA_USER: 'root',
283
+ PMA_PASSWORD: 'password',
284
+ },
285
+ },
286
+ 'tests-phpmyadmin': {
287
+ image: 'phpmyadmin',
288
+ ports: [ testsPhpmyadminPorts ],
289
+ environment: {
290
+ PMA_PORT: 3306,
291
+ PMA_HOST: 'tests-mysql',
292
+ PMA_USER: 'root',
293
+ PMA_PASSWORD: 'password',
294
+ },
295
+ },
269
296
  },
270
297
  volumes: {
271
298
  ...( ! config.env.development.coreSource && { wordpress: {} } ),
@@ -3,7 +3,6 @@
3
3
  * External dependencies
4
4
  */
5
5
  const { v2: dockerCompose } = require( 'docker-compose' );
6
- const util = require( 'util' );
7
6
  const fs = require( 'fs' ).promises;
8
7
  const path = require( 'path' );
9
8
  const inquirer = require( 'inquirer' );
@@ -11,7 +10,7 @@ const inquirer = require( 'inquirer' );
11
10
  /**
12
11
  * Promisified dependencies
13
12
  */
14
- const rimraf = util.promisify( require( 'rimraf' ) );
13
+ const { rimraf } = require( 'rimraf' );
15
14
 
16
15
  /**
17
16
  * Internal dependencies
@@ -12,7 +12,7 @@ const inquirer = require( 'inquirer' );
12
12
  * Promisified dependencies
13
13
  */
14
14
  const sleep = util.promisify( setTimeout );
15
- const rimraf = util.promisify( require( 'rimraf' ) );
15
+ const { rimraf } = require( 'rimraf' );
16
16
  const exec = util.promisify( require( 'child_process' ).exec );
17
17
 
18
18
  /**
@@ -180,6 +180,24 @@ module.exports = async function start( {
180
180
  }
181
181
  );
182
182
 
183
+ if ( config.env.development.phpmyadminPort ) {
184
+ await dockerCompose.upOne( 'phpmyadmin', {
185
+ ...dockerComposeConfig,
186
+ commandOptions: shouldConfigureWp
187
+ ? [ '--build', '--force-recreate' ]
188
+ : [],
189
+ } );
190
+ }
191
+
192
+ if ( config.env.tests.phpmyadminPort ) {
193
+ await dockerCompose.upOne( 'tests-phpmyadmin', {
194
+ ...dockerComposeConfig,
195
+ commandOptions: shouldConfigureWp
196
+ ? [ '--build', '--force-recreate' ]
197
+ : [],
198
+ } );
199
+ }
200
+
183
201
  // Make sure we've consumed the custom CLI dockerfile.
184
202
  if ( shouldConfigureWp ) {
185
203
  await dockerCompose.buildOne( [ 'cli' ], { ...dockerComposeConfig } );
@@ -225,35 +243,61 @@ module.exports = async function start( {
225
243
  const siteUrl = config.env.development.config.WP_SITEURL;
226
244
  const testsSiteUrl = config.env.tests.config.WP_SITEURL;
227
245
 
228
- const { out: mySQLAddress } = await dockerCompose.port(
246
+ const mySQLPort = await getPublicDockerPort(
229
247
  'mysql',
230
248
  3306,
231
249
  dockerComposeConfig
232
250
  );
233
- const mySQLPort = mySQLAddress.split( ':' ).pop();
234
251
 
235
- const { out: testsMySQLAddress } = await dockerCompose.port(
252
+ const testsMySQLPort = await getPublicDockerPort(
236
253
  'tests-mysql',
237
254
  3306,
238
255
  dockerComposeConfig
239
256
  );
240
- const testsMySQLPort = testsMySQLAddress.split( ':' ).pop();
241
-
242
- spinner.prefixText = 'WordPress development site started'
243
- .concat( siteUrl ? ` at ${ siteUrl }` : '.' )
244
- .concat( '\n' )
245
- .concat( 'WordPress test site started' )
246
- .concat( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' )
247
- .concat( '\n' )
248
- .concat( `MySQL is listening on port ${ mySQLPort }` )
249
- .concat(
250
- `MySQL for automated testing is listening on port ${ testsMySQLPort }`
251
- )
252
- .concat( '\n' );
253
257
 
258
+ const phpmyadminPort = config.env.development.phpmyadminPort
259
+ ? await getPublicDockerPort( 'phpmyadmin', 80, dockerComposeConfig )
260
+ : null;
261
+
262
+ const testsPhpmyadminPort = config.env.tests.phpmyadminPort
263
+ ? await getPublicDockerPort(
264
+ 'tests-phpmyadmin',
265
+ 80,
266
+ dockerComposeConfig
267
+ )
268
+ : null;
269
+
270
+ spinner.prefixText = [
271
+ 'WordPress development site started' +
272
+ ( siteUrl ? ` at ${ siteUrl }` : '.' ),
273
+ 'WordPress test site started' +
274
+ ( testsSiteUrl ? ` at ${ testsSiteUrl }` : '.' ),
275
+ `MySQL is listening on port ${ mySQLPort }`,
276
+ `MySQL for automated testing is listening on port ${ testsMySQLPort }`,
277
+ phpmyadminPort &&
278
+ `phpMyAdmin started at http://localhost:${ phpmyadminPort }`,
279
+ testsPhpmyadminPort &&
280
+ `phpMyAdmin for automated testing started at http://localhost:${ testsPhpmyadminPort }`,
281
+ ]
282
+ .filter( Boolean )
283
+ .join( '\n' );
284
+ spinner.prefixText += '\n\n';
254
285
  spinner.text = 'Done!';
255
286
  };
256
287
 
288
+ async function getPublicDockerPort(
289
+ service,
290
+ containerPort,
291
+ dockerComposeConfig
292
+ ) {
293
+ const { out: address } = await dockerCompose.port(
294
+ service,
295
+ containerPort,
296
+ dockerComposeConfig
297
+ );
298
+ return address.split( ':' ).pop().trim();
299
+ }
300
+
257
301
  /**
258
302
  * Checks for legacy installs and provides
259
303
  * the user the option to delete them.
@@ -20,6 +20,7 @@ const { checkPort, checkVersion, checkString } = require( './validate-config' );
20
20
  * @property {?number} mysqlPort An override for the development environment's MySQL port.
21
21
  * @property {?number} testsPort An override for the testing environment's port.
22
22
  * @property {?number} testsMysqlPort An override for the testing environment's MySQL port.
23
+ * @property {?number} phpmyadminPort An override for the development environment's phpMyAdmin port.
23
24
  * @property {?WPSource} coreSource An override for all environment's coreSource.
24
25
  * @property {?string} phpVersion An override for all environment's PHP version.
25
26
  * @property {?Object.<string, string>} lifecycleScripts An override for various lifecycle scripts.
@@ -40,6 +41,12 @@ module.exports = function getConfigFromEnvironmentVars( cacheDirectoryPath ) {
40
41
  testsMysqlPort: getPortFromEnvironmentVariable(
41
42
  'WP_ENV_TESTS_MYSQL_PORT'
42
43
  ),
44
+ phpmyadminPort: getPortFromEnvironmentVariable(
45
+ 'WP_ENV_PHPMYADMIN_PORT'
46
+ ),
47
+ testsPhpmyadminPort: getPortFromEnvironmentVariable(
48
+ 'WP_ENV_TESTS_PHPMYADMIN_PORT'
49
+ ),
43
50
  lifecycleScripts: getLifecycleScriptOverrides(),
44
51
  };
45
52
 
@@ -46,14 +46,15 @@ const mergeConfigs = require( './merge-configs' );
46
46
  * The environment-specific configuration options. (development/tests/etc)
47
47
  *
48
48
  * @typedef WPEnvironmentConfig
49
- * @property {WPSource} coreSource The WordPress installation to load in the environment.
50
- * @property {WPSource[]} pluginSources Plugins to load in the environment.
51
- * @property {WPSource[]} themeSources Themes to load in the environment.
52
- * @property {number} port The port to use.
53
- * @property {number} mysqlPort The port to use for MySQL. Random if empty.
54
- * @property {Object} config Mapping of wp-config.php constants to their desired values.
55
- * @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
56
- * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0.
49
+ * @property {WPSource} coreSource The WordPress installation to load in the environment.
50
+ * @property {WPSource[]} pluginSources Plugins to load in the environment.
51
+ * @property {WPSource[]} themeSources Themes to load in the environment.
52
+ * @property {number} port The port to use.
53
+ * @property {number} mysqlPort The port to use for MySQL. Random if empty.
54
+ * @property {number} phpmyadminPort The port to use for phpMyAdmin. If empty, disabled phpMyAdmin.
55
+ * @property {Object} config Mapping of wp-config.php constants to their desired values.
56
+ * @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
57
+ * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0.
57
58
  */
58
59
 
59
60
  /**
@@ -87,6 +88,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
87
88
  port: 8888,
88
89
  testsPort: 8889,
89
90
  mysqlPort: null,
91
+ phpmyadminPort: null,
90
92
  mappings: {},
91
93
  config: {
92
94
  FS_METHOD: 'direct',
@@ -282,6 +284,11 @@ function getEnvironmentVarOverrides( cacheDirectoryPath ) {
282
284
  overrideConfig.env.development.mysqlPort = overrides.mysqlPort;
283
285
  }
284
286
 
287
+ if ( overrides.phpmyadminPort ) {
288
+ overrideConfig.env.development.phpmyadminPort =
289
+ overrides.phpmyadminPort;
290
+ }
291
+
285
292
  if ( overrides.testsPort ) {
286
293
  overrideConfig.testsPort = overrides.testsPort;
287
294
  overrideConfig.env.tests.port = overrides.testsPort;
@@ -455,6 +462,10 @@ async function parseEnvironmentConfig(
455
462
  parsedConfig.mysqlPort = config.mysqlPort;
456
463
  }
457
464
 
465
+ if ( config.phpmyadminPort !== undefined ) {
466
+ parsedConfig.phpmyadminPort = config.phpmyadminPort;
467
+ }
468
+
458
469
  if ( config.phpVersion !== undefined ) {
459
470
  // Support null as a valid input.
460
471
  if ( config.phpVersion !== null ) {
@@ -31,6 +31,7 @@ exports[`Config Integration should load local and override configuration files 1
31
31
  "mappings": {},
32
32
  "mysqlPort": 23306,
33
33
  "phpVersion": null,
34
+ "phpmyadminPort": null,
34
35
  "pluginSources": [],
35
36
  "port": 999,
36
37
  "themeSources": [],
@@ -60,6 +61,7 @@ exports[`Config Integration should load local and override configuration files 1
60
61
  "mappings": {},
61
62
  "mysqlPort": 23307,
62
63
  "phpVersion": null,
64
+ "phpmyadminPort": null,
63
65
  "pluginSources": [],
64
66
  "port": 456,
65
67
  "themeSources": [],
@@ -106,6 +108,7 @@ exports[`Config Integration should load local configuration file 1`] = `
106
108
  "mappings": {},
107
109
  "mysqlPort": 13306,
108
110
  "phpVersion": null,
111
+ "phpmyadminPort": null,
109
112
  "pluginSources": [],
110
113
  "port": 123,
111
114
  "themeSources": [],
@@ -135,6 +138,7 @@ exports[`Config Integration should load local configuration file 1`] = `
135
138
  "mappings": {},
136
139
  "mysqlPort": 23307,
137
140
  "phpVersion": null,
141
+ "phpmyadminPort": null,
138
142
  "pluginSources": [],
139
143
  "port": 8889,
140
144
  "themeSources": [],
@@ -181,6 +185,7 @@ exports[`Config Integration should use default configuration 1`] = `
181
185
  "mappings": {},
182
186
  "mysqlPort": null,
183
187
  "phpVersion": null,
188
+ "phpmyadminPort": null,
184
189
  "pluginSources": [],
185
190
  "port": 8888,
186
191
  "themeSources": [],
@@ -210,6 +215,7 @@ exports[`Config Integration should use default configuration 1`] = `
210
215
  "mappings": {},
211
216
  "mysqlPort": null,
212
217
  "phpVersion": null,
218
+ "phpmyadminPort": null,
213
219
  "pluginSources": [],
214
220
  "port": 8889,
215
221
  "themeSources": [],
@@ -256,6 +262,7 @@ exports[`Config Integration should use environment variables over local and over
256
262
  "mappings": {},
257
263
  "mysqlPort": 23306,
258
264
  "phpVersion": null,
265
+ "phpmyadminPort": null,
259
266
  "pluginSources": [],
260
267
  "port": 12345,
261
268
  "testsPort": 61234,
@@ -286,6 +293,7 @@ exports[`Config Integration should use environment variables over local and over
286
293
  "mappings": {},
287
294
  "mysqlPort": 23307,
288
295
  "phpVersion": null,
296
+ "phpmyadminPort": null,
289
297
  "pluginSources": [],
290
298
  "port": 61234,
291
299
  "testsPort": 61234,
@@ -22,6 +22,7 @@ const DEFAULT_CONFIG = {
22
22
  port: 8888,
23
23
  testsPort: 8889,
24
24
  mysqlPort: null,
25
+ phpmyadminPort: null,
25
26
  phpVersion: null,
26
27
  coreSource: {
27
28
  type: 'git',
@@ -400,4 +401,57 @@ describe( 'parseConfig', () => {
400
401
  )
401
402
  );
402
403
  } );
404
+
405
+ it( 'should parse phpmyadmin configuration for a given environment', async () => {
406
+ readRawConfigFile.mockImplementation( async ( configFile ) => {
407
+ if ( configFile === '/test/gutenberg/.wp-env.json' ) {
408
+ return {
409
+ core: 'WordPress/WordPress#Test',
410
+ phpVersion: '1.0',
411
+ lifecycleScripts: {
412
+ afterStart: 'test',
413
+ },
414
+ env: {
415
+ development: {
416
+ phpmyadminPort: 9001,
417
+ },
418
+ },
419
+ };
420
+ }
421
+ } );
422
+
423
+ const parsed = await parseConfig( '/test/gutenberg', '/cache' );
424
+
425
+ const expected = {
426
+ development: {
427
+ ...DEFAULT_CONFIG.env.development,
428
+ phpmyadminPort: 9001,
429
+ },
430
+ tests: DEFAULT_CONFIG.env.tests,
431
+ };
432
+ expect( parsed.env ).toEqual( expected );
433
+ } );
434
+
435
+ it( 'should ignore root-level configuration for phpmyadmin', async () => {
436
+ readRawConfigFile.mockImplementation( async ( configFile ) => {
437
+ if ( configFile === '/test/gutenberg/.wp-env.json' ) {
438
+ return {
439
+ core: 'WordPress/WordPress#Test',
440
+ phpVersion: '1.0',
441
+ lifecycleScripts: {
442
+ afterStart: 'test',
443
+ },
444
+ phpmyadminPort: 9001,
445
+ };
446
+ }
447
+ } );
448
+
449
+ const parsed = await parseConfig( '/test/gutenberg', '/cache' );
450
+
451
+ const expected = {
452
+ development: DEFAULT_CONFIG.env.development,
453
+ tests: DEFAULT_CONFIG.env.tests,
454
+ };
455
+ expect( parsed.env ).toEqual( expected );
456
+ } );
403
457
  } );
@@ -13,7 +13,7 @@ const path = require( 'path' );
13
13
  */
14
14
  const pipeline = util.promisify( require( 'stream' ).pipeline );
15
15
  const extractZip = util.promisify( require( 'extract-zip' ) );
16
- const rimraf = util.promisify( require( 'rimraf' ) );
16
+ const { rimraf } = require( 'rimraf' );
17
17
 
18
18
  /**
19
19
  * @typedef {import('./config').WPConfig} WPConfig
@@ -10,6 +10,7 @@ const RUN_CONTAINERS = [
10
10
  'tests-wordpress',
11
11
  'cli',
12
12
  'tests-cli',
13
+ 'phpmyadmin',
13
14
  ];
14
15
 
15
16
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "10.13.1-next.a9f418477.0",
3
+ "version": "10.14.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",
@@ -44,7 +44,7 @@
44
44
  "inquirer": "^7.1.0",
45
45
  "js-yaml": "^3.13.1",
46
46
  "ora": "^4.0.2",
47
- "rimraf": "^3.0.2",
47
+ "rimraf": "^5.0.10",
48
48
  "simple-git": "^3.5.0",
49
49
  "terminal-link": "^2.0.0",
50
50
  "yargs": "^17.3.0"
@@ -55,5 +55,5 @@
55
55
  "scripts": {
56
56
  "test": "echo \"Error: run tests from root\" && exit 1"
57
57
  },
58
- "gitHead": "c1a8f3e9cada3b7d8342d1d2595c2dac0433111d"
58
+ "gitHead": "b432c18934c9db866b6dba7d37517a4e97d642e3"
59
59
  }