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
This commit is contained in:
Jonathan Desrosiers
2021-06-23 00:04:47 +00:00
parent a59cea3c92
commit 1ec56ec5b5
4 changed files with 10 additions and 7 deletions

View File

@@ -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(