From edb416c9b2767d608ebb6882a44d12a507bc7c49 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 13 Dec 2023 17:48:09 +0000 Subject: [PATCH] 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 --- src/wp-includes/script-loader.php | 2 +- tests/phpunit/tests/dependencies/scripts.php | 37 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 41be694281..df2041f865 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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', diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 95cf958d3e..7701eda675 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -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']; + } }