Skip to content

perf(rspack,webpack): drop lodash-es dependency #30409

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

Merged
merged 6 commits into from
Dec 30, 2024
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Dec 29, 2024

🔗 Linked issue

📚 Description

This is a performance improvement for webpack/rspack builders, swapping to use es-toolkit instead of lodash-es, dropping lodash-es.

I've also updated the migration docs to recommend using it rather than lodash template. -> e70ef00

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

socket-security bot commented Dec 29, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/pathe@1.1.2 None 0 30.8 kB pi0
npm/prettier@3.4.2 None 0 7.83 MB prettier-bot
npm/semver@7.6.3 None 0 95.8 kB npm-cli-ops
npm/typescript@5.7.2 None 0 22.7 MB typescript-bot
npm/ufo@1.5.4 None 0 103 kB pi0

🚮 Removed packages: npm/klona@2.0.6, npm/knip@5.41.1, npm/knitwork@1.2.0, npm/markdownlint-cli@0.43.0

View full report↗︎

Copy link

coderabbitai bot commented Dec 29, 2024

Warning

Rate limit exceeded

@danielroe has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 26 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac6182 and 5801c89.

📒 Files selected for processing (1)
  • packages/kit/src/template.ts (2 hunks)

Pull Request Changes Analysis

Walkthrough

The pull request introduces modifications across multiple files in the webpack and kit packages. In packages/kit/src/template.ts, documentation comments for the addTemplate and addTypeTemplate functions were updated to clarify their template rendering behaviour. The packages/webpack/src/utils/config.ts file saw a significant change to the getWebpackConfig function, transforming it into an asynchronous method with an additional preset parameter. In packages/webpack/src/presets/base.ts, the configuration assignment was modified to use the defu library for more flexible configuration merging. Lastly, packages/webpack/src/webpack.ts simplified the webpack configuration retrieval process by directly returning ctx.config in the webpackConfigs mapping.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/kit/src/template.ts (1)

47-49: Grammar correction in documentation
Consider adjusting the sentence structure for flow. For example, changing “Renders given types during build to disk … and register them as types.” to “Renders the specified types during the build to the project’s buildDir and registers them as types.” would be more grammatically consistent.

 /**
- * Renders given types during build  to disk in the project `buildDir`
- * and register them as types.
+ * Renders the specified types during the build to the project `buildDir`
+ * and registers them as types.
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 100eaa3 and e01d8a9.

⛔ Files ignored due to path filters (3)
  • packages/rspack/package.json is excluded by !**/package.json
  • packages/webpack/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (3)
  • docs/1.getting-started/12.upgrade.md (1 hunks)
  • packages/kit/src/template.ts (2 hunks)
  • packages/webpack/src/utils/config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/webpack/src/utils/config.ts
🔇 Additional comments (1)
packages/kit/src/template.ts (1)

17-17: Minor clarity update regarding rendering documentation
The revised comment correctly reflects where the rendered templates are placed, although it might help to reference the distinction between purely virtual output and the optional write-to-disk behaviour for even greater clarity.

Comment on lines 641 to 645
* Use `es-toolkit/compat` (a drop-in replacement for lodash template), as a dependency of _your_ project rather than Nuxt:

```diff
+ import { readFileSync } from 'node:fs'
+ import { template } from 'lodash-es'
+ import { template } from 'es-toolkit/compat'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update documentation and code references to reflect template engine change

The verification reveals several items that need attention:

  • The documentation in packages/schema/src/config/build.ts still references lodash/template and needs to be updated to reflect the new es-toolkit/compat usage.
  • Neither es-toolkit nor lodash appears in the package.json dependencies, which aligns with the documentation stating that es-toolkit should be a dependency of the user's project rather than Nuxt.
  • There are template-related implementations in the codebase, particularly in the UI templates and core functionality, but they don't appear to be using lodash's template engine.

Action items:

  • Update the documentation in packages/schema/src/config/build.ts to reference es-toolkit/compat instead of lodash/template
  • Consider adding a note in the upgrade guide about removing any existing lodash dependencies if they were only used for templating
🔗 Analysis chain

Verify es-toolkit/compat import and documentation
Ensure that the project’s dependencies include es-toolkit and that developers are aware they may need to install it separately. The updated instructions appear correct, but please confirm that you have also updated any references to lodash/template in your downstream files and scripts.


Let me gather more information to verify the usage and implementation details.


Let me check one more aspect to ensure we have a complete picture.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 1. Verify if 'es-toolkit' is declared within package.json 
rg '"es-toolkit"' package.json 

# 2. Check if leftover references to lodash/template still exist in the codebase
rg 'lodash.template'

Length of output: 856


Script:

#!/bin/bash
# 1. Check for any direct imports of lodash/template in the codebase
rg "from ['\"](lodash|lodash/template)['\"]"

# 2. Search for template-related imports and usage
rg "import.*template" -g "!*.md"

# 3. Look for .ejs file references
fd ".ejs$"

# 4. Check package.json for any lodash dependencies
rg '"lodash"' package.json

Length of output: 2081


Script:

#!/bin/bash
# Check for any template-related functionality in source files
ast-grep --pattern 'template($$$)'

# Look for any remaining lodash template usage
rg -i "lodash.*template" -g "!*.md" -g "!package.json"

Length of output: 662

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e01d8a9 and 6c9ca6f.

⛔ Files ignored due to path filters (3)
  • packages/rspack/package.json is excluded by !**/package.json
  • packages/webpack/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/webpack/src/presets/base.ts (3 hunks)
  • packages/webpack/src/utils/config.ts (1 hunks)
  • packages/webpack/src/webpack.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: build
packages/webpack/src/utils/config.ts

[failure] 66-66:
Parameter 'preset' implicitly has an 'any' type.

🔇 Additional comments (4)
packages/webpack/src/webpack.ts (2)

18-18: Ensure usage consistency for applyPresets.

You have imported applyPresets but only appear to call it once. Verify whether any additional usage or cleaning up is required for consistency.


31-31: Configuration retrieval is now direct.

Returning ctx.config directly simplifies the logic. Ensure that all relevant preset applications happen prior to this step for consistency.

packages/webpack/src/presets/base.ts (2)

12-12: Dependency choice acknowledged.

Using defu is a neat solution to merge objects flexibly without losing nested properties.


Line range hint 31-49: defu usage merges runtime and default config.

This approach supports deeper merges. Confirm the final structure includes all key fields, especially from ctx.config and ctx.userConfig.

Comment on lines 66 to 70
export async function getWebpackConfig (ctx: WebpackConfigContext, preset): Promise<Configuration> {
// Clone to avoid leaking config between Client and Server
// TODO: rewrite webpack implementation to avoid necessity for this
return cloneDeep(ctx.config)
await applyPresets(ctx, preset)
return ctx.config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Parameter needs explicit type.

The preset parameter’s type is implicitly any. Define an interface or use a generic type to improve type safety.

Apply this patch to avoid implicit any type:

-export async function getWebpackConfig (ctx: WebpackConfigContext, preset): Promise<Configuration> {
+export async function getWebpackConfig (ctx: WebpackConfigContext, preset: WebpackConfigPresetItem | WebpackConfigPresetItem[]): Promise<Configuration> {
   await applyPresets(ctx, preset)
   return ctx.config
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getWebpackConfig (ctx: WebpackConfigContext, preset): Promise<Configuration> {
// Clone to avoid leaking config between Client and Server
// TODO: rewrite webpack implementation to avoid necessity for this
return cloneDeep(ctx.config)
await applyPresets(ctx, preset)
return ctx.config
export async function getWebpackConfig (ctx: WebpackConfigContext, preset: WebpackConfigPresetItem | WebpackConfigPresetItem[]): Promise<Configuration> {
// Clone to avoid leaking config between Client and Server
// TODO: rewrite webpack implementation to avoid necessity for this
await applyPresets(ctx, preset)
return ctx.config
🧰 Tools
🪛 GitHub Check: build

[failure] 66-66:
Parameter 'preset' implicitly has an 'any' type.

@danielroe danielroe changed the title perf(rspack,webpack): swap to es-toolkit dependency perf(rspack,webpack): drop lodash-es dependency Dec 30, 2024
@danielroe danielroe merged commit c1b8b92 into main Dec 30, 2024
47 checks passed
@danielroe danielroe deleted the perf/es-toolkit branch December 30, 2024 19:38
@github-actions github-actions bot mentioned this pull request Dec 30, 2024
@github-actions github-actions bot mentioned this pull request Jan 4, 2025
Kamsou pushed a commit to Kamsou/nuxt that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy