Skip to content

Commit fe07bf3

Browse files
committed
Simplify build
1 parent c207b12 commit fe07bf3

File tree

3 files changed

+15
-52
lines changed

3 files changed

+15
-52
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://develop.svn.wordpress.org/trunk"
88
},
99
"gutenberg": {
10-
"ref": "dbb0e0f6bd414445ad52d3aec967ee0900e9167c"
10+
"ref": "c5a9e02338f37d8d7c80570aaaaff261e3f9d198"
1111
},
1212
"engines": {
1313
"node": ">=20.10.0",

tools/gutenberg/build-gutenberg.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const { spawn } = require( 'child_process' );
1313
const fs = require( 'fs' );
1414
const path = require( 'path' );
1515

16-
// Constants
17-
const GUTENBERG_BUILD_COMMAND = 'npm run build';
18-
1916
// Paths
2017
const rootDir = path.resolve( __dirname, '../..' );
2118
const gutenbergDir = path.join( rootDir, 'gutenberg' );
@@ -97,7 +94,6 @@ async function main() {
9794
}
9895

9996
console.log( '✅ Gutenberg directory found' );
100-
console.log( ` Build command: ${ GUTENBERG_BUILD_COMMAND }` );
10197

10298
// Modify Gutenberg's package.json for Core build
10399
console.log( '\n⚙️ Configuring build for WordPress Core...' );
@@ -124,17 +120,20 @@ async function main() {
124120
process.exit( 1 );
125121
}
126122

127-
// Parse build command
128-
const [ cmd, ...args ] = GUTENBERG_BUILD_COMMAND.split( ' ' );
129-
130123
// Build Gutenberg
131-
console.log( '\n🔨 Building Gutenberg...' );
124+
console.log( '\n🔨 Building Gutenberg for WordPress Core...' );
132125
console.log( ' (This may take a few minutes)' );
133126

134127
const startTime = Date.now();
135128

136129
try {
137-
await exec( cmd, args, { cwd: gutenbergDir } );
130+
// On Windows, shell mode is used and needs the argument wrapped in quotes
131+
// On Unix, arguments are passed directly without shell parsing
132+
const baseUrlArg = process.platform === 'win32'
133+
? '--base-url="includes_url( \'build\' )"'
134+
: '--base-url=includes_url( \'build\' )';
135+
136+
await exec( 'npm', [ 'run', 'build', '--', baseUrlArg ], { cwd: gutenbergDir } );
138137

139138
const duration = Math.round( ( Date.now() - startTime ) / 1000 );
140139
console.log( `✅ Build completed in ${ duration }s` );

tools/gutenberg/copy-gutenberg-build.js

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ function generateScriptModulesPackages() {
253253
if ( match ) {
254254
// Parse PHP array to JavaScript object
255255
const assetData = parsePHPArray( match[1] );
256-
257-
// Create entries for both minified and non-minified versions
258256
assetsMin[ jsPathMin ] = assetData;
259257
assetsRegular[ jsPathRegular ] = assetData;
260258
}
@@ -680,52 +678,18 @@ function parsePHPArray( phpArrayContent ) {
680678
function transformPHPContent( content, srcPath, destPath ) {
681679
let transformed = content;
682680

683-
// Replace plugins_url() with includes_url()
684-
// Handles patterns like: plugins_url( 'build/...' . $var, dirname( __FILE__ ) )
685-
transformed = transformed.replace(
686-
/plugins_url\(\s*([^,]+),\s*(?:dirname\(\s*__FILE__\s*\)|__FILE__)\s*\)/g,
687-
( match, firstArg ) => {
688-
return `includes_url( ${ firstArg.trim() } )`;
689-
}
690-
);
691-
692-
// Replace plugin_dir_path( __FILE__ ) with ABSPATH . WPINC . '/build/'
693-
transformed = transformed.replace(
694-
/plugin_dir_path\(\s*__FILE__\s*\)/g,
695-
"ABSPATH . WPINC . '/build/'"
696-
);
697-
698-
// Replace dirname( __FILE__ ) patterns in path construction
681+
// Fix boot module asset file path for Core's different directory structure
682+
// FROM: __DIR__ . '/../../modules/boot/index.min.asset.php'
683+
// TO: ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php'
684+
// This is needed because Core copies modules to a different location than the plugin structure
699685
transformed = transformed.replace(
700-
/dirname\(\s*__FILE__\s*\)/g,
701-
"ABSPATH . WPINC . '/build'"
702-
);
703-
704-
// Replace __DIR__ with ABSPATH . WPINC . '/build'
705-
transformed = transformed.replace(
706-
/__DIR__\s*\.\s*['"]\/\.\.\/(.*?)['"]/g,
707-
( match, relativePath ) => {
708-
return `ABSPATH . WPINC . '/build/${ relativePath }'`;
709-
}
686+
/__DIR__\s*\.\s*['"]\/\.\.\/\.\.\/modules\/boot\/index\.min\.asset\.php['"]/g,
687+
"ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php'"
710688
);
711689

712690
// Special transformations for page-wp-admin.php files
713691
if ( destPath.includes( 'page-wp-admin.php' ) ) {
714-
// Fix boot module asset file path
715-
// FROM: ABSPATH . WPINC . '/build/' . '../../modules/boot/index.min.asset.php'
716-
// TO: ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php'
717-
transformed = transformed.replace(
718-
/ABSPATH\s*\.\s*WPINC\s*\.\s*['"]\/build\/['"]\s*\.\s*['"]\.\.\/\.\.\/modules\/boot\/index\.min\.asset\.php['"]/g,
719-
"ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php'"
720-
);
721692

722-
// Fix loader.js path - replace plugin_dir_url with data URI for empty module
723-
// FROM: plugin_dir_url( __FILE__ ) . 'loader.js'
724-
// TO: 'data:text/javascript,' (empty module for dependency registration only)
725-
transformed = transformed.replace(
726-
/plugin_dir_url\(\s*__FILE__\s*\)\s*\.\s*['"]loader\.js['"]/g,
727-
"'data:text/javascript,'"
728-
);
729693

730694
// Fix enqueue condition to also work for direct page files (e.g., fonts.php)
731695
// This allows the page to work both via menu (admin.php?page=X) and direct file (X.php)

0 commit comments

Comments
 (0)