Skip to content

Commit b2d243f

Browse files
committed
Build Tools:
- Update the DependencyExtractionWebpackPlugin to 2.3.0 and set it to output a single assets file. - Grunt: copy the assets file to both `SOURCE_DIR` and `BUILD_DIR` as `wp-includes/assets/script-loader-packages.php`. - "Unignore" the `wp-includes/assets` directory. Its content will be committed similarly to `wp-includes/blocks`. - Update `wp_default_packages_scripts()` to use the above file. This also removes the hard-coded lists of packages and packages with translations. Props gziolo, pbearne, johnbillion, isabel_brison, ocean90, azaozz. Fixes #48154. git-svn-id: https://develop.svn.wordpress.org/trunk@47352 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4e18f78 commit b2d243f

7 files changed

Lines changed: 34 additions & 85 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ wp-tests-config.php
2424
/src/wp-admin/css/*-rtl.css
2525
/src/wp-admin/css/colors/*/*.css
2626
/src/wp-admin/js
27-
/src/wp-includes/assets
2827
/src/wp-includes/js
2928
/src/wp-includes/css/dist
3029
/src/wp-includes/css/*.min.css

Gruntfile.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module.exports = function(grunt) {
117117
WORKING_DIR + 'wp-includes/js/'
118118
],
119119
'webpack-assets': [
120-
WORKING_DIR + 'wp-includes/js/**/*.asset.php'
120+
WORKING_DIR + 'wp-includes/js/dist/assets.php'
121121
],
122122
dynamic: {
123123
dot: true,
@@ -356,10 +356,16 @@ module.exports = function(grunt) {
356356
]
357357
},
358358
'webpack-assets': {
359-
expand: true,
360-
cwd: WORKING_DIR + 'wp-includes/js/',
361-
src: 'dist/*.asset.php',
362-
dest: WORKING_DIR + 'wp-includes/assets/'
359+
files: [
360+
{
361+
src: WORKING_DIR + 'wp-includes/js/dist/assets.php',
362+
dest: SOURCE_DIR + 'wp-includes/assets/script-loader-packages.php'
363+
},
364+
{
365+
src: WORKING_DIR + 'wp-includes/js/dist/assets.php',
366+
dest: BUILD_DIR + 'wp-includes/assets/script-loader-packages.php'
367+
}
368+
]
363369
},
364370
version: {
365371
options: {

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"devDependencies": {
2828
"@wordpress/custom-templated-path-webpack-plugin": "1.6.0",
29-
"@wordpress/dependency-extraction-webpack-plugin": "2.2.0",
29+
"@wordpress/dependency-extraction-webpack-plugin": "2.3.0",
3030
"@wordpress/e2e-test-utils": "4.3.0",
3131
"@wordpress/library-export-default-webpack-plugin": "1.6.0",
3232
"@wordpress/scripts": "6.2.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('a11y.js' => array('dependencies' => array('wp-dom-ready', 'wp-polyfill'), 'version' => 'ae574a3e6c97a8f964dcbb3ebc12afdb'), 'annotations.js' => array('dependencies' => array('lodash', 'wp-data', 'wp-hooks', 'wp-i18n', 'wp-polyfill', 'wp-rich-text'), 'version' => 'da0fd5e89656a085dce028b7801d5448'), 'api-fetch.js' => array('dependencies' => array('wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '3f9c4530789ad55104bd4e6fb1d7b2c0'), 'autop.js' => array('dependencies' => array('wp-polyfill'), 'version' => '205ce2875ce340d29d444c2b6204f1c0'), 'blob.js' => array('dependencies' => array('wp-polyfill'), 'version' => 'aba7ab22bcfc07e4378e40e92e7ab85d'), 'block-directory.js' => array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives'), 'version' => '32349b6b799bb23ecdff857c3a1c85d8'), 'block-editor.js' => array('dependencies' => array('lodash', 'react', 'wp-a11y', 'wp-blob', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-token-list', 'wp-url', 'wp-viewport', 'wp-wordcount'), 'version' => 'b5ff1c6c60ac9bf9e43e71d7a0f992e4'), 'block-library.js' => array('dependencies' => array('lodash', 'moment', 'wp-api-fetch', 'wp-autop', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-deprecated', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-server-side-render', 'wp-url', 'wp-viewport'), 'version' => 'a5882b7f029c0a75c9df5b562c076b86'), 'block-serialization-default-parser.js' => array('dependencies' => array('wp-polyfill'), 'version' => '493193bef61f5a7f8f8f89ca631a01de'), 'blocks.js' => array('dependencies' => array('lodash', 'wp-autop', 'wp-blob', 'wp-block-serialization-default-parser', 'wp-compose', 'wp-data', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-shortcode'), 'version' => 'ee754416797881e577236b3cc2495651'), 'components.js' => array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-a11y', 'wp-compose', 'wp-deprecated', 'wp-dom', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-warning'), 'version' => 'fd429ba1f75a7eee7aef48ce1895249c'), 'compose.js' => array('dependencies' => array('lodash', 'wp-element', 'wp-is-shallow-equal', 'wp-polyfill'), 'version' => '73886b98cede5ee6ca063ddc889ac566'), 'core-data.js' => array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-blocks', 'wp-data', 'wp-deprecated', 'wp-element', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-url'), 'version' => 'a5dfc158a4629acf3eaa4c086bda8992'), 'data.js' => array('dependencies' => array('lodash', 'react', 'wp-compose', 'wp-deprecated', 'wp-element', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-priority-queue', 'wp-redux-routine'), 'version' => '3442a3ba7f75e8c54d93263da11d0e77'), 'data-controls.js' => array('dependencies' => array('wp-api-fetch', 'wp-data', 'wp-polyfill'), 'version' => '9dd473f24e19d3b632d799376da103ed'), 'date.js' => array('dependencies' => array('moment', 'wp-polyfill'), 'version' => '030fdca2819467d4296a129a89763133'), 'deprecated.js' => array('dependencies' => array('wp-hooks', 'wp-polyfill'), 'version' => 'e016dcf6dc5ed48938f8622acbc152f3'), 'dom.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => 'ee6b351074b0921dcfe09c2fb1ffb06f'), 'dom-ready.js' => array('dependencies' => array('wp-polyfill'), 'version' => '5045831f601200e96ad481e311acfe42'), 'edit-post.js' => array('dependencies' => array('lodash', 'wp-a11y', 'wp-api-fetch', 'wp-block-editor', 'wp-block-library', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-media-utils', 'wp-notices', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-viewport'), 'version' => 'cc2c3b1f5dc2e8bfbb2bfb21c50a603f'), 'editor.js' => array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-autop', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-data-controls', 'wp-date', 'wp-deprecated', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-keyboard-shortcuts', 'wp-keycodes', 'wp-media-utils', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-server-side-render', 'wp-url', 'wp-viewport', 'wp-wordcount'), 'version' => '63131715a52708dc239d4eafce97aba0'), 'element.js' => array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-escape-html', 'wp-polyfill'), 'version' => '41f8060e94eb56bb3c5d230d8b7dc349'), 'escape-html.js' => array('dependencies' => array('wp-polyfill'), 'version' => '3e3956f7e4a89e843080316c1ea3ff9f'), 'format-library.js' => array('dependencies' => array('lodash', 'wp-block-editor', 'wp-components', 'wp-data', 'wp-dom', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-keycodes', 'wp-polyfill', 'wp-primitives', 'wp-rich-text', 'wp-url'), 'version' => 'c9654deb47ed294f14ff96151af02331'), 'hooks.js' => array('dependencies' => array('wp-polyfill'), 'version' => '0181cce8c3861eae44439abdc3c37e7a'), 'html-entities.js' => array('dependencies' => array('wp-polyfill'), 'version' => 'c43b49e3f3da377cefdadb0131ba7a31'), 'i18n.js' => array('dependencies' => array('wp-polyfill'), 'version' => 'a2eb6e6af4832e39a703494f847a2370'), 'is-shallow-equal.js' => array('dependencies' => array('wp-polyfill'), 'version' => '3bb3f6a7a8127b024342e718ad297e81'), 'keyboard-shortcuts.js' => array('dependencies' => array('lodash', 'wp-compose', 'wp-data', 'wp-keycodes', 'wp-polyfill'), 'version' => '23a620781734eaba58ba6c330785209c'), 'keycodes.js' => array('dependencies' => array('lodash', 'wp-i18n', 'wp-polyfill'), 'version' => '2e2855269d5ab0ab5f2b9f8811e007a4'), 'list-reusable-blocks.js' => array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '327a5cae1d26e1724881d6f7a9ec32b1'), 'media-utils.js' => array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-blob', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '30343cf12ac797ef15c05beb2befdf21'), 'notices.js' => array('dependencies' => array('lodash', 'wp-data', 'wp-polyfill'), 'version' => '3b3e946b2d484de31e4be1dc7a48001e'), 'nux.js' => array('dependencies' => array('lodash', 'wp-components', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives'), 'version' => 'cf36cb89f359dbf8a1b1f2bddbd35606'), 'plugins.js' => array('dependencies' => array('lodash', 'wp-compose', 'wp-element', 'wp-hooks', 'wp-polyfill'), 'version' => '474a4e9edc27fd2d9679d00ef548c966'), 'primitives.js' => array('dependencies' => array('wp-element', 'wp-polyfill'), 'version' => '6e6869dc94974fb23e5747bc1cf59e23'), 'priority-queue.js' => array('dependencies' => array('wp-polyfill'), 'version' => 'a36cabae37a1aac99726445836474a79'), 'redux-routine.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => '455bbe5442bfb84840ff801a9ea5be69'), 'rich-text.js' => array('dependencies' => array('lodash', 'wp-compose', 'wp-data', 'wp-deprecated', 'wp-element', 'wp-escape-html', 'wp-is-shallow-equal', 'wp-keycodes', 'wp-polyfill'), 'version' => 'ef45226203dde56110939da3aaaa0905'), 'server-side-render.js' => array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-deprecated', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '110181c4ac96264be701b8a27777b9a2'), 'shortcode.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => '3173f285aee099b367ac20385a778615'), 'token-list.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => '4b20a43e08878013a4cc5812236d6046'), 'url.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => '14dce49ab7da6088abc01bec4529f9d0'), 'viewport.js' => array('dependencies' => array('lodash', 'wp-compose', 'wp-data', 'wp-element', 'wp-polyfill'), 'version' => '8cd5499a15fd58371759a3182b50ac33'), 'warning.js' => array('dependencies' => array('wp-polyfill'), 'version' => 'f634219101ddcef8327fb62f2bcb6a93'), 'wordcount.js' => array('dependencies' => array('lodash', 'wp-polyfill'), 'version' => '5f3b21f75e28874cac2c76a7d05c5e42'));

src/wp-includes/script-loader.php

Lines changed: 17 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -231,81 +231,23 @@ function wp_get_script_polyfill( &$scripts, $tests ) {
231231
function wp_default_packages_scripts( &$scripts ) {
232232
$suffix = wp_scripts_get_suffix();
233233

234-
$packages = array(
235-
'a11y',
236-
'annotations',
237-
'api-fetch',
238-
'autop',
239-
'blob',
240-
'block-directory',
241-
'block-editor',
242-
'block-library',
243-
'block-serialization-default-parser',
244-
'blocks',
245-
'components',
246-
'compose',
247-
'core-data',
248-
'data',
249-
'data-controls',
250-
'date',
251-
'deprecated',
252-
'dom',
253-
'dom-ready',
254-
'edit-post',
255-
'editor',
256-
'element',
257-
'escape-html',
258-
'format-library',
259-
'hooks',
260-
'html-entities',
261-
'i18n',
262-
'is-shallow-equal',
263-
'keyboard-shortcuts',
264-
'keycodes',
265-
'list-reusable-blocks',
266-
'media-utils',
267-
'notices',
268-
'nux',
269-
'plugins',
270-
'primitives',
271-
'priority-queue',
272-
'redux-routine',
273-
'rich-text',
274-
'shortcode',
275-
'server-side-render',
276-
'token-list',
277-
'url',
278-
'viewport',
279-
'warning',
280-
'wordcount',
281-
);
282-
283-
$package_translations = array(
284-
'api-fetch',
285-
'blocks',
286-
'block-directory',
287-
'block-editor',
288-
'block-library',
289-
'components',
290-
'edit-post',
291-
'editor',
292-
'format-library',
293-
'keycodes',
294-
'list-reusable-blocks',
295-
'nux',
296-
);
297-
298-
foreach ( $packages as $package ) {
299-
$handle = 'wp-' . $package;
300-
$path = "/wp-includes/js/dist/$package$suffix.js";
301-
302-
if ( ! file_exists( ABSPATH . $path ) ) {
303-
continue;
234+
// Expects multidimensional array like:
235+
// 'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
236+
// 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
237+
// 'api-fetch.js' => array(...
238+
$assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
239+
240+
foreach ( $assets as $package_name => $package_data ) {
241+
$basename = basename( $package_name, '.js' );
242+
$handle = 'wp-' . $basename;
243+
$path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
244+
245+
if ( ! empty( $package_data['dependencies'] ) ) {
246+
$dependencies = $package_data['dependencies'];
247+
} else {
248+
$dependencies = array();
304249
}
305250

306-
$asset_file = require ABSPATH . WPINC . "/assets/dist/$package$suffix.asset.php";
307-
$dependencies = $asset_file['dependencies'];
308-
309251
// Add dependencies that cannot be detected and generated by build tools.
310252
switch ( $handle ) {
311253
case 'wp-block-library':
@@ -316,9 +258,9 @@ function wp_default_packages_scripts( &$scripts ) {
316258
break;
317259
}
318260

319-
$scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 );
261+
$scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
320262

321-
if ( in_array( $package, $package_translations, true ) ) {
263+
if ( in_array( 'wp-i18n', $dependencies, true ) ) {
322264
$scripts->set_translations( $handle );
323265
}
324266
}

tools/webpack/packages.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil
246246
} ),
247247
new DependencyExtractionPlugin( {
248248
injectPolyfill: true,
249+
combineAssets: true,
249250
} ),
250251
new CopyWebpackPlugin(
251252
[

0 commit comments

Comments
 (0)