Make WordPress Core


Ignore:
Timestamp:
12/13/2023 05:48:09 PM (3 years ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r56933 r57185  
    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}
Note: See TracChangeset for help on using the changeset viewer.