-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
Walkthrough本次更改主要涉及 Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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问题,但建议考虑以下架构改进:
- 集中化忽略路径的处理逻辑
- 引入配置驱动的忽略规则系统
- 优化性能,减少重复的路径检查
建议:
- 创建统一的
WatchFilter
结构体来处理所有忽略规则- 使用构建器模式来配置监控规则
- 缓存正则表达式匹配结果
- 考虑使用
gitignore
风格的规则系统是否需要我协助设计这个重构方案?
if Self::should_ignore_watch(&path, ignore_list) | ||
|| path.to_string_lossy().contains("node_modules") | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
重构 node_modules 路径检查逻辑
当前实现存在以下问题:
- 与
get_ignore_list
中的 node_modules 检查重复 - 使用简单的字符串匹配而不是已有的正则表达式模式
- 可能与
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)
))
}
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1684 +/- ##
==========================================
- Coverage 55.64% 55.63% -0.01%
==========================================
Files 173 173
Lines 17530 17531 +1
==========================================
- Hits 9754 9753 -1
- Misses 7776 7778 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr 描述里补充下问题原因和解的思路?
monorepo 仅忽略了
root
-> allparents root
下的node_modules
文件监听, 对于monorepo
兄弟子包的依赖, 会把node_modules
囊括进去.eg.
以上会忽略
root/node_modules
,repo1/node_modules
监听repo2/node_modules
显然
repo2/node_modules
是不需要被监听的整个
watch
模块之后需要一次大的重构, 目前的判断模式过于繁琐低效.目前没有时间o(╥﹏╥)o, 先简单对大型
monorepo
项目做个修复.Summary by CodeRabbit
新功能
变更
Watcher
结构体中的方法签名,以改进监视逻辑。