From a9c313e0a9ff9d1c5f90c207bd911e19915af4c6 Mon Sep 17 00:00:00 2001 From: Christopher Holder <40126819+ChristopherPHolder@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:50:43 +0300 Subject: [PATCH] deps(lodash): migrate lodash to lodash-es (#16211) --- cli/test/smokehouse/frontends/lib.js | 2 +- .../smokehouse/frontends/smokehouse-bin.js | 2 +- cli/test/smokehouse/report-assert.js | 2 +- core/config/config-helpers.js | 6 +++--- core/gather/base-artifacts.js | 4 ++-- core/lib/arbitrary-equality-map.js | 4 ++-- core/runner.js | 8 ++++---- core/scripts/i18n/collect-strings.js | 4 ++-- package.json | 4 ++-- shared/localization/swap-locale.js | 8 ++++---- yarn.lock | 20 +++++++++++++++---- 11 files changed, 38 insertions(+), 26 deletions(-) diff --git a/cli/test/smokehouse/frontends/lib.js b/cli/test/smokehouse/frontends/lib.js index 08683373a39a..7283662bd2c3 100644 --- a/cli/test/smokehouse/frontends/lib.js +++ b/cli/test/smokehouse/frontends/lib.js @@ -12,7 +12,7 @@ /* eslint-disable no-console */ -import cloneDeep from 'lodash/cloneDeep.js'; +import {cloneDeep} from 'lodash-es'; import smokeTests from '../core-tests.js'; import {runSmokehouse, getShardedDefinitions} from '../smokehouse.js'; diff --git a/cli/test/smokehouse/frontends/smokehouse-bin.js b/cli/test/smokehouse/frontends/smokehouse-bin.js index 2ae51e1bf6aa..acb20ac51d26 100644 --- a/cli/test/smokehouse/frontends/smokehouse-bin.js +++ b/cli/test/smokehouse/frontends/smokehouse-bin.js @@ -16,7 +16,7 @@ import path from 'path'; import fs from 'fs'; import url from 'url'; -import cloneDeep from 'lodash/cloneDeep.js'; +import {cloneDeep} from 'lodash-es'; import yargs from 'yargs'; import * as yargsHelpers from 'yargs/helpers'; import log from 'lighthouse-logger'; diff --git a/cli/test/smokehouse/report-assert.js b/cli/test/smokehouse/report-assert.js index e21707be5dfe..2cc4e767af75 100644 --- a/cli/test/smokehouse/report-assert.js +++ b/cli/test/smokehouse/report-assert.js @@ -9,7 +9,7 @@ * against the results actually collected from Lighthouse. */ -import cloneDeep from 'lodash/cloneDeep.js'; +import {cloneDeep} from 'lodash-es'; import log from 'lighthouse-logger'; import {LocalConsole} from './lib/local-console.js'; diff --git a/core/config/config-helpers.js b/core/config/config-helpers.js index 00b672386593..53f9a5778828 100644 --- a/core/config/config-helpers.js +++ b/core/config/config-helpers.js @@ -8,7 +8,7 @@ import path from 'path'; import {createRequire} from 'module'; import url from 'url'; -import isDeepEqual from 'lodash/isEqual.js'; +import {isEqual} from 'lodash-es'; import * as constants from './constants.js'; import ConfigPlugin from './config-plugin.js'; @@ -69,7 +69,7 @@ const mergeOptionsOfItems = function(items) { * - `null` is treated similarly to `undefined` for whether a value should be overridden. * - `overwriteArrays` controls array extension behavior: * - true: Arrays are overwritten without any merging or concatenation. - * - false: Arrays are concatenated and de-duped by isDeepEqual. + * - false: Arrays are concatenated and de-duped by isEqual. * - Objects are recursively merged. * - If the `settings` key is encountered while traversing an object, its arrays are *always* * overridden, not concatenated. (`overwriteArrays` is flipped to `true`) @@ -90,7 +90,7 @@ function _mergeConfigFragment(base, extension, overwriteArrays = false) { if (!Array.isArray(base)) throw new TypeError(`Expected array but got ${typeof base}`); const merged = base.slice(); extension.forEach(item => { - if (!merged.some(candidate => isDeepEqual(candidate, item))) merged.push(item); + if (!merged.some(candidate => isEqual(candidate, item))) merged.push(item); }); return merged; diff --git a/core/gather/base-artifacts.js b/core/gather/base-artifacts.js index 5bb2a639cda4..b4e33a368174 100644 --- a/core/gather/base-artifacts.js +++ b/core/gather/base-artifacts.js @@ -5,7 +5,7 @@ */ import log from 'lighthouse-logger'; -import isDeepEqual from 'lodash/isEqual.js'; +import {isEqual} from 'lodash-es'; import { getBrowserVersion, getBenchmarkIndex, getEnvironmentWarnings, @@ -52,7 +52,7 @@ function deduplicateWarnings(warnings) { const unique = []; for (const warning of warnings) { - if (unique.some(existing => isDeepEqual(warning, existing))) continue; + if (unique.some(existing => isEqual(warning, existing))) continue; unique.push(warning); } diff --git a/core/lib/arbitrary-equality-map.js b/core/lib/arbitrary-equality-map.js index 85648d3e6fb2..4981cfd235b0 100644 --- a/core/lib/arbitrary-equality-map.js +++ b/core/lib/arbitrary-equality-map.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import isDeepEqual from 'lodash/isEqual.js'; +import {isEqual} from 'lodash-es'; /** * @fileoverview This class is designed to allow maps with arbitrary equality functions. @@ -73,7 +73,7 @@ class ArbitraryEqualityMap { * @return {boolean} */ static deepEquals(objA, objB) { - return isDeepEqual(objA, objB); + return isEqual(objA, objB); } } diff --git a/core/runner.js b/core/runner.js index ad4ccaeab9e7..96e762bd40cf 100644 --- a/core/runner.js +++ b/core/runner.js @@ -9,7 +9,7 @@ import path from 'path'; import log from 'lighthouse-logger'; -import isDeepEqual from 'lodash/isEqual.js'; +import {isEqual} from 'lodash-es'; import {ReportScoring} from './scoring.js'; import {Audit} from './audits/audit.js'; @@ -308,7 +308,7 @@ class Runner { ...Object.keys(normalizedAuditSettings), ]); for (const k of keys) { - if (!isDeepEqual(normalizedGatherSettings[k], normalizedAuditSettings[k])) { + if (!isEqual(normalizedGatherSettings[k], normalizedAuditSettings[k])) { throw new Error( `Cannot change settings between gathering and auditing… Difference found at: \`${k}\` @@ -318,8 +318,8 @@ vs } } - // Call `isDeepEqual` on the entire thing, just in case something was missed. - if (!isDeepEqual(normalizedGatherSettings, normalizedAuditSettings)) { + // Call `isEqual` on the entire thing, just in case something was missed. + if (!isEqual(normalizedGatherSettings, normalizedAuditSettings)) { throw new Error('Cannot change settings between gathering and auditing'); } } diff --git a/core/scripts/i18n/collect-strings.js b/core/scripts/i18n/collect-strings.js index 3ef95a4240c5..215fe1001694 100644 --- a/core/scripts/i18n/collect-strings.js +++ b/core/scripts/i18n/collect-strings.js @@ -16,7 +16,7 @@ import {expect} from 'expect'; import tsc from 'typescript'; import MessageParser from '@formatjs/icu-messageformat-parser'; import esMain from 'es-main'; -import isDeepEqual from 'lodash/isEqual.js'; +import {isEqual} from 'lodash-es'; import {Util} from '../../../shared/util.js'; import {collectAndBakeCtcStrings} from './bake-ctc-to-lhl.js'; @@ -660,7 +660,7 @@ function doPlaceholdersMatch(strings) { // Technically placeholder `content` is not required to match by TC, but since // `example` must match and any auto-generated `example` is copied from `content`, // it would be confusing to let it differ when `example` is explicit. - return strings.every(val => isDeepEqual(val.ctc.placeholders, strings[0].ctc.placeholders)); + return strings.every(val => isEqual(val.ctc.placeholders, strings[0].ctc.placeholders)); } /** diff --git a/package.json b/package.json index dcb2a194b7df..38226d65bd46 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "@types/google.analytics": "0.0.39", "@types/jpeg-js": "^0.3.7", "@types/jsdom": "^16.2.13", - "@types/lodash": "^4.14.178", + "@types/lodash-es": "^4.17.12", "@types/mocha": "^9.0.0", "@types/node": "*", "@types/pako": "^1.0.1", @@ -195,7 +195,7 @@ "js-library-detector": "^6.7.0", "lighthouse-logger": "^2.0.1", "lighthouse-stack-packs": "1.12.1", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "lookup-closest-locale": "6.2.0", "metaviewport-parser": "0.3.0", "open": "^8.4.0", diff --git a/shared/localization/swap-locale.js b/shared/localization/swap-locale.js index 8e5d40436317..f80e93359366 100644 --- a/shared/localization/swap-locale.js +++ b/shared/localization/swap-locale.js @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -import _set from 'lodash/set.js'; -import _get from 'lodash/get.js'; +import {set} from 'lodash-es'; +import {get} from 'lodash-es'; import * as format from './format.js'; @@ -72,7 +72,7 @@ function swapLocale(lhr, requestedLocale) { // If the path isn't valid or the value isn't a string, there's no point in trying to replace it. /** @type {unknown} */ - const originalString = _get(lhr, path); + const originalString = get(lhr, path); if (typeof originalString !== 'string') { continue; } @@ -96,7 +96,7 @@ function swapLocale(lhr, requestedLocale) { } // Write string back into the LHR. - _set(lhr, path, relocalizedString); + set(lhr, path, relocalizedString); } } diff --git a/yarn.lock b/yarn.lock index e059d5a6a3c6..6ac4968758af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1458,10 +1458,17 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= -"@types/lodash@^4.14.178": - version "4.14.178" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8" - integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw== +"@types/lodash-es@^4.17.12": + version "4.17.12" + resolved "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz#65f6d1e5f80539aa7cfbfc962de5def0cf4f341b" + integrity sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.17.10" + resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.10.tgz#64f3edf656af2fe59e7278b73d3e62404144a6e6" + integrity sha512-YpS0zzoduEhuOWjAotS6A5AVCva7X4lVlYLF0FYHAY9sdraBfnatttHItlWeZdGhuEkf+OzMNg2ZYAx8t+52uQ== "@types/long@^4.0.1": version "4.0.1" @@ -5099,6 +5106,11 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +lodash-es@^4.17.21: + version "4.17.21" + resolved "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" + integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== + lodash.assign@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"