-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"; | ||
|
|
@@ -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, | ||
|
|
@@ -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( | ||
|
|
@@ -404,12 +402,11 @@ async function resolveConfig({ | |
| return null; | ||
| } | ||
|
|
||
| let configPreset: ReactRouterConfig = omit( | ||
| return omit( | ||
| await preset.reactRouterConfig({ reactRouterUserConfig }), | ||
| // @ts-expect-error | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what error is this suppressing? 👀
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@brophdawg11 Looking at the code, I would say we could just map to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because a yeah thats awkward. you can cast personal preference i guess, though
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Indeed.
Yeah I don't like casting, hence the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to @pcattori for type preference questions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expect-error is nice because we'll get a type error if/when we fix types for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pcattori That's indeed (one of) the reason(s) why I don't like casting. |
||
| excludedConfigPresetKeys, | ||
| ); | ||
|
|
||
| return configPreset; | ||
| }), | ||
| ) | ||
| ).filter(function isNotNull<T>(value: T | null): value is T { | ||
|
|
@@ -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({ | ||
|
|
||
| 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>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are only two uses of deepFreeze - here, and on a newly created object.
Given that deep freeze is already recursing the object, it seems like folding the cloning into that would potentially simplify things a bit (as well as saving a few cycles).