Skip to content

Commit edb416c

Browse files
committed
External Libraries: For Lodash, sync the declared version number with the one that is loaded.
In [50941] the version of lodash was updated, however the version inside `wp_default_packages_vendor` was not updated at the same time. This updates the version to correctly reflect the version that is loaded. Also adds some basic tests for the scripts in `wp_default_packages_vendor` that match the name of the package from package.json to help prevent errors like this in the future. Props jadpm, jorbin, swissspidy. Fixes #60048. See #52991. git-svn-id: https://develop.svn.wordpress.org/trunk@57185 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5eef2bb commit edb416c

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/wp-includes/script-loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function wp_default_packages_vendor( $scripts ) {
110110
'react-dom' => '18.2.0',
111111
'regenerator-runtime' => '0.14.0',
112112
'moment' => '2.29.4',
113-
'lodash' => '4.17.19',
113+
'lodash' => '4.17.21',
114114
'wp-polyfill-fetch' => '3.6.17',
115115
'wp-polyfill-formdata' => '4.0.10',
116116
'wp-polyfill-node-contains' => '4.8.0',

tests/phpunit/tests/dependencies/scripts.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,4 +3352,41 @@ public function data_provider_script_move_to_footer() {
33523352

33533353
);
33543354
}
3355+
3356+
/**
3357+
* @ticket 60048
3358+
*
3359+
* @covers ::wp_default_packages_vendor
3360+
*
3361+
* @dataProvider data_wp_default_packages_vendor
3362+
*/
3363+
public function test_wp_default_packages_vendor_lodash( $script ) {
3364+
global $wp_scripts;
3365+
$package_json = $this->_scripts_from_package_json();
3366+
3367+
wp_default_packages_vendor( $wp_scripts );
3368+
3369+
$this->assertEquals( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver );
3370+
}
3371+
3372+
public function data_wp_default_packages_vendor() {
3373+
return array(
3374+
array( 'script' => 'lodash' ),
3375+
array( 'script' => 'moment' ),
3376+
array( 'script' => 'react' ),
3377+
array( 'script' => 'react-dom' ),
3378+
array( 'script' => 'regenerator-runtime' ),
3379+
);
3380+
}
3381+
3382+
/**
3383+
* Helper to return dependencies from package.json.
3384+
*/
3385+
private function _scripts_from_package_json() {
3386+
$package = file_get_contents( ABSPATH . '../package.json' );
3387+
$data = json_decode( $package, true );
3388+
3389+
$provider = array();
3390+
return $data['dependencies'];
3391+
}
33553392
}

0 commit comments

Comments
 (0)