fix(fs): resolve ignore pattern matching for dot-prefix paths#751
fix(fs): resolve ignore pattern matching for dot-prefix paths#751
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe FS driver's ignore matcher now uses Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/drivers/fs.ts (1)
35-39: Please add regression tests for this behavior.Add tests for dot-prefixed base directories with
**/node_modules/**and**/.git/**, plus a case confirming absolute ignore patterns still match after introducingrelativePath.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/drivers/fs.ts` around lines 35 - 39, Add regression tests exercising the function that computes relativePath and checks ignorePatterns (the code using relative(base, path), relativePath, matchesGlob and ignorePatterns). Specifically, add tests that: (1) ensure dot-prefixed base directories (e.g., base = "./src" or base = ".cache") still match patterns like "**/node_modules/**" and "**/.git/**" for files under those directories; and (2) verify that absolute ignore patterns still match when relativePath logic is used (i.e., an absolute pattern remains matched for an absolute path). Target the function that returns the ignore decision (the code using relativePath and matchesGlob) and create clear unit cases for node_modules, .git, and an absolute-pattern match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/drivers/fs.ts`:
- Around line 35-39: Add regression tests exercising the function that computes
relativePath and checks ignorePatterns (the code using relative(base, path),
relativePath, matchesGlob and ignorePatterns). Specifically, add tests that: (1)
ensure dot-prefixed base directories (e.g., base = "./src" or base = ".cache")
still match patterns like "**/node_modules/**" and "**/.git/**" for files under
those directories; and (2) verify that absolute ignore patterns still match when
relativePath logic is used (i.e., an absolute pattern remains matched for an
absolute path). Target the function that returns the ignore decision (the code
using relativePath and matchesGlob) and create clear unit cases for
node_modules, .git, and an absolute-pattern match.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/drivers/fs.ts`:
- Line 3: The code imports isMatch from "picomatch" in src/drivers/fs.ts but the
package is missing from package.json; add "picomatch" to the dependencies
section of package.json (appropriate semver, e.g., latest stable) so the import
of isMatch resolves during install and CI.
6938f41 to
b457130
Compare
Replace `path.matchesGlob` with `picomatch.isMatch` and enable
`{ dot: true }` so that `**` glob patterns correctly traverse
dot-prefix directory segments (e.g. `.config/`, `.superset/`).
Without this, projects under dot-prefix paths have their
`node_modules` watched entirely, causing EMFILE errors.
Fixes unjs#750
b457130 to
630c046
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@package.json`:
- Line 82: The project currently lists "picomatch" only in devDependencies but
src/drivers/fs.ts imports and uses picomatch at runtime; move "picomatch":
"^4.0.3" from devDependencies into the top-level dependencies in package.json
(ensure the dependency entry exists under "dependencies" and remove it from
"devDependencies") so consumers installing the package in production get
picomatch and avoid ERR_MODULE_NOT_FOUND when the fs driver (src/drivers/fs.ts)
is used; optionally regenerate the lockfile after updating dependencies.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 55c216f0-b330-437f-ad9a-dcaff6e7ec06
📒 Files selected for processing (2)
package.jsonsrc/drivers/fs.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/drivers/fs.ts
picomatch is imported at runtime in src/drivers/fs.ts, so it must be in dependencies for consumers to resolve it in production. Co-Authored-By: Claude Opus 4.6 <[email protected]>
use relative path from base before matching to avoid dot-prefix issues
|
Thanks for PR ❤️ Replaced The original issue was that For absolute ignore patterns (e.g. Also added a regression test for |
Summary
The FS driver's
ignorefunction usespath.matchesGlob, which does not traverse dot-prefix directory segments with**glob patterns. When a project resides under a dot-prefix path (e.g.~/.config/project/), ignore patterns like**/node_modules/**silently fail, causing chokidar to watch all files innode_modulesand triggeringEMFILE: too many open files.Fix
Replace
path.matchesGlobwithpicomatch.isMatchand enable{ dot: true }.picomatchis added todevDependencies.Changes
src/drivers/fs.ts— Replacepath.matchesGlobwithpicomatch.isMatch({ dot: true })package.json— Addpicomatch: ^4.0.3todevDependenciesFixes #750