Skip to content

Commit 1aa7b4f

Browse files
committed
refactor(dev): replace lodash
1 parent 3d76762 commit 1aa7b4f

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import fs from "node:fs";
22
import { execSync } from "node:child_process";
33
import PackageJson from "@npmcli/package-json";
44
import * as ViteNode from "../vite/vite-node";
5+
import { isEqual } from "es-toolkit/predicate";
56
import type * as Vite from "vite";
67
import Path from "pathe";
78
import chokidar, {
89
type FSWatcher,
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

1714
import {
1815
type RouteManifest,
@@ -56,7 +53,11 @@ type BranchRoute = Pick<
5653

5754
export const configRouteToBranchRoute = (
5855
configRoute: RouteManifestEntry,
59-
): BranchRoute => pick(configRoute, branchRouteProperties);
56+
): BranchRoute =>
57+
branchRouteProperties.reduce(
58+
(obj, key) => ({ ...obj, [key]: configRoute[key] }),
59+
{} as BranchRoute,
60+
);
6061

6162
export type ServerBundlesFunction = (args: {
6263
branch: BranchRoute[];
@@ -389,7 +390,7 @@ async function resolveConfig({
389390
}
390391

391392
// Prevent mutations to the user config
392-
reactRouterUserConfig = deepFreeze(cloneDeep(reactRouterUserConfig));
393+
reactRouterUserConfig = deepFreeze(structuredClone(reactRouterUserConfig));
393394

394395
let presets: ReactRouterConfig[] = (
395396
await Promise.all(
@@ -404,10 +405,10 @@ async function resolveConfig({
404405
return null;
405406
}
406407

407-
let configPreset: ReactRouterConfig = omit(
408-
await preset.reactRouterConfig({ reactRouterUserConfig }),
409-
excludedConfigPresetKeys,
410-
);
408+
let configPreset: ReactRouterConfig = await preset.reactRouterConfig({
409+
reactRouterUserConfig,
410+
});
411+
excludedConfigPresetKeys.forEach((key) => delete configPreset[key]);
411412

412413
return configPreset;
413414
}),

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

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

54
import invariant from "../invariant";
65

@@ -225,7 +224,10 @@ function route(
225224
file,
226225
children,
227226
path: path ?? undefined,
228-
...pick(options, createConfigRouteOptionKeys),
227+
...createConfigRouteOptionKeys.reduce(
228+
(obj, key) => ({ ...obj, [key]: options[key] }),
229+
{},
230+
),
229231
};
230232
}
231233

@@ -240,11 +242,17 @@ type CreateIndexOptions = Pick<
240242
* Helper function for creating a route config entry for an index route, for use
241243
* within `routes.ts`.
242244
*/
243-
function index(file: string, options?: CreateIndexOptions): RouteConfigEntry {
245+
function index(
246+
file: string,
247+
options: CreateIndexOptions = {},
248+
): RouteConfigEntry {
244249
return {
245250
file,
246251
index: true,
247-
...pick(options, createIndexOptionKeys),
252+
...createIndexOptionKeys.reduce(
253+
(obj, key) => ({ ...obj, [key]: options[key] }),
254+
{},
255+
),
248256
};
249257
}
250258

@@ -281,7 +289,10 @@ function layout(
281289
return {
282290
file,
283291
children,
284-
...pick(options, createLayoutOptionKeys),
292+
...createLayoutOptionKeys.reduce(
293+
(obj, key) => ({ ...obj, [key]: options[key] }),
294+
{},
295+
),
285296
};
286297
}
287298

packages/react-router-dev/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
"chokidar": "^4.0.0",
8585
"dedent": "^1.5.3",
8686
"es-module-lexer": "^1.3.1",
87+
"es-toolkit": "^1.39.8",
8788
"exit-hook": "2.2.1",
8889
"jsesc": "3.0.2",
89-
"lodash": "^4.17.21",
9090
"pathe": "^1.1.2",
9191
"picocolors": "^1.1.1",
9292
"prettier": "^3.6.2",
@@ -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/vite/plugin.ts

Lines changed: 5 additions & 3 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 "es-toolkit/string";
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";
@@ -732,7 +731,10 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
732731
let routes = routeIds
733732
? // For server bundle builds, the server build should only import the
734733
// routes for this bundle rather than importing all routes
735-
pick(ctx.reactRouterConfig.routes, routeIds)
734+
routeIds.reduce(
735+
(obj, key) => ({ ...obj, [key]: ctx.reactRouterConfig.routes[key] }),
736+
{},
737+
)
736738
: // Otherwise, all routes are imported as usual
737739
ctx.reactRouterConfig.routes;
738740

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)