Make WordPress Core

Changeset 61679


Ignore:
Timestamp:
02/18/2026 08:12:50 PM (7 months ago)
Author:
youknowriad
Message:

Build: Fix Gutenberg build base-url argument passing across platforms.

When building Gutenberg, the --base-url argument was forwarded through
npm run build --, which passes arguments through a shell layer. The
argument value includes_url( 'build/' ) contains spaces, parentheses,
and single quotes that could be mangled by shell parsing on some
platforms, causing the generated constants.php to lose the trailing
slash in build_url.

This invokes node bin/build.mjs directly instead, bypassing npm's
shell forwarding entirely. The argument is passed as a single array
element via spawn, so it arrives intact regardless of platform.

Props youknowriad, desrosj.
See #64656.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/gutenberg/build-gutenberg.js

    r61673 r61679  
    142142
    143143        try {
    144                 // On Windows, shell mode is used and needs the argument wrapped in quotes
    145                 // On Unix, arguments are passed directly without shell parsing
    146                 const baseUrlArg =
    147                         process.platform === 'win32'
    148                                 ? '--base-url="includes_url( \'build/\' )"'
    149                                 : "--base-url=includes_url( 'build/' )";
    150 
    151                 await exec( 'npm', [ 'run', 'build', '--', '--skip-types', baseUrlArg ], {
     144                // Invoke the build script directly with node instead of going through
     145                // `npm run build --` to avoid shell argument mangling of the base-url
     146                // value (which contains spaces, parentheses, and single quotes).
     147                // The PATH is extended with node_modules/.bin so that bin commands
     148                // like `wp-build` are found, matching what npm would normally provide.
     149                const binPath = path.join( gutenbergDir, 'node_modules', '.bin' );
     150                await exec( 'node', [
     151                        'bin/build.mjs',
     152                        '--skip-types',
     153                        "--base-url=includes_url( 'build/' )",
     154                ], {
    152155                        cwd: gutenbergDir,
     156                        env: {
     157                                ...process.env,
     158                                PATH: binPath + path.delimiter + process.env.PATH,
     159                        },
    153160                } );
    154161
Note: See TracChangeset for help on using the changeset viewer.