From 1ec56ec5b55dc535eb7d6a72fd8c548541179219 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 23 Jun 2021 00:04:47 +0000 Subject: [PATCH] Build/Test Tools: Add the `regenerator-runtime` script as a dependency to `wp-polyfill`. In [51146], the `core-js` package replaced the deprecated `@babel//polyfill` one. The `core-js` package builds `wp-polyfill` from a configuration provided by `@wordpress/babel-preset-default` instead of copying a one size fits all polyfill. That change caused an issue where plugins and themes relying on the `regenerator-runtime` script being included in the `wp-polyfill.js` file encountering fatal JavaScript errors. This adds the `regenerator-runtime` package to Core and registers it as a dependency for `wp-polyfill`. While Core does not require `regenerator-runtime`, it will allow for a smoother transition to using `core-js`. This dependency will be removed in a future version of WordPress, so developers are encouraged to add `regenerator-runtime` as a dependency for any custom script that requires it. Follow up to [51146]. Props gziolo, herregroen, jeherve, hellofromtonya, peterwilsoncc. Fixes #52941. git-svn-id: https://develop.svn.wordpress.org/trunk@51212 602fd350-edb4-49c9-b593-d223f7449a82 --- package.json | 1 + src/wp-includes/script-loader.php | 12 ++++++------ tests/phpunit/tests/dependencies/scripts.php | 2 +- tools/webpack/packages.js | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 933aa4cb82..1e85090124 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,7 @@ "polyfill-library": "3.105.0", "react": "16.13.1", "react-dom": "16.13.1", + "regenerator-runtime": "0.13.7", "twemoji": "13.1.0", "underscore": "1.13.1", "whatwg-fetch": "3.0.0" diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index c7a6963f73..b2abe86f26 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -80,8 +80,9 @@ function wp_default_packages_vendor( $scripts ) { $suffix = wp_scripts_get_suffix(); $vendor_scripts = array( - 'react' => array( 'wp-polyfill' ), - 'react-dom' => array( 'react' ), + 'react' => array( 'wp-polyfill' ), + 'react-dom' => array( 'react' ), + 'regenerator-runtime', 'moment', 'lodash', 'wp-polyfill-fetch', @@ -91,12 +92,13 @@ function wp_default_packages_vendor( $scripts ) { 'wp-polyfill-dom-rect', 'wp-polyfill-element-closest', 'wp-polyfill-object-fit', - 'wp-polyfill', + 'wp-polyfill' => array( 'regenerator-runtime' ), ); $vendor_scripts_versions = array( 'react' => '16.13.1', 'react-dom' => '16.13.1', + 'regenerator-runtime' => '0.13.7', 'moment' => '2.29.1', 'lodash' => '4.17.19', 'wp-polyfill-fetch' => '3.0.0', @@ -106,7 +108,7 @@ function wp_default_packages_vendor( $scripts ) { 'wp-polyfill-dom-rect' => '3.104.0', 'wp-polyfill-element-closest' => '2.0.2', 'wp-polyfill-object-fit' => '2.3.5', - 'wp-polyfill' => '7.4.4', + 'wp-polyfill' => '3.15.0', ); foreach ( $vendor_scripts as $handle => $dependencies ) { @@ -121,8 +123,6 @@ function wp_default_packages_vendor( $scripts ) { $scripts->add( $handle, $path, $dependencies, $version, 1 ); } - $scripts->add( 'wp-polyfill', null, array( 'wp-polyfill' ) ); - did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' ); did_action( 'init' ) && $scripts->add_inline_script( diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 533704ed09..ddcf04a85f 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -723,7 +723,7 @@ JS; $ver = get_bloginfo( 'version' ); $suffix = wp_scripts_get_suffix(); - $expected = "\n"; + $expected = "\n"; $expected .= "\n"; $expected .= "\n"; $expected .= "\n"; diff --git a/tools/webpack/packages.js b/tools/webpack/packages.js index 4a9f308e3a..80840b8b90 100644 --- a/tools/webpack/packages.js +++ b/tools/webpack/packages.js @@ -84,6 +84,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'moment.js': 'moment/moment.js', 'react.js': 'react/umd/react.development.js', 'react-dom.js': 'react-dom/umd/react-dom.development.js', + 'regenerator-runtime.js': 'regenerator-runtime/runtime.js', }; const minifiedVendors = { @@ -98,6 +99,7 @@ module.exports = function( env = { environment: 'production', watch: false, buil }; const minifyVendors = { + 'regenerator-runtime.min.js': 'regenerator-runtime/runtime.js', 'wp-polyfill-fetch.min.js': 'whatwg-fetch/dist/fetch.umd.js', 'wp-polyfill-element-closest.min.js': 'element-closest/element-closest.js', 'wp-polyfill-node-contains.min.js': 'polyfill-library/polyfills/__dist/Node.prototype.contains/raw.js',