Script Loader: Remove importmap polyfill.

The polyfill was added in [57492], but all browsers supported by WordPress already support import maps.

This not only disables the polyfill, but completely removes it as it was only added recently and there is no usage outside of core.

Props swissspidy, desrosj, luisherranz, gziolo.
Fixes #60970.

git-svn-id: https://develop.svn.wordpress.org/trunk@58952 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Pascal Birchler 2024-08-29 06:04:02 +00:00
parent 0a9dcb4bfc
commit 35f82135f1
7 changed files with 4 additions and 67 deletions

11
package-lock.json generated
View File

@ -79,7 +79,6 @@
"clipboard": "2.0.11",
"core-js-url-browser": "3.6.4",
"element-closest": "^3.0.2",
"es-module-shims": "1.8.2",
"formdata-polyfill": "4.0.10",
"hoverintent": "2.2.1",
"imagesloaded": "5.0.0",
@ -14115,11 +14114,6 @@
"integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==",
"dev": true
},
"node_modules/es-module-shims": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/es-module-shims/-/es-module-shims-1.8.2.tgz",
"integrity": "sha512-7vIYVzpOhXtpc3Yn03itB+GSgVZFW7oL4kdydA+iL+IEi7HiSLBUxM05QFw4SxTl6e++pMpGqZPo2+vdNs3TbA=="
},
"node_modules/es-object-atoms": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz",
@ -44753,11 +44747,6 @@
"integrity": "sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==",
"dev": true
},
"es-module-shims": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/es-module-shims/-/es-module-shims-1.8.2.tgz",
"integrity": "sha512-7vIYVzpOhXtpc3Yn03itB+GSgVZFW7oL4kdydA+iL+IEi7HiSLBUxM05QFw4SxTl6e++pMpGqZPo2+vdNs3TbA=="
},
"es-object-atoms": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.0.0.tgz",

View File

@ -148,7 +148,6 @@
"clipboard": "2.0.11",
"core-js-url-browser": "3.6.4",
"element-closest": "^3.0.2",
"es-module-shims": "1.8.2",
"formdata-polyfill": "4.0.10",
"hoverintent": "2.2.1",
"imagesloaded": "5.0.0",

View File

@ -236,20 +236,6 @@ class WP_Script_Modules {
public function print_import_map() {
$import_map = $this->get_import_map();
if ( ! empty( $import_map['imports'] ) ) {
global $wp_scripts;
if ( isset( $wp_scripts ) ) {
wp_print_inline_script_tag(
wp_get_script_polyfill(
$wp_scripts,
array(
'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")' => 'wp-polyfill-importmap',
)
),
array(
'id' => 'wp-load-polyfill-importmap',
)
);
}
wp_print_inline_script_tag(
wp_json_encode( $import_map, JSON_HEX_TAG | JSON_HEX_AMP ),
array(

View File

@ -96,7 +96,6 @@ function wp_default_packages_vendor( $scripts ) {
'lodash',
'wp-polyfill-fetch',
'wp-polyfill-formdata',
'wp-polyfill-importmap',
'wp-polyfill-node-contains',
'wp-polyfill-url',
'wp-polyfill-dom-rect',
@ -122,7 +121,6 @@ function wp_default_packages_vendor( $scripts ) {
'wp-polyfill-object-fit' => '2.3.5',
'wp-polyfill-inert' => '3.1.2',
'wp-polyfill' => '3.15.0',
'wp-polyfill-importmap' => '1.8.2',
);
foreach ( $vendor_scripts as $handle => $dependencies ) {

View File

@ -3117,9 +3117,9 @@ HTML
*/
public function test_wp_get_script_polyfill() {
global $wp_scripts;
$script_name = 'wp-polyfill-importmap';
$test_script = 'HTMLScriptElement.supports && HTMLScriptElement.supports("importmap")';
$script_url = 'https://example.com/wp-polyfill-importmap.js';
$script_name = 'tmp-polyfill-foo';
$test_script = 'HTMLScriptElement.supports && HTMLScriptElement.supports("foo")';
$script_url = 'https://example.com/polyfill-foo.js';
wp_register_script( $script_name, $script_url );
$polyfill = wp_get_script_polyfill(
@ -3133,7 +3133,7 @@ HTML
$expected = '( ' . $test_script . ' ) || document.write( \'<script src="' . $script_url . '"></scr\' + \'ipt>\' );';
$this->assertEquals( $expected, $polyfill );
$this->assertSame( $expected, $polyfill );
}
/**

View File

@ -700,39 +700,6 @@ class Tests_Script_Modules_WpScriptModules extends WP_UnitTestCase {
$this->assertStringStartsWith( '/dep.js', $import_map['dep'] );
}
/**
* @ticket 60348
*
* @covers ::print_import_map_polyfill()
*/
public function test_wp_print_import_map_has_no_polyfill_when_no_modules_registered() {
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );
$this->assertSame( '', $import_map_polyfill );
}
/**
* @ticket 60348
*
* @covers ::print_import_map_polyfill()
*/
public function test_wp_print_import_map_has_polyfill_when_modules_registered() {
$script_name = 'wp-polyfill-importmap';
wp_register_script( $script_name, '/wp-polyfill-importmap.js' );
$this->script_modules->enqueue( 'foo', '/foo.js', array( 'dep' ), '1.0' );
$this->script_modules->register( 'dep', '/dep.js' );
$import_map_polyfill = get_echo( array( $this->script_modules, 'print_import_map' ) );
wp_deregister_script( $script_name );
$p = new WP_HTML_Tag_Processor( $import_map_polyfill );
$p->next_tag( array( 'tag' => 'SCRIPT' ) );
$id = $p->get_attribute( 'id' );
$this->assertSame( 'wp-load-polyfill-importmap', $id );
}
/**
* @ticket 61510
*/

View File

@ -93,7 +93,6 @@ module.exports = function (
'wp-polyfill-object-fit.js':
'objectFitPolyfill/src/objectFitPolyfill.js',
'wp-polyfill-inert.js': 'wicg-inert/dist/inert.js',
'wp-polyfill-importmap.js': 'es-module-shims/dist/es-module-shims.wasm.js',
'moment.js': 'moment/moment.js',
'regenerator-runtime.js': 'regenerator-runtime/runtime.js',
'react.js': 'react/umd/react.development.js',
@ -122,7 +121,6 @@ module.exports = function (
'polyfill-library/polyfills/__dist/Node.prototype.contains/raw.js',
'wp-polyfill-dom-rect.min.js':
'polyfill-library/polyfills/__dist/DOMRect/raw.js',
'wp-polyfill-importmap.min.js': 'es-module-shims/dist/es-module-shims.wasm.js',
};
const phpFiles = {