Skip to content

Commit

Permalink
deps(lodash): migrate lodash to lodash-es (#16211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherPHolder authored Oct 11, 2024
1 parent 0c7c183 commit a9c313e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cli/test/smokehouse/frontends/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/frontends/smokehouse-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/report-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`)
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/gather/base-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import log from 'lighthouse-logger';
import isDeepEqual from 'lodash/isEqual.js';
import {isEqual} from 'lodash-es';

import {
getBrowserVersion, getBenchmarkIndex, getEnvironmentWarnings,
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions core/lib/arbitrary-equality-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,7 +73,7 @@ class ArbitraryEqualityMap {
* @return {boolean}
*/
static deepEquals(objA, objB) {
return isDeepEqual(objA, objB);
return isEqual(objA, objB);
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}\`
Expand All @@ -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');
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions shared/localization/swap-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
Expand All @@ -96,7 +96,7 @@ function swapLocale(lhr, requestedLocale) {
}

// Write string back into the LHR.
_set(lhr, path, relocalizedString);
set(lhr, path, relocalizedString);
}
}

Expand Down
20 changes: 16 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a9c313e

Please sign in to comment.