Skip to content

Commit a8dbf14

Browse files
youknowriaddmsnell
authored andcommitted
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. git-svn-id: https://develop.svn.wordpress.org/trunk@61679 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 135fa9e commit a8dbf14

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

tools/gutenberg/build-gutenberg.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,22 @@ async function main() {
141141
const startTime = Date.now();
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

155162
const duration = Math.round( ( Date.now() - startTime ) / 1000 );

0 commit comments

Comments
 (0)