Skip to content
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

fix: pnpm workspace watch too many files #1684

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Jinbao1001
Copy link
Member

@Jinbao1001 Jinbao1001 commented Nov 8, 2024

monorepo 仅忽略了 root -> all parents root 下的 node_modules 文件监听, 对于monorepo 兄弟子包的依赖, 会把 node_modules囊括进去.

eg.

-root
  -node_modules
  -repo1
      -repo2
      -node_modules
  -repo2
      -node_modules

以上会忽略root/node_modules, repo1/node_modules 监听repo2/node_modules
显然repo2/node_modules是不需要被监听的

整个watch 模块之后需要一次大的重构, 目前的判断模式过于繁琐低效.
目前没有时间o(╥﹏╥)o, 先简单对大型monorepo项目做个修复.

Summary by CodeRabbit

  • 新功能

    • 增强文件监视功能,自动忽略“node_modules”目录,减少不必要的事件处理。
  • 变更

    • 更新了Watcher结构体中的方法签名,以改进监视逻辑。

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

本次更改主要涉及 crates/mako/src/dev/watch.rs 文件中 Watcher 结构体及其方法的修改。watch_file_or_dir 方法新增了一个条件,以忽略包含 "node_modules" 的路径,从而防止监视该目录中的文件或子目录。虽然 normalize_eventsget_ignore_list 方法的签名和功能未发生变化,但它们仍然在更新的忽略逻辑中发挥作用。

Changes

文件路径 更改摘要
crates/mako/src/dev/watch.rs - 更新 watch_file_or_dir 方法,新增忽略 "node_modules" 路径的条件。
- 更新 Watcher 结构体的 watchnormalize_events 方法签名。

Possibly related PRs

Suggested reviewers

  • sorrycc
  • xusd320

🐇 在草地上跳跃,欢快无比,

忽略 "node_modules",真是轻松自在!

监视文件,逻辑更清晰,

兔子们欢呼,代码更完美!

让我们一起庆祝,代码如诗!🌼✨


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

🧹 Outside diff range and nitpick comments (1)
crates/mako/src/dev/watch.rs (1)

Line range hint 1-255: 建议进行更全面的重构以优化文件监控机制

当前的修复虽然解决了immediate问题,但建议考虑以下架构改进:

  1. 集中化忽略路径的处理逻辑
  2. 引入配置驱动的忽略规则系统
  3. 优化性能,减少重复的路径检查

建议:

  1. 创建统一的 WatchFilter 结构体来处理所有忽略规则
  2. 使用构建器模式来配置监控规则
  3. 缓存正则表达式匹配结果
  4. 考虑使用 gitignore 风格的规则系统

是否需要我协助设计这个重构方案?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eacee04 and 6d9a8ed.

📒 Files selected for processing (1)
  • crates/mako/src/dev/watch.rs (1 hunks)

Comment on lines +153 to +155
if Self::should_ignore_watch(&path, ignore_list)
|| path.to_string_lossy().contains("node_modules")
{
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

重构 node_modules 路径检查逻辑

当前实现存在以下问题:

  1. get_ignore_list 中的 node_modules 检查重复
  2. 使用简单的字符串匹配而不是已有的正则表达式模式
  3. 可能与 watch 方法中的 node_modules_regexes 逻辑冲突

建议按以下方式重构:

-        if Self::should_ignore_watch(&path, ignore_list)
-            || path.to_string_lossy().contains("node_modules")
-        {
+        if Self::should_ignore_watch(&path, ignore_list) {
             return Ok(());
         }

然后在 should_ignore_watch 方法中统一处理 node_modules 的检查逻辑:

fn should_ignore_watch(path: &Path, ignore_list: &[PathBuf]) -> bool {
    let path_str = path.to_string_lossy();
    ignore_list
        .iter()
        .any(|ignored| path_str.strip_prefix(ignored.to_str().unwrap()).is_some())
        || (path_str.contains("node_modules") 
            && !self.node_modules_regexes.iter().any(|regex| 
                regex.is_match(&path_str)
            ))
}

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 55.63%. Comparing base (6ddd711) to head (6d9a8ed).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/dev/watch.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1684      +/-   ##
==========================================
- Coverage   55.63%   55.63%   -0.01%     
==========================================
  Files         173      173              
  Lines       17530    17531       +1     
==========================================
  Hits         9753     9753              
- Misses       7777     7778       +1     

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

Copy link
Member

@sorrycc sorrycc left a comment

Choose a reason for hiding this comment

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

pr 描述里补充下问题原因和解的思路?

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