Skip to content

refactor(dev): replace lodash #14180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/react-router-dev/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import { execSync } from "node:child_process";
import fs from "node:fs";
import { isDeepStrictEqual } from "node:util";
import PackageJson from "@npmcli/package-json";
import * as ViteNode from "../vite/vite-node";
import type * as Vite from "vite";
Expand All @@ -9,11 +10,8 @@ import chokidar, {
type EmitArgs as ChokidarEmitArgs,
} from "chokidar";
import colors from "picocolors";
import pick from "lodash/pick";
import omit from "lodash/omit";
import cloneDeep from "lodash/cloneDeep";
import isEqual from "lodash/isEqual";

import { omit, pick } from "../utils";
import {
type RouteManifest,
type RouteManifestEntry,
Expand Down Expand Up @@ -389,7 +387,7 @@ async function resolveConfig({
}

// Prevent mutations to the user config
reactRouterUserConfig = deepFreeze(cloneDeep(reactRouterUserConfig));
reactRouterUserConfig = deepFreeze(structuredClone(reactRouterUserConfig));

let presets: ReactRouterConfig[] = (
await Promise.all(
Expand All @@ -404,12 +402,11 @@ async function resolveConfig({
return null;
}

let configPreset: ReactRouterConfig = omit(
return omit(
await preset.reactRouterConfig({ reactRouterUserConfig }),
// @ts-expect-error
excludedConfigPresetKeys,
);

return configPreset;
}),
)
).filter(function isNotNull<T>(value: T | null): value is T {
Expand Down Expand Up @@ -775,10 +772,14 @@ export async function createConfigLoader({

let configChanged =
result.ok &&
!isEqual(omitRoutes(currentConfig), omitRoutes(result.value));
!isDeepStrictEqual(
omitRoutes(currentConfig),
omitRoutes(result.value),
);

let routeConfigChanged =
result.ok && !isEqual(currentConfig?.routes, result.value.routes);
result.ok &&
!isDeepStrictEqual(currentConfig?.routes, result.value.routes);

for (let handler of changeHandlers) {
handler({
Expand Down
7 changes: 5 additions & 2 deletions packages/react-router-dev/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Path from "pathe";
import * as v from "valibot";
import pick from "lodash/pick";

import invariant from "../invariant";
import { pick } from "../utils";

declare global {
var __reactRouterAppDirectory: string;
Expand Down Expand Up @@ -240,7 +240,10 @@ type CreateIndexOptions = Pick<
* Helper function for creating a route config entry for an index route, for use
* within `routes.ts`.
*/
function index(file: string, options?: CreateIndexOptions): RouteConfigEntry {
function index(
file: string,
options: CreateIndexOptions = {},
): RouteConfigEntry {
return {
file,
index: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-router-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
"es-module-lexer": "^1.3.1",
"exit-hook": "2.2.1",
"jsesc": "3.0.2",
"lodash": "^4.17.21",
"pathe": "^1.1.2",
"picocolors": "^1.1.1",
"prettier": "^3.6.2",
"react-refresh": "^0.14.0",
"scule": "^1.3.0",
"semver": "^7.3.7",
"set-cookie-parser": "^2.6.0",
"tinyglobby": "^0.2.14",
Expand All @@ -105,7 +105,6 @@
"@types/dedent": "^0.7.0",
"@types/express": "^4.17.9",
"@types/jsesc": "^3.0.1",
"@types/lodash": "^4.14.182",
"@types/node": "^20.0.0",
"@types/npmcli__package-json": "^4.0.0",
"@types/set-cookie-parser": "^2.4.1",
Expand Down
15 changes: 15 additions & 0 deletions packages/react-router-dev/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const pick = <T extends object, K extends keyof T>(
obj: T,
keys: readonly K[],
): Pick<T, K> =>
Object.fromEntries(
Object.entries(obj).filter(([key]) => keys.includes(key as K)),
) as Pick<T, K>;

export const omit = <T extends object, K extends keyof T>(
obj: T,
keys: readonly K[],
): Omit<T, K> =>
Object.fromEntries(
Object.entries(obj).filter(([key]) => !keys.includes(key as K)),
) as Omit<T, K>;
4 changes: 2 additions & 2 deletions packages/react-router-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ import {
init as initEsModuleLexer,
parse as esModuleLexer,
} from "es-module-lexer";
import { kebabCase } from "scule";
import { escapePath as escapePathAsGlob } from "tinyglobby";
import pick from "lodash/pick";
import jsesc from "jsesc";
import colors from "picocolors";
import kebabCase from "lodash/kebabCase";

import * as Typegen from "../typegen";
import type { RouteManifestEntry, RouteManifest } from "../config/routes";
Expand All @@ -44,6 +43,7 @@ import type {
Manifest as ReactRouterManifest,
} from "../manifest";
import invariant from "../invariant";
import { pick } from "../utils";
import type { Cache } from "./cache";
import { generate, parse } from "./babel";
import type { NodeRequestHandler } from "./node-adapter";
Expand Down
19 changes: 8 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading