Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude Iterator helpers from polyfills #69070

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/babel-preset-default/polyfill-exclusions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ module.exports = [
//
// @see https://github.com/WordPress/gutenberg/pull/67230
/^es(next)?\.set\./,
// Remove Iterator feature polyfills.
// For the same reasoning as for Set exlusion above, we're excluding all iterator helper polyfills.
//
// @see https://github.com/WordPress/wordpress-develop/pull/8224#issuecomment-2636390007.
/^es(next)?\.iterator\./,
];
48 changes: 48 additions & 0 deletions phpunit/script-dependencies-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* @group script-dependencies
*/
class Test_Script_Dependencies extends WP_UnitTestCase {
public $bundled_scripts = array( 'wp-upload-media' );

/**
* Tests for accidental `wp-polyfill` script dependents.
*/
public function test_polyfill_dependents() {
$scripts = wp_scripts();
$registered_scripts = $scripts->registered;
$dependents = array();

// Iterate over all registered scripts, finding dependents of the `wp-polyfill` script.
// Based on private `WP_Scripts::get_dependents` method.
foreach ( $registered_scripts as $registered_handle => $args ) {
// Ignore bundled packages, they don't load separate polyfills.
if ( in_array( $registered_handle, $this->bundled_scripts, true ) ) {
continue;
}
Comment on lines +20 to +23
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not ideal, but I couldn't find out why wp-upload-media is missing from $dependents on CI. However, we could skip checking for bundled packages as they are not enqueued separately.

The unit tests are passing without an issue locally. Happy to adjust further if anyone has ideas why this is only failing on CI.


if ( in_array( 'wp-polyfill', $args->deps, true ) ) {
$dependents[] = $registered_handle;
}
}

// This list should get smaller over time as we remove `wp-polyfill` dependencies.
// If the list update is intentional, please add a comment explaining why.
$expected = array(
'react',
'wp-blob',
'wp-block-editor',
'wp-block-library',
'wp-blocks',
'wp-edit-site',
'wp-core-data',
'wp-editor',
'wp-router',
'wp-url',
'wp-widgets',
);

$this->assertEqualSets( $expected, $dependents );
}
}
Loading