@wordpress/env 10.39.0 → 11.0.1-next.v.20260206T143.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.
@@ -107,21 +107,13 @@ function getMountArgs( config ) {
107
107
  }
108
108
 
109
109
  // Mount themes
110
+ // All theme types (local, git, zip) can be mounted after downloading/extraction
110
111
  for ( const theme of envConfig.themeSources || [] ) {
111
- if ( theme.type === 'local' || theme.type === 'git' ) {
112
- args.push(
113
- '--mount-dir',
114
- theme.path,
115
- `/wordpress/wp-content/themes/${ theme.basename }`
116
- );
117
- } else {
118
- throw new Error(
119
- `Theme source "${ theme.basename || theme.path }" of type "${
120
- theme.type
121
- }" ` +
122
- `is not supported with Playground runtime. Only local and git themes are supported.`
123
- );
124
- }
112
+ args.push(
113
+ '--mount-dir',
114
+ theme.path,
115
+ `/wordpress/wp-content/themes/${ theme.basename }`
116
+ );
125
117
  }
126
118
 
127
119
  // Mount custom mappings
@@ -75,6 +75,15 @@ class PlaygroundRuntime {
75
75
  return 'WARNING! This will remove the WordPress Playground environment and all local files.';
76
76
  }
77
77
 
78
+ /**
79
+ * Get the warning message for cleanup confirmation.
80
+ *
81
+ * @return {string} Warning message.
82
+ */
83
+ getCleanupWarningMessage() {
84
+ return 'WARNING! This will remove the WordPress Playground environment and all local files.';
85
+ }
86
+
78
87
  /**
79
88
  * Start the WordPress Playground environment.
80
89
  *
@@ -350,6 +359,25 @@ class PlaygroundRuntime {
350
359
  spinner.text = 'Removed WordPress Playground environment.';
351
360
  }
352
361
 
362
+ /**
363
+ * Cleanup the WordPress Playground environment.
364
+ *
365
+ * For Playground, cleanup is the same as destroy since there are no
366
+ * shared resources like Docker images to preserve.
367
+ *
368
+ * @param {Object} config The wp-env config object.
369
+ * @param {Object} options Cleanup options.
370
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
371
+ */
372
+ async cleanup( config, { spinner } ) {
373
+ await this.stop( config, { spinner } );
374
+
375
+ spinner.text = 'Removing local files.';
376
+ await rimraf( config.workDirectoryPath );
377
+
378
+ spinner.text = 'Cleaned up WordPress Playground environment.';
379
+ }
380
+
353
381
  /**
354
382
  * Run a command in the Playground environment.
355
383
  *
@@ -367,21 +395,71 @@ class PlaygroundRuntime {
367
395
  }
368
396
 
369
397
  /**
370
- * Clean/reset the WordPress database.
398
+ * Reset the WordPress database.
371
399
  *
372
400
  * @param {Object} config The wp-env config object.
373
- * @param {Object} options Clean options.
401
+ * @param {Object} options Reset options.
374
402
  * @param {Object} options.spinner A CLI spinner which indicates progress.
375
403
  * @param {boolean} options.debug True if debug mode is enabled.
376
404
  */
377
405
  async clean( config, { spinner, debug } ) {
378
- spinner.text = 'Cleaning WordPress Playground environment.';
406
+ spinner.text = 'Resetting WordPress Playground environment.';
379
407
 
380
408
  // For Playground, we restart the server to reset the database
381
409
  await this.stop( config, { spinner } );
382
410
  await this.start( config, { spinner, debug } );
383
411
 
384
- spinner.text = 'Cleaned WordPress Playground environment.';
412
+ spinner.text = 'Reset WordPress Playground environment.';
413
+ }
414
+
415
+ /**
416
+ * Get the status of the Playground environment.
417
+ *
418
+ * @param {Object} config The wp-env config object.
419
+ * @param {Object} options Status options.
420
+ * @param {Object} options.spinner A CLI spinner which indicates progress.
421
+ * @return {Promise<Object>} Status object with environment information.
422
+ */
423
+ async getStatus( config, { spinner } ) {
424
+ spinner.text = 'Getting environment status.';
425
+
426
+ const envConfig = config.env.development;
427
+ const port = envConfig.port || 8888;
428
+ const pidFile = path.join( config.workDirectoryPath, 'playground.pid' );
429
+
430
+ // Check if server is running.
431
+ let isRunning = false;
432
+
433
+ try {
434
+ const pidContent = await fs.readFile( pidFile, 'utf8' );
435
+ const pid = parseInt( pidContent.trim(), 10 );
436
+
437
+ // Check if process is still alive.
438
+ process.kill( pid, 0 );
439
+
440
+ // Check if server is responding.
441
+ await this._checkServer( port );
442
+ isRunning = true;
443
+ } catch {
444
+ // Process not running or server not responding.
445
+ }
446
+
447
+ return {
448
+ status: isRunning ? 'running' : 'stopped',
449
+ runtime: 'playground',
450
+ urls: {
451
+ development: isRunning ? `http://localhost:${ port }` : null,
452
+ },
453
+ ports: {
454
+ development: port,
455
+ },
456
+ config: {
457
+ multisite: envConfig.multisite,
458
+ xdebug: 'off',
459
+ },
460
+ configPath: config.configDirectoryPath,
461
+ installPath: config.workDirectoryPath,
462
+ };
385
463
  }
386
464
 
387
465
  /**
@@ -131,4 +131,87 @@ describe( 'buildDockerComposeConfig', () => {
131
131
  expect( dockerConfig.volumes.wordpress ).toBe( undefined );
132
132
  expect( dockerConfig.volumes[ 'tests-wordpress' ] ).toBe( undefined );
133
133
  } );
134
+
135
+ it( 'should add healthcheck to mysql services', () => {
136
+ const config = buildDockerComposeConfig( {
137
+ workDirectoryPath: '/some/path',
138
+ env: {
139
+ development: {
140
+ port: 8888,
141
+ mysqlPort: 3306,
142
+ coreSource: null,
143
+ pluginSources: [],
144
+ themeSources: [],
145
+ mappings: {},
146
+ },
147
+ tests: {
148
+ port: 8889,
149
+ mysqlPort: 3307,
150
+ coreSource: null,
151
+ pluginSources: [],
152
+ themeSources: [],
153
+ mappings: {},
154
+ },
155
+ },
156
+ } );
157
+
158
+ expect( config.services.mysql.healthcheck ).toBeDefined();
159
+ expect( config.services.mysql.healthcheck.test ).toEqual( [
160
+ 'CMD',
161
+ 'healthcheck.sh',
162
+ '--connect',
163
+ '--innodb_initialized',
164
+ ] );
165
+ expect( config.services.mysql.healthcheck.interval ).toBe( '5s' );
166
+ expect( config.services.mysql.healthcheck.timeout ).toBe( '10s' );
167
+ expect( config.services.mysql.healthcheck.retries ).toBe( 12 );
168
+ expect( config.services.mysql.healthcheck.start_period ).toBe( '60s' );
169
+
170
+ // Verify MARIADB_AUTO_UPGRADE is set for existing installations
171
+ expect( config.services.mysql.environment.MARIADB_AUTO_UPGRADE ).toBe(
172
+ '1'
173
+ );
174
+
175
+ expect( config.services[ 'tests-mysql' ].healthcheck ).toBeDefined();
176
+ expect( config.services[ 'tests-mysql' ].healthcheck.test ).toEqual( [
177
+ 'CMD',
178
+ 'healthcheck.sh',
179
+ '--connect',
180
+ '--innodb_initialized',
181
+ ] );
182
+ expect(
183
+ config.services[ 'tests-mysql' ].environment.MARIADB_AUTO_UPGRADE
184
+ ).toBe( '1' );
185
+ } );
186
+
187
+ it( 'should use service_healthy condition for WordPress depends_on', () => {
188
+ const config = buildDockerComposeConfig( {
189
+ workDirectoryPath: '/some/path',
190
+ env: {
191
+ development: {
192
+ port: 8888,
193
+ mysqlPort: 3306,
194
+ coreSource: null,
195
+ pluginSources: [],
196
+ themeSources: [],
197
+ mappings: {},
198
+ },
199
+ tests: {
200
+ port: 8889,
201
+ mysqlPort: 3307,
202
+ coreSource: null,
203
+ pluginSources: [],
204
+ themeSources: [],
205
+ mappings: {},
206
+ },
207
+ },
208
+ } );
209
+
210
+ expect( config.services.wordpress.depends_on ).toEqual( {
211
+ mysql: { condition: 'service_healthy' },
212
+ } );
213
+ expect( config.services[ 'tests-wordpress' ].depends_on ).toEqual( {
214
+ 'tests-mysql': { condition: 'service_healthy' },
215
+ } );
216
+ } );
134
217
  } );
package/lib/test/cli.js CHANGED
@@ -19,8 +19,11 @@ jest.mock( '../env', () => {
19
19
  return {
20
20
  start: jest.fn( Promise.resolve.bind( Promise ) ),
21
21
  stop: jest.fn( Promise.resolve.bind( Promise ) ),
22
+ reset: jest.fn( Promise.resolve.bind( Promise ) ),
22
23
  clean: jest.fn( Promise.resolve.bind( Promise ) ),
23
24
  run: jest.fn( Promise.resolve.bind( Promise ) ),
25
+ destroy: jest.fn( Promise.resolve.bind( Promise ) ),
26
+ cleanup: jest.fn( Promise.resolve.bind( Promise ) ),
24
27
  ValidationError: actual.ValidationError,
25
28
  LifecycleScriptError: actual.LifecycleScriptError,
26
29
  };
@@ -41,26 +44,33 @@ describe( 'env cli', () => {
41
44
  expect( spinner.text ).toBe( '' );
42
45
  } );
43
46
 
44
- it( 'parses clean commands for the default environment.', () => {
45
- cli().parse( [ 'clean' ] );
46
- const { environment, spinner } = env.clean.mock.calls[ 0 ][ 0 ];
47
+ it( 'parses reset commands for the default environment.', () => {
48
+ cli().parse( [ 'reset' ] );
49
+ const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
47
50
  expect( environment ).toBe( 'tests' );
48
51
  expect( spinner.text ).toBe( '' );
49
52
  } );
50
- it( 'parses clean commands for all environments.', () => {
51
- cli().parse( [ 'clean', 'all' ] );
52
- const { environment, spinner } = env.clean.mock.calls[ 0 ][ 0 ];
53
+ it( 'parses reset commands for all environments.', () => {
54
+ cli().parse( [ 'reset', 'all' ] );
55
+ const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
53
56
  expect( environment ).toBe( 'all' );
54
57
  expect( spinner.text ).toBe( '' );
55
58
  } );
56
- it( 'parses clean commands for the development environment.', () => {
57
- cli().parse( [ 'clean', 'development' ] );
58
- const { environment, spinner } = env.clean.mock.calls[ 0 ][ 0 ];
59
+ it( 'parses reset commands for the development environment.', () => {
60
+ cli().parse( [ 'reset', 'development' ] );
61
+ const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
59
62
  expect( environment ).toBe( 'development' );
60
63
  expect( spinner.text ).toBe( '' );
61
64
  } );
62
- it( 'parses clean commands for the tests environment.', () => {
63
- cli().parse( [ 'clean', 'tests' ] );
65
+ it( 'parses reset commands for the tests environment.', () => {
66
+ cli().parse( [ 'reset', 'tests' ] );
67
+ const { environment, spinner } = env.reset.mock.calls[ 0 ][ 0 ];
68
+ expect( environment ).toBe( 'tests' );
69
+ expect( spinner.text ).toBe( '' );
70
+ } );
71
+
72
+ it( 'parses clean (deprecated) commands for the default environment.', () => {
73
+ cli().parse( [ 'clean' ] );
64
74
  const { environment, spinner } = env.clean.mock.calls[ 0 ][ 0 ];
65
75
  expect( environment ).toBe( 'tests' );
66
76
  expect( spinner.text ).toBe( '' );
@@ -81,6 +91,32 @@ describe( 'env cli', () => {
81
91
  expect( spinner.text ).toBe( '' );
82
92
  } );
83
93
 
94
+ it( 'parses destroy commands.', () => {
95
+ cli().parse( [ 'destroy' ] );
96
+ const { spinner, scripts, force } = env.destroy.mock.calls[ 0 ][ 0 ];
97
+ expect( spinner.text ).toBe( '' );
98
+ expect( scripts ).toBe( true );
99
+ expect( force ).toBe( false );
100
+ } );
101
+ it( 'parses destroy commands with --force flag.', () => {
102
+ cli().parse( [ 'destroy', '--force' ] );
103
+ const { force } = env.destroy.mock.calls[ 0 ][ 0 ];
104
+ expect( force ).toBe( true );
105
+ } );
106
+
107
+ it( 'parses cleanup commands.', () => {
108
+ cli().parse( [ 'cleanup' ] );
109
+ const { spinner, scripts, force } = env.cleanup.mock.calls[ 0 ][ 0 ];
110
+ expect( spinner.text ).toBe( '' );
111
+ expect( scripts ).toBe( true );
112
+ expect( force ).toBe( false );
113
+ } );
114
+ it( 'parses cleanup commands with --force flag.', () => {
115
+ cli().parse( [ 'cleanup', '--force' ] );
116
+ const { force } = env.cleanup.mock.calls[ 0 ][ 0 ];
117
+ expect( force ).toBe( true );
118
+ } );
119
+
84
120
  it( 'handles successful commands with messages.', async () => {
85
121
  env.start.mockResolvedValueOnce( 'success message' );
86
122
  cli().parse( [ 'start' ] );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/env",
3
- "version": "10.39.0",
3
+ "version": "11.0.1-next.v.20260206T143.0+81f8de885",
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",
@@ -64,5 +64,5 @@
64
64
  "scripts": {
65
65
  "test": "echo \"Error: run tests from root\" && exit 1"
66
66
  },
67
- "gitHead": "eee1cfb1472f11183e40fb77465a5f13145df7ad"
67
+ "gitHead": "6ae3fbb907e6c309ff6a0685e5e5ff0c2ee23b15"
68
68
  }
@@ -1,33 +0,0 @@
1
- 'use strict';
2
- /**
3
- * External dependencies
4
- */
5
- const path = require( 'path' );
6
- const { existsSync } = require( 'fs' );
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- const { loadConfig } = require( '../config' );
12
-
13
- /**
14
- * Logs the path to where wp-env files are installed.
15
- *
16
- * @param {Object} options
17
- * @param {Object} options.spinner
18
- */
19
- module.exports = async function installPath( { spinner } ) {
20
- // Stop the spinner so that stdout is not polluted.
21
- spinner.stop();
22
-
23
- const config = await loadConfig( path.resolve( '.' ) );
24
-
25
- if ( ! existsSync( config.workDirectoryPath ) ) {
26
- console.error(
27
- 'wp-env has not yet been initialized. Please run `wp-env start` first.'
28
- );
29
- process.exit( 1 );
30
- }
31
-
32
- console.log( config.workDirectoryPath );
33
- };