From c8326abe7359dfb37b982b3978e779224e42d91d Mon Sep 17 00:00:00 2001 From: evan-moon Date: Fri, 8 Aug 2025 13:10:32 +0900 Subject: [PATCH 1/2] chore(gatsby): migrate lodash to es-toolkit --- packages/gatsby/cache-dir/dev-loader.js | 2 +- .../gatsby/cache-dir/develop-static-entry.js | 2 +- .../cache-dir/ssr-develop-static-entry.js | 9 +++++++- packages/gatsby/package.json | 2 +- .../load-plugins/load-internal-plugins.ts | 2 +- .../bootstrap/load-plugins/process-plugin.ts | 2 +- .../bootstrap/load-plugins/resolve-plugin.ts | 2 +- .../bootstrap/load-plugins/utils/get-api.ts | 2 +- .../src/bootstrap/load-plugins/validate.ts | 14 ++++++------ .../gatsby/src/bootstrap/load-themes/index.ts | 2 +- .../gatsby/src/bootstrap/redirects-writer.ts | 4 ++-- .../gatsby/src/bootstrap/requires-writer.ts | 10 ++++----- .../src/bootstrap/schema-hot-reloader.ts | 2 +- packages/gatsby/src/commands/build-html.ts | 2 +- packages/gatsby/src/datastore/common/query.ts | 2 +- .../src/datastore/in-memory/indexing.ts | 4 ++-- .../datastore/in-memory/run-fast-filters.ts | 4 ++-- .../internal-plugins/functions/gatsby-node.ts | 8 +++---- packages/gatsby/src/query/graphql-errors.js | 6 ++--- packages/gatsby/src/query/graphql-runner.ts | 2 +- packages/gatsby/src/query/index.ts | 4 ++-- packages/gatsby/src/query/query-runner.ts | 1 - .../gatsby/src/redux/actions/restricted.ts | 3 +-- packages/gatsby/src/redux/index.ts | 6 ++--- .../src/redux/reducers/__tests__/queries.ts | 2 +- packages/gatsby/src/redux/reducers/babelrc.ts | 10 ++++----- .../src/redux/reducers/inference-metadata.ts | 2 +- packages/gatsby/src/redux/reducers/jobs.ts | 10 ++++----- .../gatsby/src/redux/reducers/redirects.ts | 4 ++-- .../src/redux/reducers/resolved-nodes.ts | 2 +- packages/gatsby/src/redux/reducers/status.ts | 6 ++--- .../schema/graphql-engine/bundle-webpack.ts | 2 +- .../schema/graphql-engine/print-plugins.ts | 2 +- .../infer/__tests__/inference-metadata.ts | 6 ++--- .../src/schema/infer/build-example-data.ts | 2 +- .../src/schema/infer/inference-metadata.ts | 2 +- .../schema/infer/type-conflict-reporter.ts | 2 +- packages/gatsby/src/schema/print.ts | 6 ++--- packages/gatsby/src/schema/utils.ts | 2 +- packages/gatsby/src/services/initialize.ts | 4 ++-- .../src/utils/__tests__/handle-flags.ts | 2 -- packages/gatsby/src/utils/adapter/init.ts | 1 - .../gatsby/src/utils/babel-loader-helpers.ts | 6 ++--- packages/gatsby/src/utils/changed-pages.ts | 4 ++-- packages/gatsby/src/utils/flags.ts | 4 ++-- .../gatsby/src/utils/gatsby-dependents.ts | 2 +- .../gatsby/src/utils/graphql-typegen/utils.ts | 4 ++-- packages/gatsby/src/utils/handle-flags.ts | 4 ++-- packages/gatsby/src/utils/jobs/manager.ts | 4 ++-- packages/gatsby/src/utils/js-chunk-names.ts | 2 +- .../gatsby/src/utils/merge-gatsby-config.ts | 8 +++---- packages/gatsby/src/utils/prepare-regex.ts | 4 ++-- packages/gatsby/src/utils/sanitize-node.ts | 22 +++++++++---------- .../src/utils/validate-engines/index.ts | 2 +- .../webpack/plugins/static-query-mapper.ts | 2 +- packages/gatsby/src/utils/worker/pool.ts | 2 +- 56 files changed, 117 insertions(+), 117 deletions(-) diff --git a/packages/gatsby/cache-dir/dev-loader.js b/packages/gatsby/cache-dir/dev-loader.js index d25bf3ec25614..107effaf264f8 100644 --- a/packages/gatsby/cache-dir/dev-loader.js +++ b/packages/gatsby/cache-dir/dev-loader.js @@ -5,7 +5,7 @@ import getSocket from "./socketIo" import normalizePagePath from "./normalize-page-path" // TODO move away from lodash -import isEqual from "lodash/isEqual" +import { isEqual } from "es-toolkit/compat" function mergePageEntry(cachedPage, newPageData) { return { diff --git a/packages/gatsby/cache-dir/develop-static-entry.js b/packages/gatsby/cache-dir/develop-static-entry.js index 77a1cd9357a1f..ec40dccfd66e1 100644 --- a/packages/gatsby/cache-dir/develop-static-entry.js +++ b/packages/gatsby/cache-dir/develop-static-entry.js @@ -1,7 +1,7 @@ /* global BROWSER_ESM_ONLY */ import React from "react" import { renderToStaticMarkup } from "react-dom/server" -import { merge } from "lodash" +import { merge } from "es-toolkit/compat" import { apiRunner } from "./api-runner-ssr" import asyncRequires from "$virtual/async-requires" diff --git a/packages/gatsby/cache-dir/ssr-develop-static-entry.js b/packages/gatsby/cache-dir/ssr-develop-static-entry.js index fd4aed55e748a..2192a82cb7420 100644 --- a/packages/gatsby/cache-dir/ssr-develop-static-entry.js +++ b/packages/gatsby/cache-dir/ssr-develop-static-entry.js @@ -2,7 +2,14 @@ import React from "react" import fs from "fs-extra" import { renderToStaticMarkup, renderToPipeableStream } from "react-dom/server" -import { get, merge, isObject, flatten, uniqBy, concat } from "lodash" +import { + get, + merge, + isObject, + flatten, + uniqBy, + concat, +} from "es-toolkit/compat" import nodePath from "path" import { apiRunner, apiRunnerAsync } from "./api-runner-ssr" import { grabMatchParams } from "./find-path" diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index c68db3ac3ebb9..e92e7bfb82c02 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -120,7 +120,7 @@ "latest-version": "^7.0.0", "linkfs": "^2.1.0", "lmdb": "2.5.3", - "lodash": "^4.17.21", + "es-toolkit": "^1.30.0", "meant": "^1.0.3", "memoizee": "^0.4.15", "micromatch": "^4.0.5", diff --git a/packages/gatsby/src/bootstrap/load-plugins/load-internal-plugins.ts b/packages/gatsby/src/bootstrap/load-plugins/load-internal-plugins.ts index e58a38e1deb64..d23ff033f54e0 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/load-internal-plugins.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/load-internal-plugins.ts @@ -1,5 +1,5 @@ import { slash } from "gatsby-core-utils" -import { uniqWith, isEqual } from "lodash" +import { uniqWith, isEqual } from "es-toolkit/compat" import path from "path" import reporter from "gatsby-cli/lib/reporter" import { store } from "../../redux" diff --git a/packages/gatsby/src/bootstrap/load-plugins/process-plugin.ts b/packages/gatsby/src/bootstrap/load-plugins/process-plugin.ts index c9707e4c8069f..bb4f791e58fa1 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/process-plugin.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/process-plugin.ts @@ -1,7 +1,7 @@ import { IPluginInfo, PluginRef } from "./types" import { createPluginId } from "./utils/create-id" import { resolvePlugin } from "./resolve-plugin" -import { isString, isEmpty, set, merge } from "lodash" +import { isString, isEmpty, set, merge } from "es-toolkit/compat" export function processPlugin(plugin: PluginRef, rootDir: string): IPluginInfo { // Respect the directory that the plugin was sourced from initially diff --git a/packages/gatsby/src/bootstrap/load-plugins/resolve-plugin.ts b/packages/gatsby/src/bootstrap/load-plugins/resolve-plugin.ts index c8fa41df27bfb..301b7d55aedf2 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/resolve-plugin.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/resolve-plugin.ts @@ -7,7 +7,7 @@ import { IPluginInfo, PluginRef } from "./types" import { createPluginId } from "./utils/create-id" import { createFileContentHash } from "./utils/create-hash" import reporter from "gatsby-cli/lib/reporter" -import { isString } from "lodash" +import { isString } from "es-toolkit/compat" import { checkLocalPlugin } from "./utils/check-local-plugin" import { getResolvedFieldsForPlugin } from "../../utils/parcel/compile-gatsby-files" diff --git a/packages/gatsby/src/bootstrap/load-plugins/utils/get-api.ts b/packages/gatsby/src/bootstrap/load-plugins/utils/get-api.ts index 3185b3cf19f79..1afb80c10c2b3 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/utils/get-api.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/utils/get-api.ts @@ -1,5 +1,5 @@ import { ExportType, ICurrentAPIs } from "../validate" -import { keys } from "lodash" +import { keys } from "es-toolkit/compat" export const getAPI = (api: { [exportType in ExportType]: { [api: string]: boolean } diff --git a/packages/gatsby/src/bootstrap/load-plugins/validate.ts b/packages/gatsby/src/bootstrap/load-plugins/validate.ts index b553f0eb88e78..319fe1dd024f5 100644 --- a/packages/gatsby/src/bootstrap/load-plugins/validate.ts +++ b/packages/gatsby/src/bootstrap/load-plugins/validate.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { difference, intersection, toPairs, get } from "es-toolkit/compat" import path from "path" import * as semver from "semver" import * as stringSimilarity from "string-similarity" @@ -63,7 +63,7 @@ function getBadExports( let badExports: Array = [] // Discover any exports from plugins which are not "known" badExports = badExports.concat( - _.difference(pluginAPIKeys, apis).map(e => { + difference(pluginAPIKeys, apis).map(e => { return { exportName: e, pluginName: plugin.name, @@ -162,7 +162,7 @@ export async function handleBadExports({ if (hasBadExports) { const latestAPIs = await getLatestAPIs() // Output error messages for all bad exports - _.toPairs(badExports).forEach(badItem => { + toPairs(badExports).forEach(badItem => { const [exportType, entries] = badItem if (entries.length > 0) { const context = getErrorContext( @@ -473,14 +473,14 @@ export async function collatePluginAPIs({ ) if (pluginNodeExports.length > 0) { - plugin.nodeAPIs = _.intersection(pluginNodeExports, currentAPIs.node) + plugin.nodeAPIs = intersection(pluginNodeExports, currentAPIs.node) badExports.node = badExports.node.concat( getBadExports(plugin, pluginNodeExports, currentAPIs.node) ) // Collate any bad exports } if (pluginBrowserExports.length > 0) { - plugin.browserAPIs = _.intersection( + plugin.browserAPIs = intersection( pluginBrowserExports, currentAPIs.browser ) @@ -490,7 +490,7 @@ export async function collatePluginAPIs({ } if (pluginSSRExports.length > 0) { - plugin.ssrAPIs = _.intersection(pluginSSRExports, currentAPIs.ssr) + plugin.ssrAPIs = intersection(pluginSSRExports, currentAPIs.ssr) badExports.ssr = badExports.ssr.concat( getBadExports(plugin, pluginSSRExports, currentAPIs.ssr) ) // Collate any bad exports @@ -561,7 +561,7 @@ export function warnOnIncompatiblePeerDependency( packageJSON: PackageJson ): void { // Note: In the future the peer dependency should be enforced for all plugins. - const gatsbyPeerDependency = _.get(packageJSON, `peerDependencies.gatsby`) + const gatsbyPeerDependency = get(packageJSON, `peerDependencies.gatsby`) if ( !isWorker && gatsbyPeerDependency && diff --git a/packages/gatsby/src/bootstrap/load-themes/index.ts b/packages/gatsby/src/bootstrap/load-themes/index.ts index c853796e93b15..ee111cdd900d9 100644 --- a/packages/gatsby/src/bootstrap/load-themes/index.ts +++ b/packages/gatsby/src/bootstrap/load-themes/index.ts @@ -7,7 +7,7 @@ import { IPluginEntryWithParentDir, } from "../../utils/merge-gatsby-config" import { mapSeries } from "bluebird" -import { flattenDeep, isEqual, isFunction, uniqWith } from "lodash" +import { flattenDeep, isEqual, isFunction, uniqWith } from "es-toolkit/compat" import DebugCtor from "debug" import { preferDefault } from "../prefer-default" import { getConfigFile } from "../get-config-file" diff --git a/packages/gatsby/src/bootstrap/redirects-writer.ts b/packages/gatsby/src/bootstrap/redirects-writer.ts index d22cc1a26515f..4dcbadd035036 100644 --- a/packages/gatsby/src/bootstrap/redirects-writer.ts +++ b/packages/gatsby/src/bootstrap/redirects-writer.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { debounce } from "es-toolkit/compat" import fs from "fs-extra" import { joinPath, md5 } from "gatsby-core-utils" import reporter from "gatsby-cli/lib/reporter" @@ -66,7 +66,7 @@ export const writeRedirects = async (): Promise => { ) } -const debouncedWriteRedirects = _.debounce(() => { +const debouncedWriteRedirects = debounce(() => { // Don't write redirects again until bootstrap has finished. if (bootstrapFinished) { writeRedirects() diff --git a/packages/gatsby/src/bootstrap/requires-writer.ts b/packages/gatsby/src/bootstrap/requires-writer.ts index 7f596eed42282..8e132f7fc72e0 100644 --- a/packages/gatsby/src/bootstrap/requires-writer.ts +++ b/packages/gatsby/src/bootstrap/requires-writer.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { orderBy, uniqBy, map, debounce } from "es-toolkit/compat" import path from "path" import fs from "fs-extra" import reporter from "gatsby-cli/lib/reporter" @@ -56,9 +56,9 @@ export const getComponents = ( } } - return _.orderBy( - _.uniqBy( - _.map([...pages, ...slices.values()], pickComponentFields), + return orderBy( + uniqBy( + map([...pages, ...slices.values()], pickComponentFields), c => c.componentChunkName ), c => c.componentChunkName @@ -319,7 +319,7 @@ exports.head = {\n${components return true } -const debouncedWriteAll = _.debounce( +const debouncedWriteAll = debounce( async (): Promise => { const activity = reporter.activityTimer(`write out requires`, { id: `requires-writer`, diff --git a/packages/gatsby/src/bootstrap/schema-hot-reloader.ts b/packages/gatsby/src/bootstrap/schema-hot-reloader.ts index 3fc37dc809309..b08af45ed3ffa 100644 --- a/packages/gatsby/src/bootstrap/schema-hot-reloader.ts +++ b/packages/gatsby/src/bootstrap/schema-hot-reloader.ts @@ -1,4 +1,4 @@ -import { debounce, cloneDeep } from "lodash" +import { debounce, cloneDeep } from "es-toolkit/compat" import { emitter, store } from "../redux" import { rebuild } from "../schema" import { haveEqualFields } from "../schema/infer/inference-metadata" diff --git a/packages/gatsby/src/commands/build-html.ts b/packages/gatsby/src/commands/build-html.ts index 701fdda2c5d4b..e5bd352b4133a 100644 --- a/packages/gatsby/src/commands/build-html.ts +++ b/packages/gatsby/src/commands/build-html.ts @@ -2,7 +2,7 @@ import Bluebird from "bluebird" import fs from "fs-extra" import reporter from "gatsby-cli/lib/reporter" import { createErrorFromString } from "gatsby-cli/lib/reporter/errors" -import { chunk } from "lodash" +import { chunk } from "es-toolkit/compat" import { build, watch } from "../utils/webpack/bundle" import * as path from "path" import fastq from "fastq" diff --git a/packages/gatsby/src/datastore/common/query.ts b/packages/gatsby/src/datastore/common/query.ts index aef62565bfde9..8e68e841b7894 100644 --- a/packages/gatsby/src/datastore/common/query.ts +++ b/packages/gatsby/src/datastore/common/query.ts @@ -1,4 +1,4 @@ -import * as _ from "lodash" +import * as _ from "es-toolkit/compat" import { prepareRegex } from "../../utils/prepare-regex" import { makeRe } from "micromatch" diff --git a/packages/gatsby/src/datastore/in-memory/indexing.ts b/packages/gatsby/src/datastore/in-memory/indexing.ts index 2a690b96d3db3..0ea3d5757a294 100644 --- a/packages/gatsby/src/datastore/in-memory/indexing.ts +++ b/packages/gatsby/src/datastore/in-memory/indexing.ts @@ -6,7 +6,7 @@ import { objectToDottedField, } from "../common/query" import { getDataStore, getNode } from "../" -import _ from "lodash" +import { every } from "es-toolkit/compat" import { getValueAt } from "../../utils/get-value-at" import { getResolvedFields } from "../../schema/utils" @@ -63,7 +63,7 @@ export const getGatsbyNodePartial = ( // now check if we have it in memory and it has all the fields we need if ( derefPartial && - _.every( + every( indexFields.map(field => derefPartial!.gatsbyNodePartialInternalData.indexFields.has(field) ) diff --git a/packages/gatsby/src/datastore/in-memory/run-fast-filters.ts b/packages/gatsby/src/datastore/in-memory/run-fast-filters.ts index 23605f9896c9d..dc16adc623a20 100644 --- a/packages/gatsby/src/datastore/in-memory/run-fast-filters.ts +++ b/packages/gatsby/src/datastore/in-memory/run-fast-filters.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { orderBy } from "es-toolkit/compat" import { DbQuery, IDbQueryQuery, @@ -457,5 +457,5 @@ function sortNodes( }) } - return _.orderBy(nodes, sortFns, sortOrder) + return orderBy(nodes, sortFns, sortOrder) } diff --git a/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts b/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts index 910303d030de5..d3ae4e036e27f 100644 --- a/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts +++ b/packages/gatsby/src/internal-plugins/functions/gatsby-node.ts @@ -2,7 +2,7 @@ import fs from "fs-extra" import glob from "glob" import path from "path" import webpack from "webpack" -import _ from "lodash" +import { union, kebabCase, unionBy } from "es-toolkit/compat" import { getMatchPath, urlResolve } from "gatsby-core-utils" import { CreateDevServerArgs, ParentSpanPluginArgs } from "gatsby" import formatWebpackMessages from "react-dev-utils/formatWebpackMessages" @@ -121,7 +121,7 @@ const createGlobArray = (siteDirectoryPath, plugins): Array => { }) // Only return unique paths - return _.union(globs) + return union(globs) } async function globAsync( @@ -178,7 +178,7 @@ const createWebpackConfig = async ({ const finalName = urlResolve(dir, name === `index` ? `` : name) // functionId should have only alphanumeric characters and dashes - const functionIdBase = _.kebabCase(compiledFunctionName).replace( + const functionIdBase = kebabCase(compiledFunctionName).replace( /[^a-zA-Z0-9-]/g, `-` ) @@ -212,7 +212,7 @@ const createWebpackConfig = async ({ // Combine functions by the route name so that functions in the default // functions directory can override the plugin's implementations. // @ts-ignore - Seems like a TS bug: https://github.com/microsoft/TypeScript/issues/28010#issuecomment-713484584 - const knownFunctions = _.unionBy(...allFunctions, func => func.functionRoute) + const knownFunctions = unionBy(...allFunctions, func => func.functionRoute) store.dispatch(internalActions.setFunctions(knownFunctions)) diff --git a/packages/gatsby/src/query/graphql-errors.js b/packages/gatsby/src/query/graphql-errors.js index 19a486e216d6c..580cf551a8a32 100644 --- a/packages/gatsby/src/query/graphql-errors.js +++ b/packages/gatsby/src/query/graphql-errors.js @@ -4,7 +4,7 @@ const fs = require(`fs-extra`) import { print, visit, getLocation } from "graphql" import { codeFrameColumns } from "@babel/code-frame" const { distance: levenshtein } = require(`fastest-levenshtein`) -import _ from "lodash" +import { camelCase, upperFirst } from "es-toolkit/compat" import report from "gatsby-cli/lib/reporter" const { locInGraphQlToLocInFile } = require(`./error-parser`) import { getCodeFrame } from "./graphql-errors-codeframe" @@ -118,9 +118,7 @@ export function multipleRootQueriesError( const otherName = otherDef.name.value const field = def.selectionSet.selections[0].name.value const otherField = otherDef.selectionSet.selections[0].name.value - const unifiedName = `${_.camelCase(name)}And${_.upperFirst( - _.camelCase(otherName) - )}` + const unifiedName = `${camelCase(name)}And${upperFirst(camelCase(otherName))}` // colors are problematic for tests as we can different // results depending on platform, so we don't diff --git a/packages/gatsby/src/query/graphql-runner.ts b/packages/gatsby/src/query/graphql-runner.ts index 5a42e989c31eb..2b69dc4608ccf 100644 --- a/packages/gatsby/src/query/graphql-runner.ts +++ b/packages/gatsby/src/query/graphql-runner.ts @@ -11,7 +11,7 @@ import { NoDeprecatedCustomRule, print, } from "graphql" -import { debounce } from "lodash" +import { debounce } from "es-toolkit/compat" import reporter from "gatsby-cli/lib/reporter" import { sha1 } from "gatsby-core-utils/hash" diff --git a/packages/gatsby/src/query/index.ts b/packages/gatsby/src/query/index.ts index a4924bc3a9bbf..64e87de78e88b 100644 --- a/packages/gatsby/src/query/index.ts +++ b/packages/gatsby/src/query/index.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { groupBy } from "es-toolkit/compat" import fastq from "fastq" import { IProgressReporter } from "gatsby-cli/lib/reporter/reporter-progress" import { store } from "../redux" @@ -58,7 +58,7 @@ export { calcDirtyQueryIds as calcInitialDirtyQueryIds } * Groups queryIds by whether they are static or page queries. */ export function groupQueryIds(queryIds: Array): IGroupedQueryIds { - const grouped = _.groupBy(queryIds, p => { + const grouped = groupBy(queryIds, p => { if (p.startsWith(`sq--`)) { return `static` } else if (p.startsWith(`slice--`)) { diff --git a/packages/gatsby/src/query/query-runner.ts b/packages/gatsby/src/query/query-runner.ts index 5bd88552af66c..77af70ed68182 100644 --- a/packages/gatsby/src/query/query-runner.ts +++ b/packages/gatsby/src/query/query-runner.ts @@ -1,5 +1,4 @@ import { Span } from "opentracing" -import _ from "lodash" import fs from "fs-extra" import report from "gatsby-cli/lib/reporter" import { ExecutionResult, GraphQLError } from "graphql" diff --git a/packages/gatsby/src/redux/actions/restricted.ts b/packages/gatsby/src/redux/actions/restricted.ts index c076e766b35c2..aa541c01c9a2c 100644 --- a/packages/gatsby/src/redux/actions/restricted.ts +++ b/packages/gatsby/src/redux/actions/restricted.ts @@ -1,5 +1,4 @@ -import camelCase from "lodash/camelCase" -import isEqual from "lodash/isEqual" +import { camelCase, isEqual } from "es-toolkit/compat" import { GraphQLSchema, GraphQLOutputType } from "graphql" import { ActionCreator } from "redux" diff --git a/packages/gatsby/src/redux/index.ts b/packages/gatsby/src/redux/index.ts index b05b6cce1ebf6..1946432480f8e 100644 --- a/packages/gatsby/src/redux/index.ts +++ b/packages/gatsby/src/redux/index.ts @@ -7,7 +7,7 @@ import { ReducersMapObject, Store, } from "redux" -import _ from "lodash" +import { pick } from "es-toolkit/compat" import { mett } from "../utils/mett" import thunk, { ThunkMiddleware, ThunkAction, ThunkDispatch } from "redux-thunk" @@ -140,7 +140,7 @@ export const saveState = (): void => { const state = store.getState() - const sliceOfStateToPersist = _.pick(state, persistedReduxKeys) + const sliceOfStateToPersist = pick(state, persistedReduxKeys) return writeToCache(sliceOfStateToPersist) } @@ -151,7 +151,7 @@ export const savePartialStateToDisk = ( transformState?: >(state: T) => T ): void => { const state = store.getState() - const contents = _.pick(state, slices) + const contents = pick(state, slices) const savedContents = transformState ? transformState(contents) : contents return writeToCache(savedContents, slices, optionalPrefix) diff --git a/packages/gatsby/src/redux/reducers/__tests__/queries.ts b/packages/gatsby/src/redux/reducers/__tests__/queries.ts index bf025a85d6152..c9bfa004e5b7a 100644 --- a/packages/gatsby/src/redux/reducers/__tests__/queries.ts +++ b/packages/gatsby/src/redux/reducers/__tests__/queries.ts @@ -25,7 +25,7 @@ import { IQueryStartAction, } from "../../types" -import { cloneDeep } from "lodash" +import { cloneDeep } from "es-toolkit/compat" type QueriesState = IGatsbyState["queries"] diff --git a/packages/gatsby/src/redux/reducers/babelrc.ts b/packages/gatsby/src/redux/reducers/babelrc.ts index f6dfb704549b0..c234c4196253f 100644 --- a/packages/gatsby/src/redux/reducers/babelrc.ts +++ b/packages/gatsby/src/redux/reducers/babelrc.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { findIndex, merge } from "es-toolkit/compat" import { IGatsbyState, ActionsUnion, IPlugin } from "../types" @@ -48,7 +48,7 @@ export const babelrcReducer = ( return } - const index = _.findIndex( + const index = findIndex( state.stages[stage].plugins, (plugin: IPlugin) => plugin.name === action.payload.name ) @@ -58,7 +58,7 @@ export const babelrcReducer = ( const plugin = state.stages[stage].plugins[index] state.stages[stage].plugins[index] = { name: plugin.name, - options: _.merge(plugin.options, action.payload.options), + options: merge(plugin.options, action.payload.options), } } else { state.stages[stage].plugins = [ @@ -76,7 +76,7 @@ export const babelrcReducer = ( return } - const index = _.findIndex( + const index = findIndex( state.stages[stage].presets, (plugin: IPlugin) => plugin.name === action.payload.name ) @@ -86,7 +86,7 @@ export const babelrcReducer = ( const plugin = state.stages[stage].presets[index] state.stages[stage].presets[index] = { name: plugin.name, - options: _.merge(plugin.options, action.payload.options), + options: merge(plugin.options, action.payload.options), } } else { state.stages[stage].presets = [ diff --git a/packages/gatsby/src/redux/reducers/inference-metadata.ts b/packages/gatsby/src/redux/reducers/inference-metadata.ts index 014acb6ba95eb..6cc3296c8983e 100644 --- a/packages/gatsby/src/redux/reducers/inference-metadata.ts +++ b/packages/gatsby/src/redux/reducers/inference-metadata.ts @@ -1,6 +1,6 @@ // Tracking structure of nodes to utilize this metadata for schema inference // Type descriptors stay relevant at any point in time making incremental inference trivial -import { omit } from "lodash" +import { omit } from "es-toolkit/compat" import { addNode, addNodes, diff --git a/packages/gatsby/src/redux/reducers/jobs.ts b/packages/gatsby/src/redux/reducers/jobs.ts index 385748fbe623e..07e035fd6edae 100644 --- a/packages/gatsby/src/redux/reducers/jobs.ts +++ b/packages/gatsby/src/redux/reducers/jobs.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { findIndex, merge, get } from "es-toolkit/compat" import { oneLine } from "common-tags" import moment from "moment" @@ -14,9 +14,9 @@ export const jobsReducer = ( if (!action.payload.id) { throw new Error(`An ID must be provided when creating or setting job`) } - const index = _.findIndex(state.active, j => j.id === action.payload.id) + const index = findIndex(state.active, j => j.id === action.payload.id) if (index !== -1) { - const mergedJob = _.merge(state.active[index], { + const mergedJob = merge(state.active[index], { ...action.payload, createdAt: Date.now(), plugin: action.plugin, @@ -38,10 +38,10 @@ export const jobsReducer = ( throw new Error(`An ID must be provided when ending a job`) } const completedAt = Date.now() - const index = _.findIndex(state.active, j => j.id === action.payload.id) + const index = findIndex(state.active, j => j.id === action.payload.id) if (index === -1) { throw new Error(oneLine` - The plugin "${_.get(action, `plugin.name`, `anonymous`)}" + The plugin "${get(action, `plugin.name`, `anonymous`)}" tried to end a job with the id "${action.payload.id}" that either hasn't yet been created or has already been ended`) } diff --git a/packages/gatsby/src/redux/reducers/redirects.ts b/packages/gatsby/src/redux/reducers/redirects.ts index f77a17d4de2e8..0e8448ba454b4 100644 --- a/packages/gatsby/src/redux/reducers/redirects.ts +++ b/packages/gatsby/src/redux/reducers/redirects.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { isEqual } from "es-toolkit/compat" import { IGatsbyState, IRedirect, ICreateRedirectAction } from "../types" const redirects = new Map>() @@ -8,7 +8,7 @@ function exists(newRedirect: IRedirect): boolean { if (!fromPathRedirects) return false - return fromPathRedirects.some(redirect => _.isEqual(redirect, newRedirect)) + return fromPathRedirects.some(redirect => isEqual(redirect, newRedirect)) } function add(redirect: IRedirect): void { diff --git a/packages/gatsby/src/redux/reducers/resolved-nodes.ts b/packages/gatsby/src/redux/reducers/resolved-nodes.ts index 790e488107870..ef2f7fde780ff 100644 --- a/packages/gatsby/src/redux/reducers/resolved-nodes.ts +++ b/packages/gatsby/src/redux/reducers/resolved-nodes.ts @@ -1,4 +1,4 @@ -import merge from "lodash/merge" +import { merge } from "es-toolkit/compat" import { IGatsbyState, ActionsUnion } from "../types" export const resolvedNodesCacheReducer = ( diff --git a/packages/gatsby/src/redux/reducers/status.ts b/packages/gatsby/src/redux/reducers/status.ts index 43c86a9639a71..f686cdcd1b292 100644 --- a/packages/gatsby/src/redux/reducers/status.ts +++ b/packages/gatsby/src/redux/reducers/status.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { isObject, merge } from "es-toolkit/compat" import { uuid } from "gatsby-core-utils" import { ActionsUnion, IGatsbyState } from "../types" @@ -34,7 +34,7 @@ export const statusReducer = ( if (!action.plugin || !action.plugin?.name) { throw new Error(`You can't set plugin status without a plugin`) } - if (!_.isObject(action.payload)) { + if (!isObject(action.payload)) { throw new Error( `You must pass an object into setPluginStatus. What was passed in was ${JSON.stringify( action.payload, @@ -47,7 +47,7 @@ export const statusReducer = ( ...state, plugins: { ...state.plugins, - [action.plugin.name]: _.merge( + [action.plugin.name]: merge( {}, state.plugins[action.plugin.name], action.payload diff --git a/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts b/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts index 3d62aec86bb15..cb647aad25820 100644 --- a/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts +++ b/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts @@ -17,7 +17,7 @@ import * as nodeApis from "../../utils/api-node-docs" import { store } from "../../redux" import { PackageJson } from "../../.." import { slash } from "gatsby-core-utils/path" -import { isEqual } from "lodash" +import { isEqual } from "es-toolkit/compat" import { IPlatformAndArch, getCurrentPlatformAndTarget, diff --git a/packages/gatsby/src/schema/graphql-engine/print-plugins.ts b/packages/gatsby/src/schema/graphql-engine/print-plugins.ts index 568837aeca615..d41a6e729513b 100644 --- a/packages/gatsby/src/schema/graphql-engine/print-plugins.ts +++ b/packages/gatsby/src/schema/graphql-engine/print-plugins.ts @@ -1,7 +1,7 @@ /* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */ import * as fs from "fs-extra" import * as path from "path" -import * as _ from "lodash" +import * as _ from "es-toolkit/compat" import { slash } from "gatsby-core-utils" import { store } from "../../redux" import { IGatsbyState } from "../../redux/types" diff --git a/packages/gatsby/src/schema/infer/__tests__/inference-metadata.ts b/packages/gatsby/src/schema/infer/__tests__/inference-metadata.ts index 31c34ad10ea36..798ec3d1f2969 100644 --- a/packages/gatsby/src/schema/infer/__tests__/inference-metadata.ts +++ b/packages/gatsby/src/schema/infer/__tests__/inference-metadata.ts @@ -1,5 +1,5 @@ // NOTE: Previously `data-tree-utils-test.js` -import _ from "lodash" +import { cloneDeep } from "es-toolkit/compat" import { addNode, @@ -1057,12 +1057,12 @@ describe(`Type change detection`, () => { const addOne = ( node: Record, metadata: ITypeMetadata = initialMetadata - ): ITypeMetadata => addNode(_.cloneDeep(metadata), node as Node) + ): ITypeMetadata => addNode(cloneDeep(metadata), node as Node) const deleteOne = ( node: Record, metadata = initialMetadata - ): ITypeMetadata => deleteNode(_.cloneDeep(metadata), node as Node) + ): ITypeMetadata => deleteNode(cloneDeep(metadata), node as Node) beforeEach(() => { initialMetadata = addNodes(undefined, nodes() as Array) diff --git a/packages/gatsby/src/schema/infer/build-example-data.ts b/packages/gatsby/src/schema/infer/build-example-data.ts index 22179149d01d6..641fad5482408 100644 --- a/packages/gatsby/src/schema/infer/build-example-data.ts +++ b/packages/gatsby/src/schema/infer/build-example-data.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-use-before-define */ -import { groupBy } from "lodash" +import { groupBy } from "es-toolkit/compat" import { IValueDescriptor, ValueType, diff --git a/packages/gatsby/src/schema/infer/inference-metadata.ts b/packages/gatsby/src/schema/infer/inference-metadata.ts index 68a2175254038..5027d179e8906 100644 --- a/packages/gatsby/src/schema/infer/inference-metadata.ts +++ b/packages/gatsby/src/schema/infer/inference-metadata.ts @@ -57,7 +57,7 @@ of fields in the node object (including nested fields) (still rare edge cases possible when reporting may be confusing, i.e. when node is deleted) */ -import { isEqual } from "lodash" +import { isEqual } from "es-toolkit/compat" import { is32BitInteger } from "../../utils/is-32-bit-integer" import { looksLikeADate } from "../types/date" import { Node } from "../../../index" diff --git a/packages/gatsby/src/schema/infer/type-conflict-reporter.ts b/packages/gatsby/src/schema/infer/type-conflict-reporter.ts index af54563176319..40a0081462241 100644 --- a/packages/gatsby/src/schema/infer/type-conflict-reporter.ts +++ b/packages/gatsby/src/schema/infer/type-conflict-reporter.ts @@ -1,4 +1,4 @@ -import sortBy from "lodash/sortBy" +import { sortBy } from "es-toolkit/compat" import report from "gatsby-cli/lib/reporter" import typeOf from "type-of" import util from "util" diff --git a/packages/gatsby/src/schema/print.ts b/packages/gatsby/src/schema/print.ts index 7d1c38caba18d..3a0d83e5ccefa 100644 --- a/packages/gatsby/src/schema/print.ts +++ b/packages/gatsby/src/schema/print.ts @@ -26,7 +26,7 @@ import { } from "graphql" import { printBlockString } from "graphql/language/blockString" import { internalExtensionNames } from "./extensions" -import _ from "lodash" +import { flatMap, omit } from "es-toolkit/compat" import { internalTypeNames } from "./types/built-in-types" export interface ISchemaPrintConfig { @@ -60,7 +60,7 @@ const descriptionLines = ( maxLen: number ): Array => { const rawLines = description.split(`\n`) - return _.flatMap(rawLines, line => { + return flatMap(rawLines, line => { if (line.length < maxLen + 5) { return line } @@ -237,7 +237,7 @@ const printObjectType = (tc: ObjectTypeComposer): string => { let fields = tc.getFields() if (tc.hasInterface(`Node`)) { extensions.dontInfer = null - fields = _.omit(fields, [`id`, `parent`, `children`, `internal`]) + fields = omit(fields, [`id`, `parent`, `children`, `internal`]) } const directives = tc.schemaComposer.getDirectives() const printedDirectives = printDirectives(extensions, directives) diff --git a/packages/gatsby/src/schema/utils.ts b/packages/gatsby/src/schema/utils.ts index 02fb76a1407b1..729b763d89a6f 100644 --- a/packages/gatsby/src/schema/utils.ts +++ b/packages/gatsby/src/schema/utils.ts @@ -14,7 +14,7 @@ import { ObjectTypeComposer, SchemaComposer, } from "graphql-compose" -import isPlainObject from "lodash/isPlainObject" +import { isPlainObject } from "es-toolkit/compat" import type { IGatsbyNodePartial } from "../datastore/in-memory/indexing" import { IGatsbyNode } from "../internal" diff --git a/packages/gatsby/src/services/initialize.ts b/packages/gatsby/src/services/initialize.ts index 2144be3620eb1..1423df71a2a9c 100644 --- a/packages/gatsby/src/services/initialize.ts +++ b/packages/gatsby/src/services/initialize.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { flattenDeep } from "es-toolkit/compat" import { slash, isCI } from "gatsby-core-utils" import * as fs from "fs-extra" import { releaseAllMutexes } from "gatsby-core-utils/mutex" @@ -617,7 +617,7 @@ export async function initialize({ store.dispatch({ type: `SET_PROGRAM_EXTENSIONS`, - payload: _.flattenDeep([extensions, apiResults]), + payload: flattenDeep([extensions, apiResults]), }) const workerPool = WorkerPool.create() diff --git a/packages/gatsby/src/utils/__tests__/handle-flags.ts b/packages/gatsby/src/utils/__tests__/handle-flags.ts index 1990d79f54551..8e2e3971d4e7c 100644 --- a/packages/gatsby/src/utils/__tests__/handle-flags.ts +++ b/packages/gatsby/src/utils/__tests__/handle-flags.ts @@ -1,5 +1,3 @@ -import _ from "lodash" - import handleFlags from "../handle-flags" import { IFlag, satisfiesSemvers, fitnessEnum } from "../flags" diff --git a/packages/gatsby/src/utils/adapter/init.ts b/packages/gatsby/src/utils/adapter/init.ts index 0afab63c2f5e2..a832d7f42325a 100644 --- a/packages/gatsby/src/utils/adapter/init.ts +++ b/packages/gatsby/src/utils/adapter/init.ts @@ -1,5 +1,4 @@ import reporter from "gatsby-cli/lib/reporter" -import _ from "lodash" import { createRequireFromPath } from "gatsby-core-utils/create-require-from-path" import { join } from "path" import { emptyDir, ensureDir, outputJson } from "fs-extra" diff --git a/packages/gatsby/src/utils/babel-loader-helpers.ts b/packages/gatsby/src/utils/babel-loader-helpers.ts index 67a670b4bcf43..63098429c7a95 100644 --- a/packages/gatsby/src/utils/babel-loader-helpers.ts +++ b/packages/gatsby/src/utils/babel-loader-helpers.ts @@ -1,5 +1,5 @@ import path from "path" -import _ from "lodash" +import { findIndex, merge } from "es-toolkit/compat" import Babel, { ConfigItem, PluginItem, @@ -233,7 +233,7 @@ export const mergeConfigItemOptions = ({ type: CreateConfigItemOptions["type"] babel: typeof Babel }): Array => { - const index = _.findIndex( + const index = findIndex( items, i => i.file?.resolved === itemToMerge.file?.resolved ) @@ -243,7 +243,7 @@ export const mergeConfigItemOptions = ({ items[index] = babel.createConfigItem( [ itemToMerge.file?.resolved, - _.merge({}, items[index].options, itemToMerge.options), + merge({}, items[index].options, itemToMerge.options), ], { type, diff --git a/packages/gatsby/src/utils/changed-pages.ts b/packages/gatsby/src/utils/changed-pages.ts index 9a6f4c327f913..e71c0e3780f88 100644 --- a/packages/gatsby/src/utils/changed-pages.ts +++ b/packages/gatsby/src/utils/changed-pages.ts @@ -1,9 +1,9 @@ import { actions } from "../redux/actions" import { store } from "../redux" const { deletePage } = actions -import { isEqualWith } from "lodash" +import { isEqualWith } from "es-toolkit/compat" import { IGatsbyPage } from "../redux/types" -import type { IsEqualCustomizer } from "lodash" +import type { IsEqualCustomizer } from "es-toolkit/compat" export function deleteUntouchedPages( currentPages: Map, diff --git a/packages/gatsby/src/utils/flags.ts b/packages/gatsby/src/utils/flags.ts index 0ff2d98ce6893..9eab65d194bbb 100644 --- a/packages/gatsby/src/utils/flags.ts +++ b/packages/gatsby/src/utils/flags.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { toPairs } from "es-toolkit/compat" import semver from "semver" // Does this experiment run for only builds @@ -9,7 +9,7 @@ export const satisfiesSemvers = ( ): boolean => { // Check each semver check for the flag. // If any are false, then the flag doesn't pass - const result = _.toPairs(semverConstraints).every( + const result = toPairs(semverConstraints).every( ([packageName, semverConstraint]) => { let packageVersion: string try { diff --git a/packages/gatsby/src/utils/gatsby-dependents.ts b/packages/gatsby/src/utils/gatsby-dependents.ts index f353bbf5a1271..7c23f5c250921 100644 --- a/packages/gatsby/src/utils/gatsby-dependents.ts +++ b/packages/gatsby/src/utils/gatsby-dependents.ts @@ -1,5 +1,5 @@ import { store } from "../redux" -import { memoize } from "lodash" +import { memoize } from "es-toolkit/compat" import { createRequireFromPath } from "gatsby-core-utils" import { join, dirname } from "path" diff --git a/packages/gatsby/src/utils/graphql-typegen/utils.ts b/packages/gatsby/src/utils/graphql-typegen/utils.ts index 517af218c6a96..9290f28ee3201 100644 --- a/packages/gatsby/src/utils/graphql-typegen/utils.ts +++ b/packages/gatsby/src/utils/graphql-typegen/utils.ts @@ -1,5 +1,5 @@ import slugify from "slugify" -import _ from "lodash" +import { camelCase } from "es-toolkit/compat" import { lexicographicSortSchema } from "graphql" import type { GraphQLSchema } from "graphql" import { IDefinitionMeta } from "../../redux/types" @@ -36,7 +36,7 @@ function guessIfUnnnamedQuery({ replacement: ` `, lower: false, }) - const pattern = _.camelCase(`${queryType}-${generatedQueryName}`) + const pattern = camelCase(`${queryType}-${generatedQueryName}`) return name.startsWith(pattern) } diff --git a/packages/gatsby/src/utils/handle-flags.ts b/packages/gatsby/src/utils/handle-flags.ts index d4022339e5ca6..9c067f124722b 100644 --- a/packages/gatsby/src/utils/handle-flags.ts +++ b/packages/gatsby/src/utils/handle-flags.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { uniq } from "es-toolkit/compat" import { isCI } from "gatsby-core-utils" import { IFlag } from "./flags" import chalk from "chalk" @@ -156,7 +156,7 @@ const handleFlags = ( addIncluded(flag) }) - enabledConfigFlags = _.uniq(enabledConfigFlags) + enabledConfigFlags = uniq(enabledConfigFlags) // TODO remove flags that longer exist. // w/ message of thanks diff --git a/packages/gatsby/src/utils/jobs/manager.ts b/packages/gatsby/src/utils/jobs/manager.ts index 20ecb52773d89..337f69710a653 100644 --- a/packages/gatsby/src/utils/jobs/manager.ts +++ b/packages/gatsby/src/utils/jobs/manager.ts @@ -2,7 +2,7 @@ import path from "path" import hasha from "hasha" import fs from "fs-extra" import pDefer from "p-defer" -import _ from "lodash" +import { isPlainObject } from "es-toolkit/compat" import { createContentDigest, slash, uuid } from "gatsby-core-utils" import reporter from "gatsby-cli/lib/reporter" import { IPhantomReporter } from "gatsby-cli" @@ -302,7 +302,7 @@ export async function enqueueJob( try { const result = await runJob(job) // this check is to keep our worker results consistent for cloud - if (result != null && !_.isPlainObject(result)) { + if (result != null && !isPlainObject(result)) { throw new Error( `Result of a worker should be an object, type of "${typeof result}" was given` ) diff --git a/packages/gatsby/src/utils/js-chunk-names.ts b/packages/gatsby/src/utils/js-chunk-names.ts index b92569c876c83..ee9025ecc3bd9 100644 --- a/packages/gatsby/src/utils/js-chunk-names.ts +++ b/packages/gatsby/src/utils/js-chunk-names.ts @@ -1,5 +1,5 @@ import memoize from "memoizee" -import { kebabCase as _kebabCase } from "lodash" +import { kebabCase as _kebabCase } from "es-toolkit/compat" import { murmurhash as _murmurhash } from "gatsby-core-utils/murmurhash" import path from "path" import { store } from "../redux" diff --git a/packages/gatsby/src/utils/merge-gatsby-config.ts b/packages/gatsby/src/utils/merge-gatsby-config.ts index cd755e45c26ea..378e080d6695c 100644 --- a/packages/gatsby/src/utils/merge-gatsby-config.ts +++ b/packages/gatsby/src/utils/merge-gatsby-config.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { merge, uniq } from "es-toolkit/compat" import { Express } from "express" import type { TrailingSlash } from "gatsby-page-utils" @@ -39,13 +39,13 @@ const howToMerge = { */ byDefault: (a: ConfigKey, b: ConfigKey): ConfigKey => b || a, siteMetadata: (objA: Metadata, objB: Metadata): Metadata => - _.merge({}, objA, objB), + merge({}, objA, objB), // plugins are concatenated and uniq'd, so we don't get two of the same plugin value plugins: ( a: Array = [], b: Array = [] ): Array => a.concat(b), - mapping: (objA: Mapping, objB: Mapping): Mapping => _.merge({}, objA, objB), + mapping: (objA: Mapping, objB: Mapping): Mapping => merge({}, objA, objB), } as const /** @@ -56,7 +56,7 @@ export const mergeGatsbyConfig = ( b: IGatsbyConfigInput ): IGatsbyConfigInput => { // a and b are gatsby configs, If they have keys, that means there are values to merge - const allGatsbyConfigKeysWithAValue = _.uniq( + const allGatsbyConfigKeysWithAValue = uniq( Object.keys(a).concat(Object.keys(b)) ) as Array diff --git a/packages/gatsby/src/utils/prepare-regex.ts b/packages/gatsby/src/utils/prepare-regex.ts index 3f493184c1f53..fdf8d6a80cfb8 100644 --- a/packages/gatsby/src/utils/prepare-regex.ts +++ b/packages/gatsby/src/utils/prepare-regex.ts @@ -1,7 +1,7 @@ -import _ from "lodash" +import { last } from "es-toolkit/compat" export const prepareRegex = (str: string): RegExp => { const exploded = str.split(`/`) - const regex = new RegExp(exploded.slice(1, -1).join(`/`), _.last(exploded)) + const regex = new RegExp(exploded.slice(1, -1).join(`/`), last(exploded)) return regex } diff --git a/packages/gatsby/src/utils/sanitize-node.ts b/packages/gatsby/src/utils/sanitize-node.ts index a92504a4cb0f4..4dbb9e5567991 100644 --- a/packages/gatsby/src/utils/sanitize-node.ts +++ b/packages/gatsby/src/utils/sanitize-node.ts @@ -1,4 +1,4 @@ -import _ from "lodash" +import { isPlainObject, pickBy, isArray, each } from "es-toolkit/compat" import type { IGatsbyNode } from "../redux/types" import type { GatsbyIterable } from "../datastore/common/iterable" @@ -12,9 +12,9 @@ type OmitUndefined = (data: Data) => Partial * @returns {Object|Array} data without undefined values */ const omitUndefined: OmitUndefined = data => { - const isPlainObject = _.isPlainObject(data) - if (isPlainObject) { - return _.pickBy(data, p => p !== undefined) + const isPlainObjectCheck = isPlainObject(data) + if (isPlainObjectCheck) { + return pickBy(data, p => p !== undefined) } return (data as GatsbyIterable).filter(p => p !== undefined) @@ -58,20 +58,20 @@ export const sanitizeNode: sanitizeNode = ( isNode = true, path = new Set() ) => { - const isPlainObject = _.isPlainObject(data) - const isArray = _.isArray(data) + const isPlainObjectCheck = isPlainObject(data) + const isArrayCheck = isArray(data) - if (isPlainObject || isArray) { + if (isPlainObjectCheck || isArrayCheck) { if (path.has(data)) return data path.add(data) - const returnData = isPlainObject + const returnData = isPlainObjectCheck ? ({} as IGatsbyNode) : ([] as Array) let anyFieldChanged = false - // _.each is a "Collection" method and thus objects with "length" property are iterated as arrays - const hasLengthProperty = isPlainObject + // each is a "Collection" method and thus objects with "length" property are iterated as arrays + const hasLengthProperty = isPlainObjectCheck ? Object.prototype.hasOwnProperty.call(data, `length`) : false let lengthProperty @@ -80,7 +80,7 @@ export const sanitizeNode: sanitizeNode = ( delete (data as IGatsbyNode).length } - _.each(data, (value, key) => { + each(data, (value, key) => { if (isNode && key === `internal`) { returnData[key] = value return diff --git a/packages/gatsby/src/utils/validate-engines/index.ts b/packages/gatsby/src/utils/validate-engines/index.ts index 50f3a8b3f8b43..bae271914dc04 100644 --- a/packages/gatsby/src/utils/validate-engines/index.ts +++ b/packages/gatsby/src/utils/validate-engines/index.ts @@ -1,6 +1,6 @@ import reporter from "gatsby-cli/lib/reporter" import { WorkerPool } from "gatsby-worker" -import { isEqual } from "lodash" +import { isEqual } from "es-toolkit/compat" import type { Span } from "opentracing" import { getCurrentPlatformAndTarget, diff --git a/packages/gatsby/src/utils/webpack/plugins/static-query-mapper.ts b/packages/gatsby/src/utils/webpack/plugins/static-query-mapper.ts index 559f20375656c..ef750fff8c12a 100644 --- a/packages/gatsby/src/utils/webpack/plugins/static-query-mapper.ts +++ b/packages/gatsby/src/utils/webpack/plugins/static-query-mapper.ts @@ -1,7 +1,7 @@ import path from "path" import { Store } from "redux" import { Compiler, NormalModule } from "webpack" -import { isEqual, cloneDeep } from "lodash" +import { isEqual, cloneDeep } from "es-toolkit/compat" import { enqueueFlush } from "../../page-data" import type { IGatsbyState, IGatsbyPageComponent } from "../../../redux/types" import { diff --git a/packages/gatsby/src/utils/worker/pool.ts b/packages/gatsby/src/utils/worker/pool.ts index a32b3392b1916..7862e85957274 100644 --- a/packages/gatsby/src/utils/worker/pool.ts +++ b/packages/gatsby/src/utils/worker/pool.ts @@ -1,5 +1,5 @@ import { WorkerPool } from "gatsby-worker" -import { chunk } from "lodash" +import { chunk } from "es-toolkit/compat" import reporter from "gatsby-cli/lib/reporter" import { cpuCoreCount } from "gatsby-core-utils" import { Span } from "opentracing" From 95df648290f37b22b4577cbb65383a4e1cba3b62 Mon Sep 17 00:00:00 2001 From: evan-moon Date: Fri, 8 Aug 2025 13:13:06 +0900 Subject: [PATCH 2/2] chore(gatsby): update yarn.lock --- yarn.lock | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/yarn.lock b/yarn.lock index f7f360db2c3b9..df5885138c0cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10629,6 +10629,11 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" +es-toolkit@^1.30.0: + version "1.39.8" + resolved "https://registry.yarnpkg.com/es-toolkit/-/es-toolkit-1.39.8.tgz#314aca3988fc1f2c3faa95b49c3029f44c690f50" + integrity sha512-A8QO9TfF+rltS8BXpdu8OS+rpGgEdnRhqIVxO/ZmNvnXBYgOdSsxukT55ELyP94gZIntWJ+Li9QRrT2u1Kitpg== + es5-ext@^0.10.35, es5-ext@^0.10.46, es5-ext@^0.10.50, es5-ext@^0.10.53, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.46: version "0.10.53" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.53.tgz#93c5a3acfdbef275220ad72644ad02ee18368de1"