Skip to content

Commit 299545c

Browse files
committed
refactor(dev): replace lodash
1 parent bd341ff commit 299545c

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

packages/react-router-dev/config/config.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import fs from "node:fs";
21
import { execSync } from "node:child_process";
2+
import fs from "node:fs";
3+
import { isDeepStrictEqual } from "node:util";
34
import PackageJson from "@npmcli/package-json";
45
import * as ViteNode from "../vite/vite-node";
56
import type * as Vite from "vite";
@@ -9,11 +10,8 @@ import chokidar, {
910
type EmitArgs as ChokidarEmitArgs,
1011
} from "chokidar";
1112
import colors from "picocolors";
12-
import pick from "lodash/pick";
13-
import omit from "lodash/omit";
14-
import cloneDeep from "lodash/cloneDeep";
15-
import isEqual from "lodash/isEqual";
1613

14+
import { omit, pick } from "../utils";
1715
import {
1816
type RouteManifest,
1917
type RouteManifestEntry,
@@ -24,8 +22,8 @@ import {
2422
} from "./routes";
2523
import { detectPackageManager } from "../cli/detectPackageManager";
2624

27-
const excludedConfigPresetKeys = ["presets"] as const satisfies ReadonlyArray<
28-
keyof ReactRouterConfig
25+
const excludedConfigPresetKeys = ["presets"] as const satisfies Readonly<
26+
Array<keyof ReactRouterConfig>
2927
>;
3028

3129
type ExcludedConfigPresetKey = (typeof excludedConfigPresetKeys)[number];
@@ -389,7 +387,7 @@ async function resolveConfig({
389387
}
390388

391389
// Prevent mutations to the user config
392-
reactRouterUserConfig = deepFreeze(cloneDeep(reactRouterUserConfig));
390+
reactRouterUserConfig = deepFreeze(structuredClone(reactRouterUserConfig));
393391

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

407-
let configPreset: ReactRouterConfig = omit(
405+
return omit(
408406
await preset.reactRouterConfig({ reactRouterUserConfig }),
407+
// @ts-expect-error
409408
excludedConfigPresetKeys,
410409
);
411-
412-
return configPreset;
413410
}),
414411
)
415412
).filter(function isNotNull<T>(value: T | null): value is T {
@@ -775,10 +772,14 @@ export async function createConfigLoader({
775772

776773
let configChanged =
777774
result.ok &&
778-
!isEqual(omitRoutes(currentConfig), omitRoutes(result.value));
775+
!isDeepStrictEqual(
776+
omitRoutes(currentConfig),
777+
omitRoutes(result.value),
778+
);
779779

780780
let routeConfigChanged =
781-
result.ok && !isEqual(currentConfig?.routes, result.value.routes);
781+
result.ok &&
782+
!isDeepStrictEqual(currentConfig?.routes, result.value.routes);
782783

783784
for (let handler of changeHandlers) {
784785
handler({

packages/react-router-dev/config/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as Path from "pathe";
22
import * as v from "valibot";
3-
import pick from "lodash/pick";
43

54
import invariant from "../invariant";
5+
import { pick } from "../utils";
66

77
declare global {
88
var __reactRouterAppDirectory: string;
@@ -240,7 +240,7 @@ type CreateIndexOptions = Pick<
240240
* Helper function for creating a route config entry for an index route, for use
241241
* within `routes.ts`.
242242
*/
243-
function index(file: string, options?: CreateIndexOptions): RouteConfigEntry {
243+
function index(file: string, options: CreateIndexOptions): RouteConfigEntry {
244244
return {
245245
file,
246246
index: true,

packages/react-router-dev/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@
8686
"es-module-lexer": "^1.3.1",
8787
"exit-hook": "2.2.1",
8888
"jsesc": "3.0.2",
89-
"lodash": "^4.17.21",
9089
"pathe": "^1.1.2",
9190
"picocolors": "^1.1.1",
9291
"prettier": "^3.6.2",
9392
"react-refresh": "^0.14.0",
93+
"scule": "^1.3.0",
9494
"semver": "^7.3.7",
9595
"set-cookie-parser": "^2.6.0",
9696
"tinyglobby": "^0.2.14",
@@ -105,7 +105,6 @@
105105
"@types/dedent": "^0.7.0",
106106
"@types/express": "^4.17.9",
107107
"@types/jsesc": "^3.0.1",
108-
"@types/lodash": "^4.14.182",
109108
"@types/node": "^20.0.0",
110109
"@types/npmcli__package-json": "^4.0.0",
111110
"@types/set-cookie-parser": "^2.4.1",

packages/react-router-dev/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const pick = <T extends object, K extends keyof T>(
2+
obj: T,
3+
keys: readonly K[],
4+
): Pick<T, K> =>
5+
Object.fromEntries(
6+
Object.entries(obj).filter(([key]) => keys.includes(key as K)),
7+
) as Pick<T, K>;
8+
9+
export const omit = <T extends object, K extends keyof T>(
10+
obj: T,
11+
keys: readonly K[],
12+
): Omit<T, K> =>
13+
Object.fromEntries(
14+
Object.entries(obj).filter(([key]) => !keys.includes(key as K)),
15+
) as Omit<T, K>;

packages/react-router-dev/vite/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ import {
3131
init as initEsModuleLexer,
3232
parse as esModuleLexer,
3333
} from "es-module-lexer";
34+
import { kebabCase } from "scule";
3435
import { escapePath as escapePathAsGlob } from "tinyglobby";
35-
import pick from "lodash/pick";
3636
import jsesc from "jsesc";
3737
import colors from "picocolors";
38-
import kebabCase from "lodash/kebabCase";
3938

4039
import * as Typegen from "../typegen";
4140
import type { RouteManifestEntry, RouteManifest } from "../config/routes";
@@ -44,6 +43,7 @@ import type {
4443
Manifest as ReactRouterManifest,
4544
} from "../manifest";
4645
import invariant from "../invariant";
46+
import { pick } from "../utils";
4747
import type { Cache } from "./cache";
4848
import { generate, parse } from "./babel";
4949
import type { NodeRequestHandler } from "./node-adapter";

pnpm-lock.yaml

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)