Make WordPress Core

Changeset 62079


Ignore:
Timestamp:
03/20/2026 04:31:45 PM (7 months ago)
Author:
desrosj
Message:

Build/Test Tools: Only include active, stable routes in build.

The registry.php file within the built assets from the gutenberg repository contains an accurate list of active, stable routes. However, the build/routes/ directory has the JavaScript and PHP files for all routes, regardless of their status.

This makes adjustments to the grunt copy tasks responsible for copying these files into the appropriate locations to extract the list of routes specified in the registry.php file so that only the required files are copied.

See #64393.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r62077 r62079  
    604604                                dest: SOURCE_DIR + 'wp-includes/certificates/ca-bundle.crt'
    605605                        },
    606                         // Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/, routes/).
     606                        // Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/).
    607607                        'gutenberg-php': {
    608608                                options: {
    … …  
    623623                                                'constants.php',
    624624                                                'pages/**/*.php',
    625                                                 'routes/**/*.php',
    626625                                        ],
    627626                                        dest: WORKING_DIR + 'wp-includes/build/',
    628627                                } ],
     628                        },
     629                        /*
     630                         * Only copy files relevant to the routes specified in the registry file.
     631                         *
     632                         * While the registry file does not contain any experimental routes, the `gutenberg/build/routes` directory
     633                         * includes the files for all registered routes. Only the files related to the routes specified in the
     634                         * registry should be included in the WordPress build.
     635                         *
     636                         * The `src` list is populated at task runtime by `routes:setup`, which reads the registry after
     637                         * `gutenberg:download` has run. See the `routes:setup` task registration for implementation details.
     638                         */
     639                        routes: {
     640                                expand: true,
     641                                cwd: 'gutenberg/build',
     642                                src: [],
     643                                dest: WORKING_DIR + 'wp-includes/build/',
    629644                        },
    630645                        'gutenberg-js': {
    … …  
    634649                                        src: [
    635650                                                'pages/**/*.js',
    636                                                 'routes/**/*.js',
    637651                                        ],
    638652                                        dest: WORKING_DIR + 'wp-includes/build/',
    … …  
    20592073        } );
    20602074
     2075        grunt.registerTask( 'routes:setup', 'Reads the routes registry and configures the copy:routes task.', function() {
     2076                const registryPath = 'gutenberg/build/routes/registry.php';
     2077                let registryContent;
     2078                try {
     2079                        registryContent = fs.readFileSync( registryPath, 'utf8' );
     2080                } catch ( e ) {
     2081                        grunt.fatal(
     2082                                'Route registry not found at ' + registryPath + '. Run `grunt gutenberg:download` first.'
     2083                        );
     2084                }
     2085                const namePattern = /'name'\s*=>\s*'([^']+)'/g;
     2086                const routeNames = [];
     2087                let match;
     2088                while ( ( match = namePattern.exec( registryContent ) ) !== null ) {
     2089                        routeNames.push( match[ 1 ] );
     2090                }
     2091
     2092                if ( routeNames.length === 0 ) {
     2093                        grunt.fatal(
     2094                                'No route names found in ' + registryPath + '. The format of the file may have changed.'
     2095                        );
     2096                }
     2097
     2098                const validName = /^[A-Za-z0-9_-]+$/;
     2099                routeNames.forEach( function( name ) {
     2100                        if ( ! validName.test( name ) ) {
     2101                                grunt.fatal(
     2102                                        'Invalid route name \'' + name + '\' in ' + registryPath + '. Expected only letters, digits, hyphens, and underscores.'
     2103                                );
     2104                        }
     2105                } );
     2106
     2107                grunt.config( [ 'copy', 'routes', 'src' ], [ 'routes/registry.php' ].concat(
     2108                        routeNames.flatMap( function( name ) {
     2109                                return [
     2110                                        'routes/' + name + '/**/*.php',
     2111                                        'routes/' + name + '/**/*.js',
     2112                                ];
     2113                        } )
     2114                ) );
     2115        } );
     2116
    20612117        grunt.registerTask( 'build:gutenberg', [
    20622118                'copy:gutenberg-php',
     2119                'routes:setup',
     2120                'copy:routes',
    20632121                'copy:gutenberg-js',
    20642122                'gutenberg:copy',
Note: See TracChangeset for help on using the changeset viewer.