Skip to content

Commit 9aa1bdd

Browse files
committed
Build/Test Tools: Remove PHP requirement for the build script.
In [61873], the `build` script started failing in some environemnts due to logic that added a requirement for `php-cli`. While WordPress itself cannot be run without PHP, the build script has never required PHP to be present to prepare `wordpress-develop` for use. This adjusts the relevant code to make use of the `php-array-reader` package instead. Reviewed by peterwilsoncc. Props dmsnell, peterwilsoncc, gaisma22, SirLouen, sabernhardt, manhar. Fixes #64925. See #64393. git-svn-id: https://develop.svn.wordpress.org/trunk@62157 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8eb4dc9 commit 9aa1bdd

3 files changed

Lines changed: 24 additions & 31 deletions

File tree

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"grunt-webpack": "7.0.1",
6767
"install-changed": "1.1.0",
6868
"json2php": "0.0.12",
69+
"php-array-reader": "2.1.3",
6970
"postcss": "8.5.8",
7071
"prettier": "npm:wp-prettier@3.0.3",
7172
"qunit": "~2.25.0",

tools/gutenberg/copy.js

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* @package WordPress
1010
*/
1111

12-
const child_process = require( 'child_process' );
1312
const fs = require( 'fs' );
1413
const path = require( 'path' );
1514
const json2php = require( 'json2php' );
15+
const { fromString } = require( 'php-array-reader' );
1616

1717
// Paths.
1818
const rootDir = path.resolve( __dirname, '../..' );
@@ -25,11 +25,7 @@ const gutenbergBuildDir = path.join( gutenbergDir, 'build' );
2525
*/
2626
const args = process.argv.slice( 2 );
2727
const buildDirArg = args.find( ( arg ) => arg.startsWith( '--build-dir=' ) );
28-
const buildTarget = buildDirArg
29-
? buildDirArg.split( '=' )[ 1 ]
30-
: args.includes( '--dev' )
31-
? 'src'
32-
: 'build';
28+
const buildTarget = 'src';
3329

3430
const wpIncludesDir = path.join( rootDir, buildTarget, 'wp-includes' );
3531

@@ -78,36 +74,14 @@ const COPY_CONFIG = {
7874
* Given a path to a PHP file which returns a single value, converts that
7975
* value into a native JavaScript value (limited by JSON serialization).
8076
*
81-
* @throws Error when PHP source file unable to be read, or PHP is unavailable.
77+
* @throws Error when PHP source file unable to be read or parsed.
8278
*
8379
* @param {string} phpFilepath Absolute path of PHP file returning a single value.
8480
* @return {Object|Array} JavaScript representation of value from input file.
8581
*/
8682
function readReturnedValueFromPHPFile( phpFilepath ) {
87-
const results = child_process.spawnSync(
88-
'php',
89-
[ '-r', '$path = file_get_contents( "php://stdin" ); if ( ! is_file( $path ) ) { die( 1 ); } try { $data = require $path; } catch ( \\Throwable $e ) { die( 2 ); } $json = json_encode( $data ); if ( ! is_string( $json ) ) { die( 3 ); } echo $json;' ],
90-
{
91-
encoding: 'utf8',
92-
input: phpFilepath,
93-
}
94-
);
95-
96-
switch ( results.status ) {
97-
case 0:
98-
return JSON.parse( results.stdout );
99-
100-
case 1:
101-
throw new Error( `Could not read PHP source file: '${ phpFilepath }'` );
102-
103-
case 2:
104-
throw new Error( `PHP source file did not return value when imported: '${ phpFilepath }'` );
105-
106-
case 3:
107-
throw new Error( `Could not serialize PHP source value into JSON: '${ phpFilepath }'` );
108-
}
109-
110-
throw new Error( `Unknown error while reading PHP source file: '${ phpFilepath }'` );
83+
const content = fs.readFileSync( phpFilepath, 'utf8' );
84+
return fromString( content );
11185
}
11286

11387
/**

0 commit comments

Comments
 (0)