-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Only include files for active, stable routes #11318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7425919
f28d443
fadfff8
a18c96b
21ac148
b5d56d7
1330f6e
d903b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -603,7 +603,7 @@ module.exports = function(grunt) { | |
| src: 'vendor/composer/ca-bundle/res/cacert.pem', | ||
| dest: SOURCE_DIR + 'wp-includes/certificates/ca-bundle.crt' | ||
| }, | ||
| // Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/, routes/). | ||
| // Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/). | ||
| 'gutenberg-php': { | ||
| options: { | ||
| process: function( content ) { | ||
|
|
@@ -622,18 +622,32 @@ module.exports = function(grunt) { | |
| 'pages.php', | ||
| 'constants.php', | ||
| 'pages/**/*.php', | ||
| 'routes/**/*.php', | ||
| ], | ||
| dest: WORKING_DIR + 'wp-includes/build/', | ||
| } ], | ||
| }, | ||
| /* | ||
| * Only copy files relevant to the routes specified in the registry file. | ||
| * | ||
| * While the registry file does not contain any experimental routes, the `gutenberg/build/routes` directory | ||
| * includes the files for all registered routes. Only the files related to the routes specified in the | ||
| * registry should be included in the WordPress build. | ||
| * | ||
| * The `src` list is populated at task runtime by `routes:setup`, which reads the registry after | ||
| * `gutenberg:download` has run. See the `routes:setup` task registration for implementation details. | ||
| */ | ||
| routes: { | ||
| expand: true, | ||
| cwd: 'gutenberg/build', | ||
| src: [], | ||
| dest: WORKING_DIR + 'wp-includes/build/', | ||
| }, | ||
| 'gutenberg-js': { | ||
| files: [ { | ||
| expand: true, | ||
| cwd: 'gutenberg/build', | ||
| src: [ | ||
| 'pages/**/*.js', | ||
| 'routes/**/*.js', | ||
| ], | ||
| dest: WORKING_DIR + 'wp-includes/build/', | ||
| } ], | ||
|
|
@@ -2058,8 +2072,52 @@ module.exports = function(grunt) { | |
| } ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'routes:setup', 'Reads the routes registry and configures the copy:routes task.', function() { | ||
| const registryPath = 'gutenberg/build/routes/registry.php'; | ||
| let registryContent; | ||
| try { | ||
| registryContent = fs.readFileSync( registryPath, 'utf8' ); | ||
| } catch ( e ) { | ||
| grunt.fatal( | ||
| 'Route registry not found at ' + registryPath + '. Run `grunt gutenberg:download` first.' | ||
| ); | ||
| } | ||
| const namePattern = /'name'\s*=>\s*'([^']+)'/g; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this rely on PHP being available? It would be nice to do do something like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good question. I don't know that we can. But I agree that would be preferable. I should have noted this in the PR and the commit message, but my intention is for this to be a temporary fix. The real problem is that the |
||
| const routeNames = []; | ||
| let match; | ||
| while ( ( match = namePattern.exec( registryContent ) ) !== null ) { | ||
| routeNames.push( match[ 1 ] ); | ||
| } | ||
|
desrosj marked this conversation as resolved.
|
||
|
|
||
| if ( routeNames.length === 0 ) { | ||
| grunt.fatal( | ||
| 'No route names found in ' + registryPath + '. The format of the file may have changed.' | ||
| ); | ||
| } | ||
|
|
||
| const validName = /^[A-Za-z0-9_-]+$/; | ||
| routeNames.forEach( function( name ) { | ||
| if ( ! validName.test( name ) ) { | ||
| grunt.fatal( | ||
| 'Invalid route name \'' + name + '\' in ' + registryPath + '. Expected only letters, digits, hyphens, and underscores.' | ||
| ); | ||
| } | ||
| } ); | ||
|
|
||
| grunt.config( [ 'copy', 'routes', 'src' ], [ 'routes/registry.php' ].concat( | ||
| routeNames.flatMap( function( name ) { | ||
| return [ | ||
| 'routes/' + name + '/**/*.php', | ||
| 'routes/' + name + '/**/*.js', | ||
| ]; | ||
|
desrosj marked this conversation as resolved.
|
||
| } ) | ||
| ) ); | ||
| } ); | ||
|
|
||
| grunt.registerTask( 'build:gutenberg', [ | ||
| 'copy:gutenberg-php', | ||
| 'routes:setup', | ||
| 'copy:routes', | ||
| 'copy:gutenberg-js', | ||
| 'gutenberg:copy', | ||
| 'copy:gutenberg-modules', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.