@wordpress/env 10.29.1-next.f34ab90e9.0 → 10.30.1-next.836ecdcae.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 +28 -0
- package/lib/cli.js +7 -0
- package/lib/commands/start.js +3 -0
- package/lib/init-config.js +60 -0
- package/lib/parse-spx-mode.js +41 -0
- package/lib/test/parse-spx-mode.js +32 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -289,6 +289,11 @@ Options:
|
|
|
289
289
|
them in a comma-separated list: `--xdebug=develop,coverage`. See
|
|
290
290
|
https://xdebug.org/docs/all_settings#mode for information about
|
|
291
291
|
Xdebug modes. [string]
|
|
292
|
+
--spx Enables SPX profiling. If not passed, SPX is turned off. If no
|
|
293
|
+
mode is set, uses "enabled". SPX is a simple profiling extension
|
|
294
|
+
with a built-in web UI. See
|
|
295
|
+
https://github.com/NoiseByNorthwest/php-spx for more information.
|
|
296
|
+
[string]
|
|
292
297
|
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
|
|
293
298
|
```
|
|
294
299
|
|
|
@@ -756,6 +761,29 @@ php_value memory_limit 2G
|
|
|
756
761
|
|
|
757
762
|
This is useful if there are options you'd like to add to `php.ini`, which is difficult to access in this environment.
|
|
758
763
|
|
|
764
|
+
### Using SPX Profiling
|
|
765
|
+
|
|
766
|
+
SPX is a simple profiling extension for PHP that provides low-overhead profiling with a built-in web UI. When enabled with `--spx`, you can access the SPX profiling interface to analyze your application's performance.
|
|
767
|
+
|
|
768
|
+
To enable SPX profiling:
|
|
769
|
+
|
|
770
|
+
```sh
|
|
771
|
+
wp-env start --spx
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
Once enabled, you can access the SPX web UI by visiting any page in your WordPress environment with the query parameters `?SPX_KEY=dev&SPX_UI_URI=/`. For example:
|
|
775
|
+
|
|
776
|
+
- Development site: `http://localhost:8888/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
777
|
+
- Test site: `http://localhost:8889/?SPX_KEY=dev&SPX_UI_URI=/`
|
|
778
|
+
|
|
779
|
+
From the SPX interface, you can:
|
|
780
|
+
- Enable profiling for subsequent requests
|
|
781
|
+
- View flame graphs and performance metrics
|
|
782
|
+
- Analyze function call timelines
|
|
783
|
+
- Examine memory usage and other performance data
|
|
784
|
+
|
|
785
|
+
SPX provides a more lightweight alternative to Xdebug for profiling, with minimal performance overhead and an intuitive web-based interface.
|
|
786
|
+
|
|
759
787
|
## Contributing to this package
|
|
760
788
|
|
|
761
789
|
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
package/lib/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ const { execSync } = require( 'child_process' );
|
|
|
14
14
|
const pkg = require( '../package.json' );
|
|
15
15
|
const env = require( './env' );
|
|
16
16
|
const parseXdebugMode = require( './parse-xdebug-mode' );
|
|
17
|
+
const parseSpxMode = require( './parse-spx-mode' );
|
|
17
18
|
const {
|
|
18
19
|
RUN_CONTAINERS,
|
|
19
20
|
validateRunContainer,
|
|
@@ -139,6 +140,12 @@ module.exports = function cli() {
|
|
|
139
140
|
coerce: parseXdebugMode,
|
|
140
141
|
type: 'string',
|
|
141
142
|
} );
|
|
143
|
+
args.option( 'spx', {
|
|
144
|
+
describe:
|
|
145
|
+
'Enables SPX profiling. If not passed, SPX is turned off. If no mode is set, uses "enabled". SPX is a simple profiling extension with a built-in web UI. See https://github.com/NoiseByNorthwest/php-spx for more information.',
|
|
146
|
+
coerce: parseSpxMode,
|
|
147
|
+
type: 'string',
|
|
148
|
+
} );
|
|
142
149
|
args.option( 'scripts', {
|
|
143
150
|
type: 'boolean',
|
|
144
151
|
describe: 'Execute any configured lifecycle scripts.',
|
package/lib/commands/start.js
CHANGED
|
@@ -46,6 +46,7 @@ const CONFIG_CACHE_KEY = 'config_checksum';
|
|
|
46
46
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
47
47
|
* @param {boolean} options.update If true, update sources.
|
|
48
48
|
* @param {string} options.xdebug The Xdebug mode to set.
|
|
49
|
+
* @param {string} options.spx The SPX mode to set.
|
|
49
50
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
50
51
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
51
52
|
*/
|
|
@@ -53,6 +54,7 @@ module.exports = async function start( {
|
|
|
53
54
|
spinner,
|
|
54
55
|
update,
|
|
55
56
|
xdebug,
|
|
57
|
+
spx,
|
|
56
58
|
scripts,
|
|
57
59
|
debug,
|
|
58
60
|
} ) {
|
|
@@ -63,6 +65,7 @@ module.exports = async function start( {
|
|
|
63
65
|
spinner,
|
|
64
66
|
debug,
|
|
65
67
|
xdebug,
|
|
68
|
+
spx,
|
|
66
69
|
writeChanges: true,
|
|
67
70
|
} );
|
|
68
71
|
|
package/lib/init-config.js
CHANGED
|
@@ -26,6 +26,7 @@ const buildDockerComposeConfig = require( './build-docker-compose-config' );
|
|
|
26
26
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
27
27
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
28
28
|
* @param {string} options.xdebug The Xdebug mode to set. Defaults to "off".
|
|
29
|
+
* @param {string} options.spx The SPX mode to set. Defaults to "off".
|
|
29
30
|
* @param {boolean} options.writeChanges If true, writes the parsed config to the
|
|
30
31
|
* required docker files like docker-compose
|
|
31
32
|
* and Dockerfile. By default, this is false
|
|
@@ -37,6 +38,7 @@ module.exports = async function initConfig( {
|
|
|
37
38
|
spinner,
|
|
38
39
|
debug,
|
|
39
40
|
xdebug = 'off',
|
|
41
|
+
spx = 'off',
|
|
40
42
|
writeChanges = false,
|
|
41
43
|
} ) {
|
|
42
44
|
const config = await loadConfig( path.resolve( '.' ) );
|
|
@@ -47,6 +49,11 @@ module.exports = async function initConfig( {
|
|
|
47
49
|
// so that Docker will rebuild the image whenever the xdebug flag changes.
|
|
48
50
|
config.xdebug = xdebug;
|
|
49
51
|
|
|
52
|
+
// Adding this to the config allows the start command to understand that the
|
|
53
|
+
// config has changed when only the spx param has changed. This is needed
|
|
54
|
+
// so that Docker will rebuild the image whenever the spx flag changes.
|
|
55
|
+
config.spx = spx;
|
|
56
|
+
|
|
50
57
|
const dockerComposeConfig = buildDockerComposeConfig( config );
|
|
51
58
|
|
|
52
59
|
if ( config.debug ) {
|
|
@@ -238,6 +245,12 @@ RUN echo "#$HOST_UID ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`;
|
|
|
238
245
|
config.env[ env ].phpVersion
|
|
239
246
|
);
|
|
240
247
|
|
|
248
|
+
dockerFileContent += getSpxConfig(
|
|
249
|
+
config.spx,
|
|
250
|
+
config.env[ env ].phpVersion,
|
|
251
|
+
service
|
|
252
|
+
);
|
|
253
|
+
|
|
241
254
|
// Add better PHP settings.
|
|
242
255
|
dockerFileContent += `
|
|
243
256
|
RUN echo 'upload_max_filesize = 1G' >> /usr/local/etc/php/php.ini
|
|
@@ -309,3 +322,50 @@ RUN echo 'xdebug.start_with_request=yes' >> /usr/local/etc/php/php.ini
|
|
|
309
322
|
RUN echo 'xdebug.mode=${ xdebugMode }' >> /usr/local/etc/php/php.ini
|
|
310
323
|
RUN echo 'xdebug.client_host="host.docker.internal"' >> /usr/local/etc/php/php.ini`;
|
|
311
324
|
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Gets the SPX config based on the options in the config object.
|
|
328
|
+
*
|
|
329
|
+
* @param {string} spxMode The SPX mode set in the config.
|
|
330
|
+
* @param {string} phpVersion The php version set in the environment.
|
|
331
|
+
* @param {string} service The service name.
|
|
332
|
+
* @return {string} The SPX config -- can be an empty string when it's not used.
|
|
333
|
+
*/
|
|
334
|
+
function getSpxConfig( spxMode = 'off', phpVersion, service ) {
|
|
335
|
+
if ( spxMode === 'off' || service === 'cli' ) {
|
|
336
|
+
return '';
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if ( phpVersion ) {
|
|
340
|
+
const versionTokens = phpVersion.split( '.' );
|
|
341
|
+
const majorVer = parseInt( versionTokens[ 0 ] );
|
|
342
|
+
const minorVer = parseInt( versionTokens[ 1 ] );
|
|
343
|
+
|
|
344
|
+
if ( isNaN( majorVer ) || isNaN( minorVer ) ) {
|
|
345
|
+
throw new ValidationError(
|
|
346
|
+
'Something went wrong when parsing the PHP version.'
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// SPX requires PHP 5.4 or higher
|
|
351
|
+
if ( majorVer < 5 || ( majorVer === 5 && minorVer < 4 ) ) {
|
|
352
|
+
throw new ValidationError(
|
|
353
|
+
`Cannot use SPX with PHP < 5.4. Your PHP version is ${ phpVersion }.`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return `
|
|
359
|
+
# Install SPX profiler
|
|
360
|
+
RUN apt-get update -qy
|
|
361
|
+
RUN apt-get install -qy git zlib1g-dev
|
|
362
|
+
RUN cd /tmp && git clone https://github.com/NoiseByNorthwest/php-spx.git
|
|
363
|
+
RUN cd /tmp/php-spx && git checkout release/latest
|
|
364
|
+
RUN cd /tmp/php-spx && phpize && ./configure && make && make install
|
|
365
|
+
RUN docker-php-ext-enable spx
|
|
366
|
+
RUN echo 'spx.http_enabled=1' >> /usr/local/etc/php/php.ini
|
|
367
|
+
RUN echo 'spx.http_key="dev"' >> /usr/local/etc/php/php.ini
|
|
368
|
+
RUN echo 'spx.http_ip_whitelist="*"' >> /usr/local/etc/php/php.ini
|
|
369
|
+
RUN echo 'spx.data_dir="/tmp/spx"' >> /usr/local/etc/php/php.ini
|
|
370
|
+
RUN mkdir -p /tmp/spx && chmod 777 /tmp/spx`;
|
|
371
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// SPX is a simple profiling extension for PHP
|
|
4
|
+
// See https://github.com/NoiseByNorthwest/php-spx
|
|
5
|
+
const SPX_MODES = [ 'off', 'enabled' ];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom parsing for the SPX mode set via yargs. This function ensures three things:
|
|
9
|
+
* 1. If the --spx flag was not set, set it to 'off'.
|
|
10
|
+
* 2. If the --spx flag was set by itself, default to 'enabled'.
|
|
11
|
+
* 3. If the --spx flag includes modes, make sure they are accepted by SPX.
|
|
12
|
+
*
|
|
13
|
+
* @param {string|undefined} value The user-set mode of SPX; undefined if there is no --spx flag.
|
|
14
|
+
* @return {string} The SPX mode to use with defaults applied.
|
|
15
|
+
*/
|
|
16
|
+
module.exports = function parseSpxMode( value ) {
|
|
17
|
+
if ( value === undefined ) {
|
|
18
|
+
return 'off';
|
|
19
|
+
}
|
|
20
|
+
if ( typeof value !== 'string' ) {
|
|
21
|
+
throwSpxModeError( value );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( value.length === 0 || value === 'undefined' ) {
|
|
25
|
+
return 'enabled';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ( ! SPX_MODES.includes( value ) ) {
|
|
29
|
+
throwSpxModeError( value );
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function throwSpxModeError( value ) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`"${ value }" is not a mode recognized by SPX. Valid modes are: ${ SPX_MODES.join(
|
|
38
|
+
', '
|
|
39
|
+
) }`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal dependencies
|
|
5
|
+
*/
|
|
6
|
+
const parseSpxMode = require( '../parse-spx-mode' );
|
|
7
|
+
|
|
8
|
+
describe( 'parseSpxMode', () => {
|
|
9
|
+
it( 'errors with invalid values', () => {
|
|
10
|
+
const errorMessage = 'is not a mode recognized by SPX';
|
|
11
|
+
expect( () => parseSpxMode( true ) ).toThrow( errorMessage );
|
|
12
|
+
expect( () => parseSpxMode( false ) ).toThrow( errorMessage );
|
|
13
|
+
expect( () => parseSpxMode( 1 ) ).toThrow( errorMessage );
|
|
14
|
+
} );
|
|
15
|
+
|
|
16
|
+
it( 'sets the SPX mode to "off" if no --spx flag is passed', () => {
|
|
17
|
+
const result = parseSpxMode( undefined );
|
|
18
|
+
expect( result ).toBe( 'off' );
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
it( 'sets the SPX mode to "enabled" if no mode is specified', () => {
|
|
22
|
+
const result = parseSpxMode( '' );
|
|
23
|
+
expect( result ).toBe( 'enabled' );
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
it( 'errors with a mix of valid and invalid modes', () => {
|
|
27
|
+
const fakeMode = 'invalidmode';
|
|
28
|
+
expect( () => parseSpxMode( `enabled,${ fakeMode }` ) ).toThrow(
|
|
29
|
+
fakeMode
|
|
30
|
+
);
|
|
31
|
+
} );
|
|
32
|
+
} );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.30.1-next.836ecdcae.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": "3e60b4c1e78d7b27acbf1d7dd172bbd64358a0f2"
|
|
59
59
|
}
|