Skip to content

fix(fs): resolve ignore pattern matching for dot-prefix paths#751

Merged
pi0 merged 5 commits intounjs:mainfrom
heejunKIM01:fix/fs-driver-dot-path-ignore
Mar 19, 2026
Merged

fix(fs): resolve ignore pattern matching for dot-prefix paths#751
pi0 merged 5 commits intounjs:mainfrom
heejunKIM01:fix/fs-driver-dot-path-ignore

Conversation

@heejunKIM01
Copy link
Contributor

@heejunKIM01 heejunKIM01 commented Mar 5, 2026

Summary

The FS driver's ignore function uses path.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 in node_modules and triggering EMFILE: too many open files.

Fix

Replace path.matchesGlob with picomatch.isMatch and enable { dot: true }. picomatch is added to devDependencies.

// Before (path.matchesGlob — no dot option)
matchesGlob(".config/project/node_modules/foo.js", "**/node_modules/**")
// → false

// After (picomatch with { dot: true })
isMatch(".config/project/node_modules/foo.js", "**/node_modules/**", { dot: true })
// → true

Changes

  • src/drivers/fs.ts — Replace path.matchesGlob with picomatch.isMatch({ dot: true })
  • package.json — Add picomatch: ^4.0.3 to devDependencies

Fixes #750

@heejunKIM01 heejunKIM01 requested a review from pi0 as a code owner March 5, 2026 05:55
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The FS driver's ignore matcher now uses picomatch.isMatch(path, pattern, { dot: true }) instead of path.matchesGlob, ensuring glob patterns (e.g., **/node_modules/**, **/.git/**) match across dot-prefixed path segments. No exported or public declarations changed.

Changes

Cohort / File(s) Summary
FS driver: ignore matching
src/drivers/fs.ts
Replaced matchesGlob usage with picomatch.isMatch and updated ignore() to call isMatch(path, pattern, { dot: true }), enabling pattern matching through dot-prefixed directories.
Dev dependency
package.json
Added picomatch (^4.0.3) to devDependencies to support the new matcher usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I sniffed the hidden dots by moonlight,
Swapped my matcher to make patterns right.
Now node_modules can't hide in a den,
I hop, I skip, I ignore them — then back again. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing path.matchesGlob with picomatch.isMatch to fix ignore pattern matching for dot-prefix paths.
Linked Issues check ✅ Passed The PR fully addresses issue #750 by replacing path.matchesGlob with picomatch.isMatch and enabling { dot: true } option to fix pattern matching in dot-prefixed directories.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the ignore pattern matching issue; dependency addition is justified as picomatch replacement for matchesGlob, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

🧹 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 introducing relativePath.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7978ed84-94e8-443c-992d-318b700335a8

📥 Commits

Reviewing files that changed from the base of the PR and between 34bb632 and b98fe9b.

📒 Files selected for processing (1)
  • src/drivers/fs.ts

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae322dfd-6acb-492d-b0d9-4fe736c5ee9f

📥 Commits

Reviewing files that changed from the base of the PR and between b98fe9b and 6938f41.

📒 Files selected for processing (1)
  • src/drivers/fs.ts

@heejunKIM01 heejunKIM01 force-pushed the fix/fs-driver-dot-path-ignore branch from 6938f41 to b457130 Compare March 5, 2026 06:29
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
@heejunKIM01 heejunKIM01 force-pushed the fix/fs-driver-dot-path-ignore branch from b457130 to 630c046 Compare March 5, 2026 06:34
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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between b457130 and 630c046.

📒 Files selected for processing (2)
  • package.json
  • src/drivers/fs.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/drivers/fs.ts

heejunKIM01 and others added 3 commits March 5, 2026 16:31
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
@pi0
Copy link
Member

pi0 commented Mar 19, 2026

Thanks for PR ❤️

Replaced picomatch with node:path matchesGlob to avoid extrernal deps.

The original issue was that path.matchesGlob doesn't traverse dot-prefixed segments with **. The fix: compute relative(base, path) before matching, which strips the dot-prefixed base directory so matchesGlob works correctly.

For absolute ignore patterns (e.g. resolve(dir, "folder1")), a startsWith check is used instead of glob matching.

Also added a regression test for node_modules under a dot-prefixed base path.

@pi0 pi0 merged commit b530a65 into unjs:main Mar 19, 2026
1 of 3 checks passed
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.

FS driver: ignore patterns fail in dot-prefixed directories (EMFILE)

2 participants