Skip to content

fs: apply function exclude to glob results#63049

Open
Kelpy2004 wants to merge 1 commit intonodejs:mainfrom
Kelpy2004:codex/fix-glob-function-exclude-results
Open

fs: apply function exclude to glob results#63049
Kelpy2004 wants to merge 1 commit intonodejs:mainfrom
Kelpy2004:codex/fix-glob-function-exclude-results

Conversation

@Kelpy2004
Copy link
Copy Markdown

Function-form exclude callbacks were applied while queuing subpatterns, but some terminal result paths were added directly to the result set. That meant files matched by terminal ** or terminal child patterns could bypass an exclude(path) callback that matched the full relative path.

For example, globSync('**', { cwd, exclude: (path) => path === 'a/skip.txt' }) could still include a/skip.txt.

This routes result additions through a shared helper that applies function-form excludes before recording sync and async glob results, while preserving the existing array-exclude filtering in ResultSet.

Added coverage for:

  • fs.globSync()
  • callback fs.glob()
  • fs.promises.glob()
  • terminal ** results
  • terminal pattern results

Validation performed locally:

  • node --check lib/internal/fs/glob.js
  • node --check test/parallel/test-fs-glob.mjs
  • standalone reproduction against installed Node v24.11.1 confirmed the pre-fix behavior still returns an excluded nested file

I could not run the patched Node test binary because this sparse checkout does not include a built local node executable.

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Apr 30, 2026
@Kelpy2004 Kelpy2004 force-pushed the codex/fix-glob-function-exclude-results branch from 4882cfd to de11752 Compare May 1, 2026 13:20
@Kelpy2004
Copy link
Copy Markdown
Author

I pushed an update that adds coverage for withFileTypes: true as well, so the regression tests now cover string and Dirent result paths across fs.globSync(), callback fs.glob(), and fs.promises.glob().

The currently visible GitHub Actions runs are all action_required, which means they are waiting for maintainer approval to run on this forked PR rather than failing due to test output.

Local validation:

  • node --check lib/internal/fs/glob.js
  • node --check test/parallel/test-fs-glob.mjs
  • standalone reproduction against installed Node v24.11.1 still shows the pre-fix bug (exclude does not remove a nested terminal ** result)

@Kelpy2004
Copy link
Copy Markdown
Author

@mcollina when you have a moment, could you please take a look at this fs.glob fix? It builds on the recent followSymlinks glob work and covers the function-form exclude callback being bypassed for terminal results.

The GitHub Actions runs are currently waiting for maintainer approval on this forked PR, so a review/CI approval would be appreciated. Happy to adjust the patch if you prefer a different shape before merge.

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2026
@Kelpy2004 Kelpy2004 force-pushed the codex/fix-glob-function-exclude-results branch from de11752 to 88d0ea5 Compare May 5, 2026 10:39
@Kelpy2004 Kelpy2004 requested a review from mcollina May 5, 2026 10:47
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 82.14286% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.69%. Comparing base (4744070) to head (88d0ea5).
⚠️ Report is 99 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/fs/glob.js 82.14% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63049      +/-   ##
==========================================
+ Coverage   89.66%   89.69%   +0.03%     
==========================================
  Files         706      712       +6     
  Lines      219370   221268    +1898     
  Branches    42065    42397     +332     
==========================================
+ Hits       196694   198464    +1770     
- Misses      14586    14627      +41     
- Partials     8090     8177      +87     
Files with missing lines Coverage Δ
lib/internal/fs/glob.js 91.58% <82.14%> (+0.10%) ⬆️

... and 110 files with indirect coverage changes

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

Signed-off-by: Aryan Katiyar <aryankatiyar613@gmail.com>
@Kelpy2004 Kelpy2004 force-pushed the codex/fix-glob-function-exclude-results branch from 88d0ea5 to f8c0188 Compare May 5, 2026 16:54
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

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

Labels

fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants