refactor(create-docusaurus): replace lodash with native implementation#11653
Conversation
|
Hi @torresgol10! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
slorber
left a comment
There was a problem hiding this comment.
Ok to remove the dependency, but I'll rework your PR to make it more acceptable
| // TODO remove dependency on large @docusaurus/utils | ||
| // would be better to have a new smaller @docusaurus/utils-cli package | ||
| import {askPreferredLanguage} from '@docusaurus/utils'; | ||
| import {askPreferredLanguage, kebabCase} from '@docusaurus/utils'; |
There was a problem hiding this comment.
As mentioned in the TODO, we want to remove the dependency on this package
| * Converts a string to kebab-case. | ||
| * Mimics lodash's behavior. | ||
| */ | ||
| export function kebabCase(str: string): string { |
There was a problem hiding this comment.
This is not a reliable kebabCase implementation (compared to Lodash), so we clearly don't want to expose it as a js util to use everywhere else. The Lodash implementation remains better, and this good-enough implementation can stay within the create-docusaurus package.
slorber
left a comment
There was a problem hiding this comment.
Ok to remove the dependency, but I'll rework your PR to make it more acceptable
Pre-flight checklist
Motivation
The goal of this PR is to remove the
lodashdependency from thecreate-docusauruspackage to reduce the install size and improve startup performance.Impact:
node_modulesfor creating a new site.require('lodash')overhead).Changes included:
lodashdependency fromcreate-docusaurus/package.json._.sortBywith nativeArray.prototype.sortincreate-docusaurus._.kebabCasewith a robust native implementation.kebabCaseutility to@docusaurus/utils(src/jsUtils.ts) to verify it with tests and allow reuse across the monorepo for future refactors.Test Plan
I verified that the
create-docusauruspackage builds and runs correctly withoutlodash.kebabCasein@docusaurus/utilsto verify it mimics Lodash's behavior exactly (including edge cases).yarn jest packages/docusaurus-utils/src/__tests__/jsUtils.test.ts -t "kebabCase"create-docusauruscompiles successfully.Test links
N/A (Changes affect the CLI tool and Utils, no UI changes).
Deploy preview: N/A
Related issues/PRs