fix(fs): walk does not apply exts filter to directories#7167
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
walk and walkSync's include() check ran the exts filter against the directory name when deciding whether to yield a directory entry. Directories generally don't have file extensions, so any `exts` option effectively dropped every directory from the output, even when includeDirs:true was set (the default). Pass undefined for exts in the includeDirs branch so the filter only applies to file entries. The match and skip regex filters still apply to directories. Symlink emission (the !followSymlinks branch) is unchanged because a symlink's name still has an extension just like the file or directory it points to. Existing 'walk() accepts ext option as strings' tests are updated to include the root directory in the expected entries (default includeDirs:true). Two new tests pin the includeDirs:false case so the intent is explicit. Fixes denoland#6736
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7167 +/- ##
=======================================
Coverage 94.57% 94.57%
=======================================
Files 636 636
Lines 52142 52142
Branches 9401 9401
=======================================
Hits 49315 49315
Misses 2249 2249
Partials 578 578 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6736.
walkandwalkSyncran theextsfilter against the directory name ininclude()when deciding whether to yield a directory entry. Directories generally don't have file extensions, so anyextsoption effectively dropped every directory from the output, even withincludeDirs:true(the default).Repro before the patch:
After:
The fix passes
undefinedforextsin theincludeDirsbranch of bothwalkandwalkSync. Thematchandskipregex filters still apply to directories. The!followSymlinkssymlink emission branch is unchanged because a symlink's name still has an extension just like the target.Tests:
walk() / walkSync() accepts ext option as stringstests updated to include the root directory in the expected entries (the defaultincludeDirs:truenow actually yields it).includeDirs:falsecase so the intent stays explicit.All ext-related tests pass. The four pre-existing
* regExpsfailures infs/walk_test.tsreproduce onorigin/main(verified by stashing the patch and re-running) so they're unrelated.