@wordpress/env 10.14.0 → 10.16.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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Gutenberg
2
2
 
3
- Copyright 2016-2024 by the contributors
3
+ Copyright 2016-2025 by the contributors
4
4
 
5
5
  **License for Contributions (on and after April 15, 2021)**
6
6
 
@@ -5,7 +5,7 @@
5
5
  const { v2: dockerCompose } = require( 'docker-compose' );
6
6
  const fs = require( 'fs' ).promises;
7
7
  const path = require( 'path' );
8
- const inquirer = require( 'inquirer' );
8
+ const { confirm } = require( '@inquirer/prompts' );
9
9
 
10
10
  /**
11
11
  * Promisified dependencies
@@ -40,14 +40,19 @@ module.exports = async function destroy( { spinner, scripts, debug } ) {
40
40
  'WARNING! This will remove Docker containers, volumes, networks, and images associated with the WordPress instance.'
41
41
  );
42
42
 
43
- const { yesDelete } = await inquirer.prompt( [
44
- {
45
- type: 'confirm',
46
- name: 'yesDelete',
43
+ let yesDelete = false;
44
+ try {
45
+ yesDelete = await confirm( {
47
46
  message: 'Are you sure you want to continue?',
48
47
  default: false,
49
- },
50
- ] );
48
+ } );
49
+ } catch ( error ) {
50
+ if ( error.name === 'ExitPromptError' ) {
51
+ console.log( 'Cancelled.' );
52
+ process.exit( 1 );
53
+ }
54
+ throw error;
55
+ }
51
56
 
52
57
  spinner.start();
53
58
 
@@ -6,7 +6,7 @@ const { v2: dockerCompose } = require( 'docker-compose' );
6
6
  const util = require( 'util' );
7
7
  const path = require( 'path' );
8
8
  const fs = require( 'fs' ).promises;
9
- const inquirer = require( 'inquirer' );
9
+ const { confirm } = require( '@inquirer/prompts' );
10
10
 
11
11
  /**
12
12
  * Promisified dependencies
@@ -328,15 +328,21 @@ async function checkForLegacyInstall( spinner ) {
328
328
  ' and '
329
329
  ) }. Installs are now in your home folder.\n`
330
330
  );
331
- const { yesDelete } = await inquirer.prompt( [
332
- {
333
- type: 'confirm',
334
- name: 'yesDelete',
331
+ let yesDelete = false;
332
+ try {
333
+ yesDelete = confirm( {
335
334
  message:
336
335
  'Do you wish to delete these old installs to reclaim disk space?',
337
336
  default: true,
338
- },
339
- ] );
337
+ } );
338
+ } catch ( error ) {
339
+ if ( error.name === 'ExitPromptError' ) {
340
+ console.log( 'Cancelled.' );
341
+ process.exit( 1 );
342
+ }
343
+ throw error;
344
+ }
345
+
340
346
  if ( yesDelete ) {
341
347
  await Promise.all( installs.map( ( install ) => rimraf( install ) ) );
342
348
  spinner.info( 'Old installs deleted successfully.' );
@@ -52,6 +52,7 @@ const mergeConfigs = require( './merge-configs' );
52
52
  * @property {number} port The port to use.
53
53
  * @property {number} mysqlPort The port to use for MySQL. Random if empty.
54
54
  * @property {number} phpmyadminPort The port to use for phpMyAdmin. If empty, disabled phpMyAdmin.
55
+ * @property {boolean} multisite Whether to set up a multisite installation.
55
56
  * @property {Object} config Mapping of wp-config.php constants to their desired values.
56
57
  * @property {Object.<string, WPSource>} mappings Mapping of WordPress directories to local directories which should be mounted.
57
58
  * @property {string|null} phpVersion Version of PHP to use in the environments, of the format 0.0.
@@ -89,6 +90,7 @@ const DEFAULT_ENVIRONMENT_CONFIG = {
89
90
  testsPort: 8889,
90
91
  mysqlPort: null,
91
92
  phpmyadminPort: null,
93
+ multisite: false,
92
94
  mappings: {},
93
95
  config: {
94
96
  FS_METHOD: 'direct',
@@ -142,7 +144,7 @@ async function parseConfig( configDirectoryPath, cacheDirectoryPath ) {
142
144
  } );
143
145
 
144
146
  // Users can provide overrides in environment
145
- // variables that supercede all other options.
147
+ // variables that supersede all other options.
146
148
  const environmentVarOverrides =
147
149
  getEnvironmentVarOverrides( cacheDirectoryPath );
148
150
 
@@ -466,6 +468,10 @@ async function parseEnvironmentConfig(
466
468
  parsedConfig.phpmyadminPort = config.phpmyadminPort;
467
469
  }
468
470
 
471
+ if ( config.multisite !== undefined ) {
472
+ parsedConfig.multisite = config.multisite;
473
+ }
474
+
469
475
  if ( config.phpVersion !== undefined ) {
470
476
  // Support null as a valid input.
471
477
  if ( config.phpVersion !== null ) {
@@ -129,7 +129,7 @@ function appendPortToWPConfigs( config ) {
129
129
  */
130
130
  function validatePortUniqueness( config ) {
131
131
  // We're going to build a map of the environments and their port
132
- // so we can accomodate root-level config options more easily.
132
+ // so we can accommodate root-level config options more easily.
133
133
  const environmentPorts = {};
134
134
 
135
135
  // Add all of the environments to the map. This will
@@ -179,7 +179,7 @@ function validate( config ) {
179
179
  * @return {WPRootConfig} A deep copy of the root config object.
180
180
  */
181
181
  function deepCopyRootOptions( config ) {
182
- // Create a shallow clone of the object first so we can operate on it safetly.
182
+ // Create a shallow clone of the object first so we can operate on it safely.
183
183
  const rootConfig = Object.assign( {}, config );
184
184
 
185
185
  // Since we're only dealing with the root options we don't want the environments.
@@ -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
+ "multisite": false,
32
33
  "mysqlPort": 23306,
33
34
  "phpVersion": null,
34
35
  "phpmyadminPort": null,
@@ -59,6 +60,7 @@ exports[`Config Integration should load local and override configuration files 1
59
60
  "url": "https://github.com/WordPress/WordPress.git",
60
61
  },
61
62
  "mappings": {},
63
+ "multisite": false,
62
64
  "mysqlPort": 23307,
63
65
  "phpVersion": null,
64
66
  "phpmyadminPort": null,
@@ -106,6 +108,7 @@ exports[`Config Integration should load local configuration file 1`] = `
106
108
  "url": "https://github.com/WordPress/WordPress.git",
107
109
  },
108
110
  "mappings": {},
111
+ "multisite": false,
109
112
  "mysqlPort": 13306,
110
113
  "phpVersion": null,
111
114
  "phpmyadminPort": null,
@@ -136,6 +139,7 @@ exports[`Config Integration should load local configuration file 1`] = `
136
139
  "url": "https://github.com/WordPress/WordPress.git",
137
140
  },
138
141
  "mappings": {},
142
+ "multisite": false,
139
143
  "mysqlPort": 23307,
140
144
  "phpVersion": null,
141
145
  "phpmyadminPort": null,
@@ -183,6 +187,7 @@ exports[`Config Integration should use default configuration 1`] = `
183
187
  "url": "https://github.com/WordPress/WordPress.git",
184
188
  },
185
189
  "mappings": {},
190
+ "multisite": false,
186
191
  "mysqlPort": null,
187
192
  "phpVersion": null,
188
193
  "phpmyadminPort": null,
@@ -213,6 +218,7 @@ exports[`Config Integration should use default configuration 1`] = `
213
218
  "url": "https://github.com/WordPress/WordPress.git",
214
219
  },
215
220
  "mappings": {},
221
+ "multisite": false,
216
222
  "mysqlPort": null,
217
223
  "phpVersion": null,
218
224
  "phpmyadminPort": null,
@@ -260,6 +266,7 @@ exports[`Config Integration should use environment variables over local and over
260
266
  "url": "https://github.com/WordPress/WordPress.git",
261
267
  },
262
268
  "mappings": {},
269
+ "multisite": false,
263
270
  "mysqlPort": 23306,
264
271
  "phpVersion": null,
265
272
  "phpmyadminPort": null,
@@ -291,6 +298,7 @@ exports[`Config Integration should use environment variables over local and over
291
298
  "url": "https://github.com/WordPress/WordPress.git",
292
299
  },
293
300
  "mappings": {},
301
+ "multisite": false,
294
302
  "mysqlPort": 23307,
295
303
  "phpVersion": null,
296
304
  "phpmyadminPort": null,
@@ -23,6 +23,7 @@ const DEFAULT_CONFIG = {
23
23
  testsPort: 8889,
24
24
  mysqlPort: null,
25
25
  phpmyadminPort: null,
26
+ multisite: false,
26
27
  phpVersion: null,
27
28
  coreSource: {
28
29
  type: 'git',
@@ -306,7 +306,7 @@ describe( 'validate-config', () => {
306
306
  } );
307
307
 
308
308
  describe( 'checkValidURL', () => {
309
- it( 'throws for invaid URLs', () => {
309
+ it( 'throws for invalid URLs', () => {
310
310
  expect( () =>
311
311
  checkValidURL( 'test.json', 'test', 'localhost' )
312
312
  ).toThrow(
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  /**
8
- * Error subtype which indicates that an expected validation erorr occurred
8
+ * Error subtype which indicates that an expected validation error occurred
9
9
  * while reading wp-env configuration.
10
10
  */
11
11
  class ValidationError extends Error {}
package/lib/wordpress.js CHANGED
@@ -86,11 +86,40 @@ async function configureWordPress( environment, config, spinner ) {
86
86
  // Ignore error.
87
87
  }
88
88
 
89
- const installCommand = `wp core install --url="${ config.env[ environment ].config.WP_SITEURL }" --title="${ config.name }" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`;
89
+ const isMultisite = config.env[ environment ].multisite;
90
+
91
+ const installMethod = isMultisite ? 'multisite-install' : 'install';
92
+ const installCommand = `wp core ${ installMethod } --url="${ config.env[ environment ].config.WP_SITEURL }" --title="${ config.name }" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`;
90
93
 
91
94
  // -eo pipefail exits the command as soon as anything fails in bash.
92
95
  const setupCommands = [ 'set -eo pipefail', installCommand ];
93
96
 
97
+ // Bootstrap .htaccess for multisite
98
+ if ( isMultisite ) {
99
+ // Using a subshell with `exec` was the best tradeoff I could come up
100
+ // with between readability of this source and compatibility with the
101
+ // way that all strings in `setupCommands` are later joined with '&&'.
102
+ setupCommands.push(
103
+ `(
104
+ exec > /var/www/html/.htaccess
105
+ echo 'RewriteEngine On'
106
+ echo 'RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]'
107
+ echo 'RewriteBase /'
108
+ echo 'RewriteRule ^index\.php$ - [L]'
109
+ echo ''
110
+ echo '# add a trailing slash to /wp-admin'
111
+ echo 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]'
112
+ echo ''
113
+ echo 'RewriteCond %{REQUEST_FILENAME} -f [OR]'
114
+ echo 'RewriteCond %{REQUEST_FILENAME} -d'
115
+ echo 'RewriteRule ^ - [L]'
116
+ echo 'RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]'
117
+ echo 'RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]'
118
+ echo 'RewriteRule . index.php [L]'
119
+ )`
120
+ );
121
+ }
122
+
94
123
  // WordPress versions below 5.1 didn't use proper spacing in wp-config.
95
124
  const configAnchor =
96
125
  wpVersion && isWPMajorMinorVersionLower( wpVersion, '5.1' )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "10.14.0",
3
+ "version": "10.16.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",
@@ -36,12 +36,12 @@
36
36
  "wp-env": "bin/wp-env"
37
37
  },
38
38
  "dependencies": {
39
+ "@inquirer/prompts": "^7.2.0",
39
40
  "chalk": "^4.0.0",
40
41
  "copy-dir": "^1.3.0",
41
42
  "docker-compose": "^0.24.3",
42
43
  "extract-zip": "^1.6.7",
43
44
  "got": "^11.8.5",
44
- "inquirer": "^7.1.0",
45
45
  "js-yaml": "^3.13.1",
46
46
  "ora": "^4.0.2",
47
47
  "rimraf": "^5.0.10",
@@ -55,5 +55,5 @@
55
55
  "scripts": {
56
56
  "test": "echo \"Error: run tests from root\" && exit 1"
57
57
  },
58
- "gitHead": "b432c18934c9db866b6dba7d37517a4e97d642e3"
58
+ "gitHead": "f48b9f56629e400891abb5ae491504de475237ff"
59
59
  }