Skip to content

Commit 49d8c11

Browse files
committed
Build/Test Tools: Remove the requirement to clone/build Gutenberg.
This iterates on the changes from [61438] by removing the need to: - Check out the WordPress/gutenberg repository at the pinned hash. - Run `npm install` within that checkout. - Run `npm build` within that checkout. Instead, the build script will now download a prebuilt zip file published to the GitHub Container Registry by a GitHub Actions workflow recently merged to the Gutenberg Repository (related PR: WordPress/gutenberg#75844). This also removes redundant code responsible for: - Copying files from the `gutenberg` directory to the appropriate locations during the build script in favor of using `grunt copy`. - Modifying built files to replace specific text, such as `sourceMappingURL`, in favor of `grunt replace`. The remaining files within the `tools/gutenberg` directory have been renamed to remove `gutenberg` from the file names. Since these are already nested in a `gutenberg` directory, that was redundant. Since the intention of the pinned value for the repository in the `package.json` file is to specify a full-length commit hash, `ref` has been renamed to `sha`. In Git `ref` encompasses branches, tags, and commit hashes, so this hopefully makes it more clear that something like `branch-name` should not be used. Follow up to [61438], [61439], [61458], [61492], [61677], [61867]. Props desrosj, dmsnell, westonruter, mcsf, jorbin. See #64393. git-svn-id: https://develop.svn.wordpress.org/trunk@61873 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b80140a commit 49d8c11

File tree

10 files changed

+522
-1092
lines changed

10 files changed

+522
-1092
lines changed

Gruntfile.js

Lines changed: 126 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ module.exports = function(grunt) {
5353
webpackFiles = [
5454
'wp-includes/assets/*',
5555
'wp-includes/css/dist',
56-
'wp-includes/blocks/**/*.css',
5756
'!wp-includes/assets/script-loader-packages.min.php',
5857
'!wp-includes/assets/script-modules-packages.min.php',
5958
],
@@ -588,7 +587,97 @@ module.exports = function(grunt) {
588587
certificates: {
589588
src: 'vendor/composer/ca-bundle/res/cacert.pem',
590589
dest: SOURCE_DIR + 'wp-includes/certificates/ca-bundle.crt'
591-
}
590+
},
591+
// Gutenberg PHP infrastructure files (routes.php, pages.php, constants.php, pages/, routes/).
592+
'gutenberg-php': {
593+
options: {
594+
process: function( content ) {
595+
// Fix boot module asset file path for Core's different directory structure.
596+
return content.replace(
597+
/__DIR__\s*\.\s*(['"])\/..\/\..\/modules\/boot\/index\.min\.asset\.php\1/g,
598+
'ABSPATH . WPINC . \'/js/dist/script-modules/boot/index.min.asset.php\''
599+
);
600+
}
601+
},
602+
files: [ {
603+
expand: true,
604+
cwd: 'gutenberg/build',
605+
src: [
606+
'routes.php',
607+
'pages.php',
608+
'constants.php',
609+
'pages/**/*.php',
610+
'routes/**/*.php',
611+
],
612+
dest: WORKING_DIR + 'wp-includes/build/',
613+
} ],
614+
},
615+
'gutenberg-modules': {
616+
files: [ {
617+
expand: true,
618+
cwd: 'gutenberg/build/modules',
619+
src: [ '**/*', '!**/*.map' ],
620+
dest: WORKING_DIR + 'wp-includes/js/dist/script-modules/',
621+
} ],
622+
},
623+
'gutenberg-styles': {
624+
files: [ {
625+
expand: true,
626+
cwd: 'gutenberg/build/styles',
627+
src: [ '**/*', '!**/*.map' ],
628+
dest: WORKING_DIR + 'wp-includes/css/dist/',
629+
} ],
630+
},
631+
'gutenberg-theme-json': {
632+
options: {
633+
process: function( content, srcpath ) {
634+
// Replace the local schema URL with the canonical public URL for Core.
635+
if ( path.basename( srcpath ) === 'theme.json' ) {
636+
return content.replace(
637+
'"$schema": "../schemas/json/theme.json"',
638+
'"$schema": "https://schemas.wp.org/trunk/theme.json"'
639+
);
640+
}
641+
return content;
642+
}
643+
},
644+
files: [
645+
{
646+
src: 'gutenberg/lib/theme.json',
647+
dest: WORKING_DIR + 'wp-includes/theme.json',
648+
},
649+
{
650+
src: 'gutenberg/lib/theme-i18n.json',
651+
dest: WORKING_DIR + 'wp-includes/theme-i18n.json',
652+
},
653+
],
654+
},
655+
'gutenberg-icons': {
656+
options: {
657+
process: function( content, srcpath ) {
658+
// Remove the 'gutenberg' text domain from _x() calls in manifest.php.
659+
if ( path.basename( srcpath ) === 'manifest.php' ) {
660+
return content.replace(
661+
/_x\(\s*([^,]+),\s*([^,]+),\s*['"]gutenberg['"]\s*\)/g,
662+
'_x( $1, $2 )'
663+
);
664+
}
665+
return content;
666+
}
667+
},
668+
files: [
669+
{
670+
src: 'gutenberg/packages/icons/src/manifest.php',
671+
dest: WORKING_DIR + 'wp-includes/icons/manifest.php',
672+
},
673+
{
674+
expand: true,
675+
cwd: 'gutenberg/packages/icons/src/library',
676+
src: '*.svg',
677+
dest: WORKING_DIR + 'wp-includes/icons/library/',
678+
},
679+
],
680+
},
592681
},
593682
sass: {
594683
colors: {
@@ -1323,20 +1412,21 @@ module.exports = function(grunt) {
13231412
},
13241413
{
13251414
expand: true,
1326-
flatten: true,
1327-
src: [
1328-
BUILD_DIR + 'wp-includes/js/dist/block-editor.js',
1329-
BUILD_DIR + 'wp-includes/js/dist/commands.js',
1330-
],
1331-
dest: BUILD_DIR + 'wp-includes/js/dist/'
1415+
cwd: BUILD_DIR + 'wp-includes/js/dist/',
1416+
src: [ '*.js' ],
1417+
dest: BUILD_DIR + 'wp-includes/js/dist/',
13321418
},
13331419
{
13341420
expand: true,
1335-
flatten: true,
1336-
src: [
1337-
BUILD_DIR + 'wp-includes/js/dist/vendor/**/*.js'
1338-
],
1339-
dest: BUILD_DIR + 'wp-includes/js/dist/vendor/'
1421+
cwd: BUILD_DIR + 'wp-includes/js/dist/vendor/',
1422+
src: [ '**/*.js' ],
1423+
dest: BUILD_DIR + 'wp-includes/js/dist/vendor/',
1424+
},
1425+
{
1426+
expand: true,
1427+
cwd: BUILD_DIR + 'wp-includes/js/dist/script-modules/',
1428+
src: [ '**/*.js' ],
1429+
dest: BUILD_DIR + 'wp-includes/js/dist/script-modules/',
13401430
}
13411431
]
13421432
}
@@ -1475,45 +1565,38 @@ module.exports = function(grunt) {
14751565
} );
14761566

14771567
// Gutenberg integration tasks.
1478-
grunt.registerTask( 'gutenberg-checkout', 'Checks out the Gutenberg repository.', function() {
1568+
grunt.registerTask( 'gutenberg:verify', 'Verifies the installed Gutenberg version matches the expected SHA.', function() {
14791569
const done = this.async();
14801570
grunt.util.spawn( {
14811571
cmd: 'node',
1482-
args: [ 'tools/gutenberg/checkout-gutenberg.js' ],
1572+
args: [ 'tools/gutenberg/utils.js' ],
14831573
opts: { stdio: 'inherit' }
14841574
}, function( error ) {
14851575
done( ! error );
14861576
} );
14871577
} );
14881578

1489-
grunt.registerTask( 'gutenberg-build', 'Builds the Gutenberg repository.', function() {
1579+
grunt.registerTask( 'gutenberg:download', 'Downloads the built Gutenberg artifact.', function() {
14901580
const done = this.async();
1581+
const args = [ 'tools/gutenberg/download.js' ];
1582+
if ( grunt.option( 'force' ) ) {
1583+
args.push( '--force' );
1584+
}
14911585
grunt.util.spawn( {
14921586
cmd: 'node',
1493-
args: [ 'tools/gutenberg/build-gutenberg.js' ],
1587+
args,
14941588
opts: { stdio: 'inherit' }
14951589
}, function( error ) {
14961590
done( ! error );
14971591
} );
14981592
} );
14991593

1500-
grunt.registerTask( 'gutenberg-copy', 'Copies Gutenberg build output to WordPress Core.', function() {
1594+
grunt.registerTask( 'gutenberg:copy', 'Copies Gutenberg JS packages and block assets to WordPress Core.', function() {
15011595
const done = this.async();
15021596
const buildDir = grunt.option( 'dev' ) ? 'src' : 'build';
15031597
grunt.util.spawn( {
15041598
cmd: 'node',
1505-
args: [ 'tools/gutenberg/copy-gutenberg-build.js', `--build-dir=${ buildDir }` ],
1506-
opts: { stdio: 'inherit' }
1507-
}, function( error ) {
1508-
done( ! error );
1509-
} );
1510-
} );
1511-
1512-
grunt.registerTask( 'gutenberg-sync', 'Syncs Gutenberg checkout and build if ref has changed.', function() {
1513-
const done = this.async();
1514-
grunt.util.spawn( {
1515-
cmd: 'node',
1516-
args: [ 'tools/gutenberg/sync-gutenberg.js' ],
1599+
args: [ 'tools/gutenberg/copy.js', `--build-dir=${ buildDir }` ],
15171600
opts: { stdio: 'inherit' }
15181601
}, function( error ) {
15191602
done( ! error );
@@ -1956,26 +2039,35 @@ module.exports = function(grunt) {
19562039
} );
19572040
} );
19582041

2042+
grunt.registerTask( 'build:gutenberg', [
2043+
'copy:gutenberg-php',
2044+
'gutenberg:copy',
2045+
'copy:gutenberg-modules',
2046+
'copy:gutenberg-styles',
2047+
'copy:gutenberg-theme-json',
2048+
'copy:gutenberg-icons',
2049+
] );
2050+
19592051
grunt.registerTask( 'build', function() {
19602052
if ( grunt.option( 'dev' ) ) {
19612053
grunt.task.run( [
2054+
'gutenberg:verify',
19622055
'build:js',
19632056
'build:css',
19642057
'build:codemirror',
1965-
'gutenberg-sync',
1966-
'gutenberg-copy',
2058+
'build:gutenberg',
19672059
'copy-vendor-scripts',
19682060
'build:certificates'
19692061
] );
19702062
} else {
19712063
grunt.task.run( [
2064+
'gutenberg:verify',
19722065
'build:certificates',
19732066
'build:files',
19742067
'build:js',
19752068
'build:css',
19762069
'build:codemirror',
1977-
'gutenberg-sync',
1978-
'gutenberg-copy',
2070+
'build:gutenberg',
19792071
'copy-vendor-scripts',
19802072
'replace:source-maps',
19812073
'verify:build'

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"url": "https://develop.svn.wordpress.org/trunk"
88
},
99
"gutenberg": {
10-
"ref": "9b8144036fa5faf75de43d4502ff9809fcf689ad"
10+
"sha": "9b8144036fa5faf75de43d4502ff9809fcf689ad",
11+
"ghcrRepo": "WordPress/gutenberg/gutenberg-wp-develop-build"
1112
},
1213
"engines": {
1314
"node": ">=20.10.0",
@@ -111,9 +112,10 @@
111112
"wicg-inert": "3.1.3"
112113
},
113114
"scripts": {
114-
"postinstall": "npm run gutenberg:sync && npm run gutenberg:copy -- --dev",
115+
"postinstall": "npm run gutenberg:download",
115116
"build": "grunt build",
116117
"build:dev": "grunt build --dev",
118+
"build:gutenberg": "grunt build:gutenberg",
117119
"dev": "grunt watch --dev",
118120
"test": "grunt test",
119121
"watch": "grunt watch",
@@ -137,10 +139,8 @@
137139
"test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js",
138140
"test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js",
139141
"typecheck:php": "node ./tools/local-env/scripts/docker.js run --rm php composer phpstan",
140-
"gutenberg:checkout": "node tools/gutenberg/checkout-gutenberg.js",
141-
"gutenberg:build": "node tools/gutenberg/build-gutenberg.js",
142-
"gutenberg:copy": "node tools/gutenberg/copy-gutenberg-build.js",
143-
"gutenberg:sync": "node tools/gutenberg/sync-gutenberg.js",
142+
"gutenberg:copy": "node tools/gutenberg/copy.js",
143+
"gutenberg:download": "node tools/gutenberg/download.js",
144144
"vendor:copy": "node tools/vendors/copy-vendors.js",
145145
"sync-gutenberg-packages": "grunt sync-gutenberg-packages",
146146
"postsync-gutenberg-packages": "grunt wp-packages:sync-stable-blocks && grunt build --dev && grunt build"

tests/phpstan/base.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ parameters:
105105
- ../../src/wp-includes/deprecated.php
106106
- ../../src/wp-includes/ms-deprecated.php
107107
- ../../src/wp-includes/pluggable-deprecated.php
108-
# These files are sourced by wordpress/gutenberg in `tools/release/sync-stable-blocks.js`.
108+
# These files are autogenerated by tools/gutenberg/copy.js.
109109
- ../../src/wp-includes/blocks
110110
# Third-party libraries.
111111
- ../../src/wp-admin/includes/class-ftp-pure.php

0 commit comments

Comments
 (0)