refactor: reduce lodash footprint (follow-up to #1509)#1524
Open
s-lukashenka-micoworks wants to merge 3 commits into
Open
refactor: reduce lodash footprint (follow-up to #1509)#1524s-lukashenka-micoworks wants to merge 3 commits into
s-lukashenka-micoworks wants to merge 3 commits into
Conversation
Picks up the security patches released in lodash 4.18.x (4.18.0/4.18.1). Addresses item 1 of the follow-ups discussed in PaloAltoNetworks#1509. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drops the dependency on four lodash utilities that have direct native equivalents: - uniq -> [...new Set(...)] (openapi.ts, sidebars/index.ts) - flatten -> Array.prototype.flat (DiscriminatorTabs, SchemaTabs) - find -> Array.prototype.find (languages.ts) - isEmpty -> Object.keys(x).length === 0 (createSchema.ts, Schema) The isEmpty call sites are guarded by a preceding truthiness check, so the value is always a non-null object there. The find call keeps optional chaining to preserve lodash's null-tolerance. Addresses item 2 of the follow-ups discussed in PaloAltoNetworks#1509. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Switches the one remaining barrel import (import { kebabCase } from
"lodash") to the subpath form (import kebabCase from "lodash/kebabCase")
so tree shaking can drop the rest of lodash. All other lodash usage in
the codebase already uses subpath imports.
Addresses item 3 of the follow-ups discussed in PaloAltoNetworks#1509.
Co-Authored-By: Claude Opus 4.8 (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.
Summary
Follow-up to the discussion in #1509. That issue proposed swapping
lodashfores-toolkit; @sserrata closed it in favor of three lower-risk steps and noted PRs for items 1–3 would be welcome. This PR implements all three.Each item is a separate commit so they can be reviewed (or dropped) independently:
build(deps): bump lodash to ^4.18.1— picks up the security patches released in the lodash 4.18.x line.refactor: replace lodash find/flatten/uniq/isEmpty with native JS— removes the four utilities that have direct native equivalents:uniq→[...new Set(...)](openapi.ts,sidebars/index.ts)flatten→Array.prototype.flat()(DiscriminatorTabs,SchemaTabs)find→Array.prototype.find()(languages.ts)isEmpty→Object.keys(x).length === 0(createSchema.ts,Schema)refactor: use lodash subpath import for kebabCase in sidebars— switches the one remaining barrel import (import { kebabCase } from "lodash") to the subpath form so the rest of lodash can be tree-shaken. Every other lodash usage already imports from a subpath.The remaining lodash utilities (
merge,mergeWith,cloneDeep,kebabCase,unionBy) are kept and could be vendored later (item 4) if the project wants to drop the dependency entirely.Notes on correctness
isEmptycall sites are both guarded by a preceding truthiness check (if (!additionalProperties) return ...), so the value is always a non-null object at the call —Object.keys(x).length === 0is equivalent there.findreplacement keeps optional chaining (arr1?.find(...)) to preserve lodash's tolerance of a nullish collection.lodash.flattenflattens a single level, which matchesArray.prototype.flat()'s default depth of 1.Testing
yarn build(tsc) passes for bothdocusaurus-plugin-openapi-docsanddocusaurus-theme-openapi-docs.sidebars,languages,openapi,webhooks).createSchema.test.ts) fails, but it fails identically on a cleanmaincheckout (anallof-mergeissue) — it is not affected by these changes.🤖 Generated with Claude Code