Skip to content

chore(pre-commit): add check-lock-file script #2915

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 1 commit into from
Jan 6, 2025

Conversation

Miles-hxy
Copy link
Collaborator

@Miles-hxy Miles-hxy commented Jan 3, 2025

描述

在预提交阶段添加了一个脚本来检查 pnpm-lock.yaml 文件的一致性和完整性。这个脚本将在每次提交代码之前运行,确保所有依赖项的版本都被正确锁定,并且没有未提交的更改。

动机

为了确保项目依赖的稳定性和可重现性,我们需要在每次提交之前验证锁文件的正确性。这有助于避免因依赖项版本不一致而导致的构建问题或运行时错误。

更改内容

  • package.json 文件的 scripts 部分添加了一个新的脚本 check-lock-file
  • .husky/pre-commit 文件中添加了一个钩子,用于在提交代码之前运行 check-lock-file 脚本。

Summary by CodeRabbit

  • 新功能

    • 在提交前检查 pnpm-lock.yaml 文件的完整性
    • 添加了一个脚本,验证包解析路径是否正确
  • 改进

    • 增强了 Git 提交前的安全检查机制
    • 确保 npm 仓库设置正确

Copy link

coderabbitai bot commented Jan 3, 2025

变更概述

演练

此拉取请求引入了一个新的预提交钩子脚本检查,用于验证 pnpm-lock.yaml 文件的完整性。在 .husky/pre-commit 中添加了 node ./scripts/check-lock.js 命令,该脚本会检查包解析路径是否正确,确保仅使用官方 npm 注册表的资源。如果检测到不正确的路径,脚本将阻止提交并显示错误信息。

变更

文件 变更摘要
.husky/pre-commit 在现有的 npx lint-staged 命令前添加 node ./scripts/check-lock.js
scripts/check-lock.js 新增脚本,用于检查 pnpm-lock.yaml 文件中的包解析路径是否正确

可能相关的 PR

建议标签

3.x

建议审阅者

  • oasis-cloud

诗歌

🐰 锁文件检查,兔子轻轻跳
路径正确否,代码慢慢扫
npm 注册表,安全有保障
提交前一检,bug 远远逃
代码之旅,兔子护航 🛡️


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.

@github-actions github-actions bot added the 3.x Target branch 3.x label Jan 3, 2025
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.97%. Comparing base (93d8a67) to head (0d5233c).
Report is 2 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2915   +/-   ##
==========================================
  Coverage      85.97%   85.97%           
==========================================
  Files            277      277           
  Lines          18692    18692           
  Branches        2769     2769           
==========================================
  Hits           16070    16070           
  Misses          2617     2617           
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 0

🧹 Nitpick comments (1)
scripts/check-lock.js (1)

6-6: 通过正则匹配定位不正确的 Registry
正则表达式可准确捕捉非 registry.npmjs.org 的域名。若团队使用内部镜像或私有源,需在此脚本内额外处理,以免误报。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93d8a67 and 0d5233c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • .husky/pre-commit (1 hunks)
  • scripts/check-lock.js (1 hunks)
🔇 Additional comments (4)
.husky/pre-commit (1)

2-2: 在 pre-commit 中添加锁文件检查脚本可有效避免依赖冲突
在执行 lint 之前先检查 pnpm-lock.yaml 的完整性有助于及时发现并修复潜在依赖冲突,增强依赖稳定性。

scripts/check-lock.js (3)

1-3: 脚本文件导入 fspath 模块的方式符合 Node.js 标准
引用的核心模块位置和方式正常,可继续保持现有实现。


4-5: 使用 path.resolve 获取锁文件绝对路径
这样可确保在不同工作目录下都能正确定位 pnpm-lock.yaml,有利于脚本通用性。


7-10: 在检测到错误路径后直接抛出异常
脚本会阻断后续提交流程,保证只在正确配置依赖的情况下才能完成提交,这与保障依赖一致性的目标相吻合。

@oasis-cloud oasis-cloud merged commit fc8754c into jdf2e:feat_v3.x Jan 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants