Make WordPress Core

Changeset 62157


Ignore:
Timestamp:
03/27/2026 12:32:38 AM (32 hours ago)
Author:
desrosj
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r62061 r62157  
    8080                "install-changed": "1.1.0",
    8181                "json2php": "0.0.12",
     82                "php-array-reader": "2.1.3",
    8283                "postcss": "8.5.8",
    8384                "prettier": "npm:wp-prettier@3.0.3",
     
    2613826139            "dev": true
    2613926140        },
     26141        "node_modules/php-array-reader": {
     26142            "version": "2.1.3",
     26143            "resolved": "https://registry.npmjs.org/php-array-reader/-/php-array-reader-2.1.3.tgz",
     26144            "integrity": "sha512-FjgMmNfnbi76wsbzO/dWEeySt0WZpxv8q/7RH0XFPyNLxsfJSf97KKe/4Rgdmx/XRDGlbl8THU5ayKwGE3Xqrw==",
     26145            "dev": true,
     26146            "license": "MIT",
     26147            "dependencies": {
     26148                "php-parser": "^3.1.5"
     26149            }
     26150        },
     26151        "node_modules/php-parser": {
     26152            "version": "3.5.0",
     26153            "resolved": "https://registry.npmjs.org/php-parser/-/php-parser-3.5.0.tgz",
     26154            "integrity": "sha512-EHdzSckQNP86jQRCEsMYhs+YzS4BfvfxnyhvzHVhVRoRUGEMFi8f3xKfuS9xdChBazZSyvb10SZbqhYQLGBcQg==",
     26155            "dev": true,
     26156            "license": "BSD-3-Clause"
     26157        },
    2614026158        "node_modules/picocolors": {
    2614126159            "version": "1.1.1",
  • trunk/package.json

    r62150 r62157  
    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",
  • trunk/tools/gutenberg/copy.js

    r62081 r62157  
    1010 */
    1111
    12 const child_process = require( 'child_process' );
    1312const fs = require( 'fs' );
    1413const path = require( 'path' );
    1514const json2php = require( 'json2php' );
     15const { fromString } = require( 'php-array-reader' );
    1616
    1717// Paths.
     
    2626const args = process.argv.slice( 2 );
    2727const buildDirArg = args.find( ( arg ) => arg.startsWith( '--build-dir=' ) );
    28 const buildTarget = buildDirArg
    29     ? buildDirArg.split( '=' )[ 1 ]
    30     : args.includes( '--dev' )
    31     ? 'src'
    32     : 'build';
     28const buildTarget = 'src';
    3329
    3430const wpIncludesDir = path.join( rootDir, buildTarget, 'wp-includes' );
     
    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.
     
    8581 */
    8682function 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
Note: See TracChangeset for help on using the changeset viewer.