Skip to content

Commit 7ac6151

Browse files
committed
Build/Test Tools: Stop generating unminified .min file.
The generated `wp-includes/assets/script-loader-packages.min.php` and `wp-includes/assets/script-modules-packages.min.php` files are not actually minified. Additionally, the only purpose they serve is to pass a different script handle to the script loader (`.min.js` vs. `.js`). This eliminates the need for those files entirely since the difference in file size is negligible, and a human-readable version is more useful. Props peterwilsoncc, desrosj. Fixes #64909. git-svn-id: https://develop.svn.wordpress.org/trunk@62072 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f45f9e1 commit 7ac6151

3 files changed

Lines changed: 36 additions & 75 deletions

File tree

src/wp-includes/script-loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ function wp_default_packages_scripts( $scripts ) {
281281
* 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
282282
* 'api-fetch.js' => array(...
283283
*/
284-
$assets_file = ABSPATH . WPINC . "/assets/script-loader-packages{$suffix}.php";
284+
$assets_file = ABSPATH . WPINC . '/assets/script-loader-packages.php';
285285
$assets = file_exists( $assets_file ) ? include $assets_file : array();
286286

287287
foreach ( $assets as $file_name => $package_data ) {
288-
$basename = str_replace( $suffix . '.js', '', basename( $file_name ) );
288+
$basename = str_replace( '.js', '', basename( $file_name ) );
289289
$handle = 'wp-' . $basename;
290290
$path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
291291

src/wp-includes/script-modules.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ function wp_default_script_modules() {
149149
/*
150150
* Expects multidimensional array like:
151151
*
152-
* 'interactivity/index.min.js' => array('dependencies' => array(…), 'version' => '…'),
153-
* 'interactivity-router/index.min.js' => array('dependencies' => array(…), 'version' => '…'),
154-
* 'block-library/navigation/view.min.js' => …
152+
* 'interactivity/index.js' => array('dependencies' => array(…), 'version' => '…'),
153+
* 'interactivity-router/index.js' => array('dependencies' => array(…), 'version' => '…'),
154+
* 'block-library/navigation/view.js' => …
155155
*/
156-
$assets_file = ABSPATH . WPINC . "/assets/script-modules-packages{$suffix}.php";
156+
$assets_file = ABSPATH . WPINC . '/assets/script-modules-packages.php';
157157
$assets = file_exists( $assets_file ) ? include $assets_file : array();
158158

159159
foreach ( $assets as $file_name => $script_module_data ) {
@@ -192,8 +192,10 @@ function wp_default_script_modules() {
192192

193193
// VIPS files are always minified — the non-minified versions are not
194194
// shipped because they are ~10MB of inlined WASM with no debugging value.
195-
if ( str_starts_with( $file_name, 'vips/' ) && ! str_contains( $file_name, '.min.' ) ) {
195+
if ( str_starts_with( $file_name, 'vips/' ) ) {
196196
$file_name = str_replace( '.js', '.min.js', $file_name );
197+
} elseif ( '' !== $suffix ) {
198+
$file_name = str_replace( '.js', $suffix . '.js', $file_name );
197199
}
198200

199201
$path = includes_url( "js/dist/script-modules/{$file_name}" );

tools/gutenberg/copy.js

Lines changed: 27 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,13 @@ function copyBlockAssets( config ) {
234234
}
235235

236236
/**
237-
* Generate script-modules-packages.min.php from individual asset files.
238-
* Reads all view.min.asset.php files from modules/block-library and combines them
239-
* into a single PHP file.
237+
* Generate script-modules-packages.php from individual asset files.
238+
* Recursively scans the Gutenberg modules/ directory for *.min.asset.php files
239+
* and combines their contents into a single PHP file.
240240
*/
241241
function generateScriptModulesPackages() {
242242
const modulesDir = path.join( gutenbergBuildDir, 'modules' );
243-
const assetsMin = {};
244-
const assetsRegular = {};
243+
const assets = {};
245244

246245
/**
247246
* Recursively process directory to find .asset.php files.
@@ -267,16 +266,13 @@ function generateScriptModulesPackages() {
267266
const normalizedPath = relativePath
268267
.split( path.sep )
269268
.join( '/' );
270-
const jsPathMin = normalizedPath.replace(
271-
/\.asset\.php$/,
272-
'.js'
273-
);
274-
const jsPathRegular = jsPathMin.replace( /\.min\.js$/, '.js' );
269+
const jsPath = normalizedPath
270+
.replace( /\.asset\.php$/, '.js' )
271+
.replace( /\.min\.js$/, '.js' );
275272

276273
try {
277274
const assetData = readReturnedValueFromPHPFile( fullPath );
278-
assetsMin[ jsPathMin ] = assetData;
279-
assetsRegular[ jsPathRegular ] = assetData;
275+
assets[ jsPath ] = assetData;
280276
} catch ( error ) {
281277
console.error(
282278
` ⚠️ Error reading ${ relativePath }:`,
@@ -289,52 +285,35 @@ function generateScriptModulesPackages() {
289285

290286
processDirectory( modulesDir, modulesDir );
291287

292-
// Generate both minified and non-minified PHP files using json2php.
293-
const phpContentMin =
294-
'<?php return ' +
295-
json2php.make( {
296-
linebreak: '\n',
297-
indent: ' ',
298-
shortArraySyntax: false,
299-
} )( assetsMin ) +
300-
';';
301-
302-
const phpContentRegular =
288+
const phpContent =
303289
'<?php return ' +
304290
json2php.make( {
305291
linebreak: '\n',
306-
indent: ' ',
292+
indent: '\t',
307293
shortArraySyntax: false,
308-
} )( assetsRegular ) +
294+
} )( assets ) +
309295
';';
310296

311-
const outputPathMin = path.join(
312-
wpIncludesDir,
313-
'assets/script-modules-packages.min.php'
314-
);
315-
const outputPathRegular = path.join(
297+
const outputPath = path.join(
316298
wpIncludesDir,
317299
'assets/script-modules-packages.php'
318300
);
319301

320-
fs.mkdirSync( path.dirname( outputPathMin ), { recursive: true } );
321-
fs.writeFileSync( outputPathMin, phpContentMin );
322-
fs.writeFileSync( outputPathRegular, phpContentRegular );
302+
fs.mkdirSync( path.dirname( outputPath ), { recursive: true } );
303+
fs.writeFileSync( outputPath, phpContent );
323304

324305
console.log(
325-
` ✅ Generated with ${ Object.keys( assetsMin ).length } modules`
306+
` ✅ Generated with ${ Object.keys( assets ).length } modules`
326307
);
327308
}
328309

329310
/**
330-
* Generate script-loader-packages.php and script-loader-packages.min.php from individual asset files.
331-
* Reads all .min.asset.php files from scripts/ and combines them into PHP files for script registration.
332-
* Generates both minified and non-minified versions.
311+
* Generate script-loader-packages.php from individual asset files.
312+
* Reads all .min.asset.php files from scripts/ and combines them into a PHP file for script registration.
333313
*/
334314
function generateScriptLoaderPackages() {
335315
const scriptsDir = path.join( gutenbergBuildDir, 'scripts' );
336-
const assetsMin = {};
337-
const assetsRegular = {};
316+
const assets = {};
338317

339318
if ( ! fs.existsSync( scriptsDir ) ) {
340319
console.log( ' ⚠️ Scripts directory not found' );
@@ -365,12 +344,7 @@ function generateScriptLoaderPackages() {
365344
assetData.dependencies = [];
366345
}
367346

368-
// Create entries for both minified and non-minified versions.
369-
const jsPathMin = `${ entry.name }.min.js`;
370-
const jsPathRegular = `${ entry.name }.js`;
371-
372-
assetsMin[ jsPathMin ] = assetData;
373-
assetsRegular[ jsPathRegular ] = assetData;
347+
assets[ `${ entry.name }.js` ] = assetData;
374348
} catch ( error ) {
375349
console.error(
376350
` ⚠️ Error reading ${ entry.name }/index.min.asset.php:`,
@@ -379,40 +353,25 @@ function generateScriptLoaderPackages() {
379353
}
380354
}
381355

382-
// Generate both minified and non-minified PHP files using json2php.
383-
const phpContentMin =
384-
'<?php return ' +
385-
json2php.make( {
386-
linebreak: '\n',
387-
indent: ' ',
388-
shortArraySyntax: false,
389-
} )( assetsMin ) +
390-
';';
391-
392-
const phpContentRegular =
356+
const phpContent =
393357
'<?php return ' +
394358
json2php.make( {
395359
linebreak: '\n',
396-
indent: ' ',
360+
indent: '\t',
397361
shortArraySyntax: false,
398-
} )( assetsRegular ) +
362+
} )( assets ) +
399363
';';
400364

401-
const outputPathMin = path.join(
402-
wpIncludesDir,
403-
'assets/script-loader-packages.min.php'
404-
);
405-
const outputPathRegular = path.join(
365+
const outputPath = path.join(
406366
wpIncludesDir,
407367
'assets/script-loader-packages.php'
408368
);
409369

410-
fs.mkdirSync( path.dirname( outputPathMin ), { recursive: true } );
411-
fs.writeFileSync( outputPathMin, phpContentMin );
412-
fs.writeFileSync( outputPathRegular, phpContentRegular );
370+
fs.mkdirSync( path.dirname( outputPath ), { recursive: true } );
371+
fs.writeFileSync( outputPath, phpContent );
413372

414373
console.log(
415-
` ✅ Generated with ${ Object.keys( assetsMin ).length } packages`
374+
` ✅ Generated with ${ Object.keys( assets ).length } packages`
416375
);
417376
}
418377

@@ -552,7 +511,7 @@ function generateBlocksJson() {
552511
'<?php return ' +
553512
json2php.make( {
554513
linebreak: '\n',
555-
indent: ' ',
514+
indent: '\t',
556515
shortArraySyntax: false,
557516
} )( blocks ) +
558517
';';

0 commit comments

Comments
 (0)