Skip to content

fix(fs/walk): do not apply exts filter to directory entries#7186

Open
LeSingh1 wants to merge 4 commits into
denoland:mainfrom
LeSingh1:fix/walk-exts-filter-includes-dirs
Open

fix(fs/walk): do not apply exts filter to directory entries#7186
LeSingh1 wants to merge 4 commits into
denoland:mainfrom
LeSingh1:fix/walk-exts-filter-includes-dirs

Conversation

@LeSingh1

Copy link
Copy Markdown

Summary

Fixes #6736

When includeDirs is true (the default) and the exts option is set, directory entries were incorrectly being filtered out by the exts check because directories have no file extension. This meant that using walk(path, { exts: ['.ts'] }) would not yield any directory entries at all, even though includeDirs defaults to true.

Before:

// Structure: mydir/ x.ts  subdir/  subdir/y.rs
Array.from(walk("mydir", { exts: [".ts"] }))
// => [{ path: "mydir/x.ts", ... }]
// Root dir and subdir are missing!

After:

Array.from(walk("mydir", { exts: [".ts"] }))
// => [
//   { path: "mydir", isDirectory: true, ... },       // root dir included
//   { path: "mydir/x.ts", isFile: true, ... },       // .ts file included
//   { path: "mydir/subdir", isDirectory: true, ... }, // subdir included
//   // mydir/subdir/y.rs excluded (not .ts)
// ]

Changes

  • fs/walk.ts: When yielding a directory entry (for the root path in both walk and walkSync), pass undefined for exts to the include() helper so that directory paths are not subject to the file-extension filter. The match and skip regexp filters still apply to directories.
  • fs/walk_test.ts: Updated the existing exts tests to include the root directory "." in expected results. Added two new tests (walk() and walkSync()) verifying that subdirectories are included when the exts option is set.
  • fs/testdata/walk/ext_with_subdir/: New testdata directory with x.ts and subdir/y.rs to exercise the subdirectory case.

Test plan

  • Existing exts tests now include the root dir "." in expected results
  • New tests walk() includes subdirs when using exts option and walkSync() includes subdirs when using exts option pass
  • All other walk tests continue to pass

LeSingh1 added 4 commits June 20, 2026 12:12
When includeDirs is true and the exts option is set, directories were
incorrectly being filtered out because they have no file extension.
Directory entries should only be subject to the match and skip filters,
not the exts filter.

Fixes denoland#6736
@github-actions github-actions Bot added the fs label Jun 20, 2026
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.58%. Comparing base (cdf74a8) to head (759bcd2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7186   +/-   ##
=======================================
  Coverage   94.57%   94.58%           
=======================================
  Files         636      637    +1     
  Lines       52142    52150    +8     
  Branches     9401     9401           
=======================================
+ Hits        49315    49324    +9     
- Misses       2249     2250    +1     
+ Partials      578      576    -2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs/walk do not include folders if exts option is given

1 participant