From b2d243fbe614e28b43dd5676eeebb1feaaecf529 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 24 Feb 2020 21:20:49 +0000 Subject: [PATCH] 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 --- .gitignore | 1 - Gruntfile.js | 16 ++-- package-lock.json | 6 +- package.json | 2 +- .../assets/script-loader-packages.php | 1 + src/wp-includes/script-loader.php | 88 ++++--------------- tools/webpack/packages.js | 1 + 7 files changed, 32 insertions(+), 83 deletions(-) create mode 100644 src/wp-includes/assets/script-loader-packages.php diff --git a/.gitignore b/.gitignore index 266d21bef9..2f4d4eb9d2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,6 @@ wp-tests-config.php /src/wp-admin/css/*-rtl.css /src/wp-admin/css/colors/*/*.css /src/wp-admin/js -/src/wp-includes/assets /src/wp-includes/js /src/wp-includes/css/dist /src/wp-includes/css/*.min.css diff --git a/Gruntfile.js b/Gruntfile.js index 11187fdff6..0bf62a6446 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -117,7 +117,7 @@ module.exports = function(grunt) { WORKING_DIR + 'wp-includes/js/' ], 'webpack-assets': [ - WORKING_DIR + 'wp-includes/js/**/*.asset.php' + WORKING_DIR + 'wp-includes/js/dist/assets.php' ], dynamic: { dot: true, @@ -356,10 +356,16 @@ module.exports = function(grunt) { ] }, 'webpack-assets': { - expand: true, - cwd: WORKING_DIR + 'wp-includes/js/', - src: 'dist/*.asset.php', - dest: WORKING_DIR + 'wp-includes/assets/' + files: [ + { + src: WORKING_DIR + 'wp-includes/js/dist/assets.php', + dest: SOURCE_DIR + 'wp-includes/assets/script-loader-packages.php' + }, + { + src: WORKING_DIR + 'wp-includes/js/dist/assets.php', + dest: BUILD_DIR + 'wp-includes/assets/script-loader-packages.php' + } + ] }, version: { options: { diff --git a/package-lock.json b/package-lock.json index 348de8197c..ddc0298fd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2525,9 +2525,9 @@ } }, "@wordpress/dependency-extraction-webpack-plugin": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@wordpress/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz", - "integrity": "sha512-74zJPfSohTfcNtNG/Y0VmE/ow1sG6wCEl7A7xN3VdhMRFUOfpfGV2XifBA9UjDoxY/IAbf80WDqiuA7MzcDMKw==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@wordpress/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.3.0.tgz", + "integrity": "sha512-FwEN0PuFr3Q5IdDLgerkIspiHkePNbzem71R3RlUevaSmnw+iH9/0Jzg4uIQ8KCMBpbrn1gAmhgdaTgTDn3EfQ==", "dev": true, "requires": { "json2php": "^0.0.4", diff --git a/package.json b/package.json index 442bc6231c..8ea1c57aaa 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "devDependencies": { "@wordpress/custom-templated-path-webpack-plugin": "1.6.0", - "@wordpress/dependency-extraction-webpack-plugin": "2.2.0", + "@wordpress/dependency-extraction-webpack-plugin": "2.3.0", "@wordpress/e2e-test-utils": "4.3.0", "@wordpress/library-export-default-webpack-plugin": "1.6.0", "@wordpress/scripts": "6.2.0", diff --git a/src/wp-includes/assets/script-loader-packages.php b/src/wp-includes/assets/script-loader-packages.php new file mode 100644 index 0000000000..7b10ea5e16 --- /dev/null +++ b/src/wp-includes/assets/script-loader-packages.php @@ -0,0 +1 @@ + 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')); \ No newline at end of file diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index ef085b5c93..60994dce30 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -231,81 +231,23 @@ function wp_get_script_polyfill( &$scripts, $tests ) { function wp_default_packages_scripts( &$scripts ) { $suffix = wp_scripts_get_suffix(); - $packages = array( - 'a11y', - 'annotations', - 'api-fetch', - 'autop', - 'blob', - 'block-directory', - 'block-editor', - 'block-library', - 'block-serialization-default-parser', - 'blocks', - 'components', - 'compose', - 'core-data', - 'data', - 'data-controls', - 'date', - 'deprecated', - 'dom', - 'dom-ready', - 'edit-post', - 'editor', - 'element', - 'escape-html', - 'format-library', - 'hooks', - 'html-entities', - 'i18n', - 'is-shallow-equal', - 'keyboard-shortcuts', - 'keycodes', - 'list-reusable-blocks', - 'media-utils', - 'notices', - 'nux', - 'plugins', - 'primitives', - 'priority-queue', - 'redux-routine', - 'rich-text', - 'shortcode', - 'server-side-render', - 'token-list', - 'url', - 'viewport', - 'warning', - 'wordcount', - ); + // Expects multidimensional array like: + // 'a11y.js' => array('dependencies' => array(...), 'version' => '...'), + // 'annotations.js' => array('dependencies' => array(...), 'version' => '...'), + // 'api-fetch.js' => array(... + $assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php'; - $package_translations = array( - 'api-fetch', - 'blocks', - 'block-directory', - 'block-editor', - 'block-library', - 'components', - 'edit-post', - 'editor', - 'format-library', - 'keycodes', - 'list-reusable-blocks', - 'nux', - ); + foreach ( $assets as $package_name => $package_data ) { + $basename = basename( $package_name, '.js' ); + $handle = 'wp-' . $basename; + $path = "/wp-includes/js/dist/{$basename}{$suffix}.js"; - foreach ( $packages as $package ) { - $handle = 'wp-' . $package; - $path = "/wp-includes/js/dist/$package$suffix.js"; - - if ( ! file_exists( ABSPATH . $path ) ) { - continue; + if ( ! empty( $package_data['dependencies'] ) ) { + $dependencies = $package_data['dependencies']; + } else { + $dependencies = array(); } - $asset_file = require ABSPATH . WPINC . "/assets/dist/$package$suffix.asset.php"; - $dependencies = $asset_file['dependencies']; - // Add dependencies that cannot be detected and generated by build tools. switch ( $handle ) { case 'wp-block-library': @@ -316,9 +258,9 @@ function wp_default_packages_scripts( &$scripts ) { break; } - $scripts->add( $handle, $path, $dependencies, $asset_file['version'], 1 ); + $scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 ); - if ( in_array( $package, $package_translations, true ) ) { + if ( in_array( 'wp-i18n', $dependencies, true ) ) { $scripts->set_translations( $handle ); } } diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index d55ff0e3f2..de6ed4a041 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -246,6 +246,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil } ), new DependencyExtractionPlugin( { injectPolyfill: true, + combineAssets: true, } ), new CopyWebpackPlugin( [