Make WordPress Core

Changeset 63917


Ignore:
Timestamp:
09/24/2026 04:16:32 PM (19 hours ago)
Author:
lancewillett
Message:

Build/Test Tools: Check file types in the build directory.

Check the final production build for misplaced CSS and JavaScript files and unexpected file types in their directories. Run the check alongside the existing build verification tasks.

Allow known bundled assets and mark the generated PHP exceptions as provisional while their placement remains under discussion.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13706

Props adrianmoldovanwp.
See #65279.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r63885 r63917  
    21642164                'verify:old-files',
    21652165                'verify:source-maps',
     2166                'verify:file-types',
    21662167        ] );
    21672168
    … …  
    22642265                                );
    22652266                        } );
     2267        } );
     2268
     2269        /**
     2270         * Ensure that CSS directories in the build contain only CSS files, JS
     2271         * directories contain only JS files, and CSS and JS files are not placed
     2272         * elsewhere in wp-admin or wp-includes.
     2273         *
     2274         * Tracked files are checked by the file-type-check.yml workflow. This
     2275         * task covers files copied in by the build, such as from npm packages
     2276         * and Gutenberg.
     2277         *
     2278         * @ticket 65279
     2279         */
     2280        grunt.registerTask( 'verify:file-types', function() {
     2281                // Paths are relative to the build directory.
     2282                const allowed = [
     2283                        /*
     2284                         * Provisional: generated PHP registries and manifests copied from Gutenberg.
     2285                         * Their placement is under discussion in #65278 and #65279.
     2286                         */
     2287                        /^wp-includes\/css\/dist\/registry\.php$/,
     2288                        /^wp-includes\/js\/dist\/.+\.asset\.php$/,
     2289                        /^wp-includes\/js\/dist\/script-modules\/registry\.php$/,
     2290
     2291                        /^wp-admin\/css\/colors\/.+\.scss$/,
     2292                        /^wp-includes\/js\/tinymce\/wp-tinymce\.php$/,
     2293                        /^wp-includes\/js\/tinymce\/license\.txt$/,
     2294                        /^wp-includes\/js\/tinymce\/skins\/.+\.(css|png|gif|svg|ttf|woff|eot)$/,
     2295                        /^wp-includes\/js\/tinymce\/plugins\/compat3x\/css\/.+\.css$/,
     2296                        /^wp-includes\/js\/(mediaelement|thickbox|imgareaselect|crop|jcrop)\/.+\.(css|png|gif|svg)$/,
     2297                        /^wp-includes\/js\/codemirror\/codemirror\.min\.css$/,
     2298                        /^wp-includes\/js\/(swfupload|plupload)\/license\.txt$/,
     2299                        // Block and route assets are built next to their PHP files.
     2300                        /^wp-includes\/(blocks|build)\//,
     2301                ];
     2302
     2303                const files = glob.sync( '{wp-admin,wp-includes}/**', {
     2304                        cwd: BUILD_DIR,
     2305                        dot: true,
     2306                        nodir: true,
     2307                } );
     2308
     2309                assert(
     2310                        files.length > 0,
     2311                        'No files found in the build directory.'
     2312                );
     2313
     2314                const misplaced = files.filter( function( file ) {
     2315                        const dir = file.match( /^wp-(?:admin|includes)\/(css|js)\// );
     2316                        const ext = file.match( /\.(css|js)$/ );
     2317
     2318                        const isMisplaced = dir ? ! ext || ext[1] !== dir[1] : !! ext;
     2319
     2320                        return isMisplaced && ! allowed.some( function( pattern ) {
     2321                                return pattern.test( file );
     2322                        } );
     2323                } );
     2324
     2325                assert(
     2326                        misplaced.length === 0,
     2327                        'Misplaced files found in the build directory:\n\n' +
     2328                        misplaced.join( '\n' ) +
     2329                        '\n\nCSS directories should contain only .css files and JS directories only .js files.' +
     2330                        '\n.css and .js files belong in those directories, not elsewhere in wp-admin/ or wp-includes/.' +
     2331                        '\nIf a file is a legitimate exception, update the verify:file-types task in Gruntfile.js.'
     2332                );
    22662333        } );
    22672334
Note: See TracChangeset for help on using the changeset viewer.