Skip to content

chore(@vben-core/shared): 优化 lodash依赖 #6328

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

pangyajun123
Copy link
Contributor

@pangyajun123 pangyajun123 commented Jun 3, 2025

  • 移除 lodash.clonedeep、lodash.get、lodash.isequal、lodash.set
  • 使用整个 lodash 库替代单独的模块
  • 更新 @types/lodash 至 4.17.17 版本

Summary by CodeRabbit

  • Chores
    • Simplified dependency management by consolidating multiple lodash-related packages into a single lodash package with unified type definitions. No changes affecting user experience.

Copy link

changeset-bot bot commented Jun 3, 2025

⚠️ No Changeset found

Latest commit: 803f4d6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Walkthrough

The changes consolidate multiple individual lodash utility dependencies and their type packages into single unified lodash and @types/lodash dependencies. Corresponding import and export statements in the utility index file are updated to import named exports from the main lodash package instead of separate submodules. No public API changes were made.

Changes

File(s) Change Summary
packages/@core/base/shared/package.json, pnpm-workspace.yaml Replaced individual lodash utility and type packages with unified lodash and @types/lodash.
packages/@core/base/shared/src/utils/index.ts Updated export statements to use named exports from lodash instead of individual sub-packages.

Poem

In the warren of code, we hopped with glee,
Four little lodash kits, now one big family!
Imports are lighter, the bundle more neat—
A single lodash carrot, tasty and sweet.
With every refactor, we leap and we bound,
Simpler dependencies, all around!
🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a60163c and 803f4d6.

📒 Files selected for processing (1)
  • packages/@core/base/shared/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/@core/base/shared/package.json
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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
Contributor

@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 ea776aa and a60163c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/@core/base/shared/package.json (1 hunks)
  • packages/@core/base/shared/src/utils/index.ts (1 hunks)
  • pnpm-workspace.yaml (2 hunks)
🔇 Additional comments (2)
packages/@core/base/shared/package.json (1)

88-88:

✅ Verification successful

LGTM! Dependency consolidation looks good.

The consolidation from individual lodash sub-packages to the unified lodash package is a good optimization that simplifies dependency management. The use of catalog references ensures consistent versioning across the workspace.

Please verify that tree shaking works effectively with your build tool to ensure the final bundle size doesn't increase significantly:

Also applies to: 94-94


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining references to individual lodash packages and verify build output

# Check if there are any remaining references to individual lodash packages
echo "Checking for remaining individual lodash package references..."
rg -i "lodash\.(clonedeep|get|isequal|set)" --type json

# Check package-lock or pnpm-lock for the removed packages
echo "Checking lock files for removed packages..."
fd "package-lock.json|pnpm-lock.yaml" --exec rg -l "lodash\.(clonedeep|get|isequal|set)" {}

# Verify the lodash functions are properly exported
echo "Verifying lodash exports..."
rg "cloneDeep|isEqual" --type ts

Length of output: 851


Ensure Re-exports and Imports Align with Consolidation

All individual lodash sub-package references are removed, and the main lodash functions are correctly re-exported and used. However, confirm that every file imports the consolidated exports rather than lingering individual packages.

Points to verify:

  • packages/effects/access/src/accessible.ts and other modules should import from the shared utils (or directly from lodash) after consolidation.
  • playground/src/api/request.ts imports cloneDeep from @vben/utils—ensure that re-export maps to the lodash cloneDeep.

If any files still import individual lodash functions from old paths, update them to use:

import { cloneDeep, get, isEqual, set } from 'lodash';

or

import { cloneDeep, get, isEqual, set } from '@core/base/shared/utils';
packages/@core/base/shared/src/utils/index.ts (1)

17-17: Perfect! Import consolidation is correctly implemented.

The change from individual lodash sub-package imports to named exports from the main lodash package is implemented correctly. This maintains the same public API while benefiting from the dependency consolidation.

'@types/lodash.get': ^4.4.9
'@types/lodash.isequal': ^4.5.8
'@types/lodash.set': ^4.3.9
'@types/lodash': ^4.17.17
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Catalog versions look appropriate.

The lodash version ^4.17.21 is the latest stable release, and @types/lodash ^4.17.17 provides comprehensive type definitions. These versions are well-tested and widely adopted.

Consider verifying compatibility with your current TypeScript configuration:

Also applies to: 117-117


🌐 Web query:

What are the latest versions of lodash and @types/lodash packages, and are there any breaking changes in lodash 4.17.21?

💡 Result:

Latest Versions of lodash and @types/lodash

  • lodash: The latest available version is 4.17.21[2][5][6][10]. No newer major or minor releases have been published since this version.
  • @types/lodash: The latest version referenced in recent package lists is 4.17.7[10]. This matches the last major release of type definitions for Lodash, which are maintained separately by the DefinitelyTyped community.

Breaking Changes in lodash 4.17.21

  • Lodash 4.17.21 is a patch release. It was published primarily to address the security vulnerability reported as CVE-2021-23337 (command injection in _.template). This patch does not introduce breaking changes compared to previous 4.x versions[9].

  • The last major breaking changes in Lodash occurred during the transition from v3 to v4. These included:

    • Dropping support for older browsers (IE < 9)
    • Changes to chain-sequence behaviors for some methods
    • Removal of category names from module paths (e.g., lodash/array/chunk moved to lodash/chunk)
    • Integration of lodash-fp into the main package as require('lodash/fp')[4]
  • The 4.17.x releases, including 4.17.21, are considered minor or patch updates. They typically address bug fixes, internal improvements, or security updates, but do not introduce major API changes or breaking changes for users already on Lodash v4[4][9].

Security Notes

  • Patch Reason: Version 4.17.21 fixed a security vulnerability (CVE-2021-23337) involving _.template. If you are using an older version, especially any release prior to 4.17.21, an upgrade is recommended to mitigate this risk[9][7].

Summary Table

Package Latest Version Breaking Changes in Latest
lodash 4.17.21 None in 4.17.21
@types/lodash 4.17.7 No, type updates only

Conclusion:

  • Upgrade to lodash 4.17.21 for security, with no breaking changes relative to earlier Lodash v4 versions.
  • For type safety in TypeScript projects, use @types/lodash 4.17.7[10].

Citations:


Fix @types/lodash version mismatch

The lodash entry at line 117 (^4.17.21) is correct—v4.17.21 is the latest patch for Lodash 4 with no breaking changes and it addresses CVE-2021-23337. However, the types entry at line 46 (@types/lodash: ^4.17.17) does not align with the currently published version of @types/lodash (latest is 4.17.7). Please verify or update:

• pnpm-workspace.yaml line 46:
‑ current: @types/lodash: ^4.17.17
‑ should be: @types/lodash: ^4.17.7

• pnpm-workspace.yaml line 117:
lodash: ^4.17.21 (no change)

🤖 Prompt for AI Agents
In pnpm-workspace.yaml at line 46, the version for @types/lodash is incorrectly
set to ^4.17.17, which does not match the latest published version 4.17.7.
Update the @types/lodash version at line 46 to ^4.17.7 to align with the current
stable release, while keeping the lodash version at line 117 unchanged as
^4.17.21.

@RanMaoting
Copy link
Contributor

感觉可以使用es-toolkit/compat, 整体替代lodash,这个库性能好像还更好,与lodash已经完全兼容了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants