fix(deps): remove lodash runtime dependency - #483
Draft
joris974 wants to merge 1 commit into
Draft
Conversation
lodash sat in `dependencies` for a single expression of shipped code.
Four usages, one of them shipped:
- `src/use-extra-deps/index.ts` (shipped): `mapValues(extraDeps, ({value}) => value)`
becomes `Object.fromEntries(Object.entries(extraDeps).map(...))`. The
existing `as T` cast is unchanged.
- `src/use-extra-deps/index.test.tsx`: `last(allDeps)` becomes
`allDeps[allDeps.length - 1]`. `Array.prototype.at` is ES2022 and this
package's `lib` only reaches ES2019, so `.at(-1)` does not compile.
- `src/use-safe-effect/index.test.tsx` and
`src/use-safe-imperative-handle/index.test.tsx`: the `isEqual` deep
comparator is only ever applied to `Array<string>`, for which an
element-wise comparison is deep equality. Each file gets a four-line
local `stringArraysEqual` rather than a hand-rolled generic deep equal.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated from the Dead Weight audit of 31 active Freckle JS/TS repos (sequence step 4: trivial lodash removals).
lodash was in
dependencies— a runtime dependency of a published package — to support one expression of shipped code. The other three usages were test-only.Per-call-site replacement
1.
src/use-extra-deps/index.ts:70— the only shipped usageextraDepsis always a plain object literal at every call site, and the iteratee is a destructuring arrow function — no lodash-specific collection or shorthand behavior in play.Object.entries/fromEntriesvisit own enumerable keys, matchingmapValues'baseForOwn. The pre-existingas Tcast (needed because the parameter is a mapped conditional type) is unchanged.2.
src/use-extra-deps/index.test.tsx:14— test onlyNot
.at(-1):Array.prototype.atis ES2022 and is not in this project's resolvedlib, so it fails to compile (TS2550). Index arithmetic matcheslodash/lastexactly, including returningundefinedon an empty array.3 & 4.
src/use-safe-effect/index.test.tsx:225andsrc/use-safe-imperative-handle/index.test.tsx:234— test onlywith, in each file:
This is deliberately not a hand-rolled generic deep-equal. In both files the comparator is only ever applied to a
p2declaredArray<string>, and for an array of strings element-wise comparison is deep equality — the type system guarantees there is no nesting to recurse into.I looked for the runner's own deep-equality first, as the safer option. This repo is a Jest holdout (
"test": "jest", ts-jest preset), so there is novitestexpect.equalsavailable, and Jest 30 does not export a boolean deep-equal on the publicexpectsurface — itsequalsis only reachable asthis.equalsinside a custom matcher or by importing the undeclared transitive@jest/expect-utils. Wrappingexpect(a).toEqual(b)in try/catch would work but pollutes assertion counts inside a render callback. The four-line local helper, scoped to the test file, is the cleaner trade.Behavior is unchanged: the tests still distinguish
['a', 'b']from['b', 'a'](order-sensitive) and still treat two structurally-equal arrays at different memory locations as equal — which is the whole point of those two cases.Note on lodash in the lockfile
For this repo lodash genuinely does leave
yarn.lock— it has no@freckle/maybeor@freckle/non-emptydependency to pull it back in. The remaining lodash-ish lockfile matches arelodash.debounceandlodash.memoize, which are separate packages arriving transitively.Worth stating for the sweep as a whole, though: in the sibling PRs (
ajax-js,query-params-js) lodash does stay in the lockfile, because@freckle/maybeand@freckle/non-emptydepend on it directly. Those PRs remove each repo's own direct dependency and usage, not the lockfile entry.Verification
Package manager respected:
yarn@1.22.22(Yarn Classic) viacorepack yarn, and the v1 lockfile format is preserved.yarn build(tsc -d):yarn lint(eslint, cache cleared first):yarn test(Jest):yarn run check-git-clean, re-run after committing the rebuiltdist/:The regenerated
dist/use-extra-deps/index.jsis committed — the lodashrequireand the__importDefaultinterop helper are both gone from the build output.On
yarn format: running it reformats three files with pre-existing prettier drift unrelated to lodash (thePrimitiveDepunion andExtraDepsindentation inuse-extra-deps/index.ts, a curried-arrow wrap inuse-safe-imperative-handle/index.test.tsx:158, and{ p1 }spacing inuse-safe-callback/index.test.tsx:27).formatis not run in CI, so this backlog has accumulated. I reverted all of it to keep this diff scoped to the dependency removal — the code I added is prettier-clean on its own. The backlog is worth its own PR.🤖 Generated with Claude Code