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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/mako/src/dev/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@
}

fn watch_file_or_dir(&mut self, path: PathBuf, ignore_list: &[PathBuf]) -> anyhow::Result<()> {
if Self::should_ignore_watch(&path, ignore_list) {
if Self::should_ignore_watch(&path, ignore_list)
|| path.to_string_lossy().contains("node_modules")

Check warning on line 154 in crates/mako/src/dev/watch.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/dev/watch.rs#L153-L154

Added lines #L153 - L154 were not covered by tests
{
Comment on lines +153 to +155
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)
            ))
}

return Ok(());
}

if path.is_file() && !self.watched_files.contains(&path) {
self.watcher
.watch(path.as_path(), notify::RecursiveMode::NonRecursive)?;
Expand Down
Loading