diff --git a/Gruntfile.js b/Gruntfile.js index ad7fcb517acfe..11f2db7a78ace 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1607,7 +1607,25 @@ module.exports = function(grunt) { args: [ 'tools/gutenberg/download.js' ], opts: { stdio: 'inherit' } }, function( error ) { - done( ! error ); + if ( error ) { + done( false ); + return; + } + /* + * Build block editor files into the src directory every time assets + * are downloaded. This prevents failures when running from src + * without running `build:dev` after those files were removed from + * version control in https://core.trac.wordpress.org/changeset/61438. + * + * See https://core.trac.wordpress.org/ticket/64393. + */ + grunt.util.spawn( { + grunt: true, + args: [ 'build:gutenberg', '--dev' ], + opts: { stdio: 'inherit' } + }, function( buildError ) { + done( ! buildError ); + } ); } ); } ); diff --git a/package.json b/package.json index 9f67a45262806..3084630a2d726 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "typecheck:php": "node ./tools/local-env/scripts/docker.js run --rm php composer phpstan", "gutenberg:copy": "node tools/gutenberg/copy.js", "gutenberg:verify": "node tools/gutenberg/utils.js", - "gutenberg:download": "node tools/gutenberg/download.js", + "gutenberg:download": "node tools/gutenberg/download.js && grunt build:gutenberg --dev", "vendor:copy": "node tools/vendors/copy-vendors.js", "sync-gutenberg-packages": "grunt sync-gutenberg-packages", "postsync-gutenberg-packages": "grunt wp-packages:sync-stable-blocks && grunt build --dev && grunt build" diff --git a/tools/gutenberg/utils.js b/tools/gutenberg/utils.js index 2b30befd38735..dc696d5e7bfd7 100644 --- a/tools/gutenberg/utils.js +++ b/tools/gutenberg/utils.js @@ -42,13 +42,19 @@ function readGutenbergConfig() { } /** - * Trigger a fresh download of the Gutenberg artifact by spawning download.js. - * Exits the process if the download fails. + * Trigger a fresh download of the Gutenberg artifact by spawning download.js, + * then run `grunt build:gutenberg --dev` to copy the build to src/. + * Exits the process if either step fails. */ function downloadGutenberg() { - const result = spawnSync( 'node', [ path.join( __dirname, 'download.js' ) ], { stdio: 'inherit' } ); - if ( result.status !== 0 ) { - process.exit( result.status ?? 1 ); + const downloadResult = spawnSync( 'node', [ path.join( __dirname, 'download.js' ) ], { stdio: 'inherit' } ); + if ( downloadResult.status !== 0 ) { + process.exit( downloadResult.status ?? 1 ); + } + + const buildResult = spawnSync( 'grunt', [ 'build:gutenberg', '--dev' ], { stdio: 'inherit', shell: true } ); + if ( buildResult.status !== 0 ) { + process.exit( buildResult.status ?? 1 ); } }