Make WordPress Core

Changeset 54289


Ignore:
Timestamp:
09/23/2022 08:25:45 AM (2 years ago)
Author:
gziolo
Message:

Build: Improve how combined assets are generated

Allows to revert changes applied in [54277] - temporary workaround for the failing Test NPM CI check on Windows.

Improvements included:

  • generate combined asset files for both production and development
  • store in the repository only the production version of the combined assets for packages, we use everything else only in development
  • to make unit tests work, ensure that they ignore react fast refresh and use the production version of combined assets that are present in the source code

Props bernhard-reiter, jsnajdr, clorith, wildworks.
Fixes #56615.

Location:
trunk
Files:
1 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/test-npm.yml

    r54277 r54289  
    5656    timeout-minutes: 20
    5757    if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
    58     continue-on-error: ${{ matrix.os == 'windows-latest' }}
    5958    strategy:
    6059      fail-fast: false
  • trunk/.gitignore

    r54235 r54289  
    2828/src/wp-admin/css/colors/*/*.css
    2929/src/wp-admin/js
     30/src/wp-includes/assets/*
     31!/src/wp-includes/assets/script-loader-packages.min.php
    3032/src/wp-includes/js
    3133/src/wp-includes/css/dist
  • trunk/Gruntfile.js

    r54276 r54289  
    126126                WORKING_DIR + 'wp-includes/assets/*',
    127127                WORKING_DIR + 'wp-includes/css/dist/',
    128                 '!' + WORKING_DIR + 'wp-includes/assets/script-loader-*.php'
     128                '!' + WORKING_DIR + 'wp-includes/assets/script-loader-packages.min.php'
    129129            ],
    130130            dynamic: {
  • trunk/src/wp-includes/assets

    • Property svn:ignore set to
      script-loader-packages.php
      script-loader-react-*.php
  • trunk/src/wp-includes/script-loader.php

    r54267 r54289  
    228228        ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
    229229        || empty( $scripts->registered['react'] )
     230        || defined( 'WP_RUN_CORE_TESTS' )
    230231    ) {
    231232        return;
     
    265266 */
    266267function wp_default_packages_scripts( $scripts ) {
    267     $suffix = wp_scripts_get_suffix();
    268 
     268    $suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix();
    269269    /*
    270270     * Expects multidimensional array like:
     
    274274     *     'api-fetch.js' => array(...
    275275     */
    276     $assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
    277 
    278     foreach ( $assets as $package_name => $package_data ) {
    279         $basename = basename( $package_name, '.js' );
     276    $assets = include ABSPATH . WPINC . "/assets/script-loader-packages{$suffix}.php";
     277
     278    foreach ( $assets as $file_name => $package_data ) {
     279        $basename = str_replace( $suffix . '.js', '', basename( $file_name ) );
    280280        $handle   = 'wp-' . $basename;
    281281        $path     = "/wp-includes/js/dist/{$basename}{$suffix}.js";
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r54142 r54289  
    737737        $expected .= "<script type='text/javascript' id='test-example-js-before'>\nconsole.log(\"before\");\n</script>\n";
    738738        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    739         $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/i18n{$suffix}.js' id='wp-i18n-js'></script>\n";
     739        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/i18n.min.js' id='wp-i18n-js'></script>\n";
    740740        $expected .= "<script type='text/javascript' id='wp-i18n-js-after'>\n";
    741741        $expected .= "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );\n";
    742742        $expected .= "</script>\n";
    743         $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y{$suffix}.js' id='wp-a11y-js'></script>\n";
     743        $expected .= "<script type='text/javascript' src='/wp-includes/js/dist/a11y.min.js' id='wp-a11y-js'></script>\n";
    744744        $expected .= "<script type='text/javascript' src='http://example2.com' id='test-example2-js'></script>\n";
    745745        $expected .= "<script type='text/javascript' id='test-example2-js-after'>\nconsole.log(\"after\");\n</script>\n";
  • trunk/tools/webpack/development.js

    r53140 r54289  
    3636            },
    3737            plugins: [ new DependencyExtractionWebpackPlugin( {
    38                 outputFilename: '../../../assets/script-loader-[name].php',
     38                outputFilename: `../../../assets/script-loader-[name]${ suffix }.php`,
    3939            } ) ],
    4040        },
     
    5454                new DependencyExtractionWebpackPlugin( {
    5555                    useDefaults: false,
    56                     outputFilename: '../../../assets/script-loader-[name].php'
     56                    outputFilename: `../../../assets/script-loader-[name]${ suffix }.php`
    5757                } ),
    5858            ],
  • trunk/tools/webpack/packages.js

    r54257 r54289  
    159159                injectPolyfill: true,
    160160                combineAssets: true,
    161                 combinedOutputFile: '../../assets/script-loader-packages.php',
     161                combinedOutputFile: `../../assets/script-loader-packages${ suffix }.php`,
    162162            } ),
    163163            new CopyWebpackPlugin( {
Note: See TracChangeset for help on using the changeset viewer.