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
This commit is contained in:
Aaron Jorbin 2023-12-13 17:48:09 +00:00
parent 5eef2bbb2a
commit edb416c9b2
2 changed files with 38 additions and 1 deletions

View File

@ -110,7 +110,7 @@ function wp_default_packages_vendor( $scripts ) {
'react-dom' => '18.2.0',
'regenerator-runtime' => '0.14.0',
'moment' => '2.29.4',
'lodash' => '4.17.19',
'lodash' => '4.17.21',
'wp-polyfill-fetch' => '3.6.17',
'wp-polyfill-formdata' => '4.0.10',
'wp-polyfill-node-contains' => '4.8.0',

View File

@ -3352,4 +3352,41 @@ HTML
);
}
/**
* @ticket 60048
*
* @covers ::wp_default_packages_vendor
*
* @dataProvider data_wp_default_packages_vendor
*/
public function test_wp_default_packages_vendor_lodash( $script ) {
global $wp_scripts;
$package_json = $this->_scripts_from_package_json();
wp_default_packages_vendor( $wp_scripts );
$this->assertEquals( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver );
}
public function data_wp_default_packages_vendor() {
return array(
array( 'script' => 'lodash' ),
array( 'script' => 'moment' ),
array( 'script' => 'react' ),
array( 'script' => 'react-dom' ),
array( 'script' => 'regenerator-runtime' ),
);
}
/**
* Helper to return dependencies from package.json.
*/
private function _scripts_from_package_json() {
$package = file_get_contents( ABSPATH . '../package.json' );
$data = json_decode( $package, true );
$provider = array();
return $data['dependencies'];
}
}