Make WordPress Core

Changeset 62072


Ignore:
Timestamp:
03/20/2026 04:16:33 AM (8 days ago)
Author:
desrosj
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r62060 r62072  
    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";
  • trunk/src/wp-includes/script-modules.php

    r61794 r62072  
    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
     
    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
  • trunk/tools/gutenberg/copy.js

    r62071 r62072  
    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 */
    241241function generateScriptModulesPackages() {
    242242    const modulesDir = path.join( gutenbergBuildDir, 'modules' );
    243     const assetsMin = {};
    244     const assetsRegular = {};
     243    const assets = {};
    245244
    246245    /**
     
    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(
     
    290286    processDirectory( modulesDir, modulesDir );
    291287
    292     // Generate both minified and non-minified PHP files using json2php.
    293     const phpContentMin =
     288    const phpContent =
    294289        '<?php return ' +
    295290        json2php.make( {
    296291            linebreak: '\n',
    297             indent: '  ',
     292            indent: '\t',
    298293            shortArraySyntax: false,
    299         } )( assetsMin ) +
     294        } )( assets ) +
    300295        ';';
    301296
    302     const phpContentRegular =
    303         '<?php return ' +
    304         json2php.make( {
    305             linebreak: '\n',
    306             indent: '  ',
    307             shortArraySyntax: false,
    308         } )( assetsRegular ) +
    309         ';';
    310 
    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`
    326     );
    327 }
    328 
    329 /**
    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.
     306        `   ✅ Generated with ${ Object.keys( assets ).length } modules`
     307    );
     308}
     309
     310/**
     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 */
    334314function generateScriptLoaderPackages() {
    335315    const scriptsDir = path.join( gutenbergBuildDir, 'scripts' );
    336     const assetsMin = {};
    337     const assetsRegular = {};
     316    const assets = {};
    338317
    339318    if ( ! fs.existsSync( scriptsDir ) ) {
     
    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(
     
    380354    }
    381355
    382     // Generate both minified and non-minified PHP files using json2php.
    383     const phpContentMin =
     356    const phpContent =
    384357        '<?php return ' +
    385358        json2php.make( {
    386359            linebreak: '\n',
    387             indent: '  ',
     360            indent: '\t',
    388361            shortArraySyntax: false,
    389         } )( assetsMin ) +
     362        } )( assets ) +
    390363        ';';
    391364
    392     const phpContentRegular =
    393         '<?php return ' +
    394         json2php.make( {
    395             linebreak: '\n',
    396             indent: '  ',
    397             shortArraySyntax: false,
    398         } )( assetsRegular ) +
    399         ';';
    400 
    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}
     
    553512        json2php.make( {
    554513            linebreak: '\n',
    555             indent: '  ',
     514            indent: '\t',
    556515            shortArraySyntax: false,
    557516        } )( blocks ) +
Note: See TracChangeset for help on using the changeset viewer.