fix(fs): do not apply exts filter to directory entries#7186
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7186 +/- ##
==========================================
+ Coverage 94.64% 94.65% +0.01%
==========================================
Files 629 628 -1
Lines 51895 51640 -255
Branches 9373 9323 -50
==========================================
- Hits 49116 48880 -236
+ Misses 2211 2198 -13
+ Partials 568 562 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Two suggestions before merge: 1. Update the
That's now inaccurate for directories, which is exactly what this PR changes. Worth adding a clarifying sentence, e.g.:
2. Test data duplication (optional). The new Otherwise the fix looks correct and complete: because |
Summary
Fixes #6736
When
includeDirsistrue(the default) and theextsoption is set, directory entries were incorrectly being filtered out by theextscheck because directories have no file extension. This meant that usingwalk(path, { exts: ['.ts'] })would not yield any directory entries at all, even thoughincludeDirsdefaults totrue.Before:
After:
Changes
fs/walk.ts: When yielding a directory entry (for the root path in bothwalkandwalkSync), passundefinedforextsto theinclude()helper so that directory paths are not subject to the file-extension filter. Thematchandskipregexp filters still apply to directories.fs/walk_test.ts: Updated the existingextstests to include the root directory"."in expected results. Added two new tests (walk()andwalkSync()) verifying that subdirectories are included when theextsoption is set.fs/testdata/walk/ext_with_subdir/: New testdata directory withx.tsandsubdir/y.rsto exercise the subdirectory case.Test plan
extstests now include the root dir"."in expected resultswalk() includes subdirs when using exts optionandwalkSync() includes subdirs when using exts optionpass