Skip to content

refactor: ConfigPreset type safety and migrate lodash to es-toolkit #14111

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 4 commits 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
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- ChristophP
- christowiz
- clavery
- cksal0805
- clonemycode
- Cmoen11
- codeape2
Expand Down
20 changes: 10 additions & 10 deletions packages/react-router-dev/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ 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 { pick, omit, cloneDeep, isEqual } from "es-toolkit";

import {
type RouteManifest,
Expand Down Expand Up @@ -391,7 +388,7 @@ async function resolveConfig({
// Prevent mutations to the user config
reactRouterUserConfig = deepFreeze(cloneDeep(reactRouterUserConfig));

let presets: ReactRouterConfig[] = (
let presets: ConfigPreset[] = (
await Promise.all(
(reactRouterUserConfig.presets ?? []).map(async (preset) => {
if (!preset.name) {
Expand All @@ -404,12 +401,15 @@ async function resolveConfig({
return null;
}

let configPreset: ReactRouterConfig = omit(
await preset.reactRouterConfig({ reactRouterUserConfig }),
excludedConfigPresetKeys,
);
let reactRouterConfig = await preset.reactRouterConfig({
reactRouterUserConfig,
});

if (reactRouterConfig != null && "presets" in reactRouterConfig) {
reactRouterConfig = omit(reactRouterConfig, excludedConfigPresetKeys);
}

return configPreset;
return reactRouterConfig;
}),
)
).filter(function isNotNull<T>(value: T | null): value is T {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Path from "pathe";
import * as v from "valibot";
import pick from "lodash/pick";
import { pick } from "es-toolkit/compat";

import invariant from "../invariant";

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 @@ -87,7 +87,6 @@
"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",
Expand All @@ -106,7 +105,7 @@
"@types/dedent": "^0.7.0",
"@types/express": "^4.17.9",
"@types/jsesc": "^3.0.1",
"@types/lodash": "^4.14.182",
"es-toolkit": "^1.39.7",
"@types/node": "^20.0.0",
"@types/npmcli__package-json": "^4.0.0",
"@types/set-cookie-parser": "^2.4.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/react-router-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ import {
parse as esModuleLexer,
} from "es-module-lexer";
import { escapePath as escapePathAsGlob } from "tinyglobby";
import pick from "lodash/pick";
import { pick, kebabCase } from "es-toolkit/compat";
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 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