Skip to content

Conversation

@MatricalDefunkt
Copy link
Contributor

This PR adds a followSymlinks option to fs.glob and fs.globSync, allowing recursive directory traversal into symbolic links when enabled.

Changes

  • Modified lib/internal/fs/glob.js:
    • Added followSymlinks to Glob constructor options.
    • Updated Glob class to handle followSymlinks: true.
    • In both synchronous and asynchronous traversal methods, added logic to resolve symbolic links using stat when followSymlinks is enabled. If the symlink points to a directory, it is now traversed.
  • Updated documentation in doc/api/fs.md.
  • Added tests in test/parallel/test-fs-glob.mjs to verify followSymlinks: true behavior.

Fixes: #61033

@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 Jan 8, 2026
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 94.80519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.52%. Comparing base (ae5cbda) to head (7b0c22d).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/fs/glob.js 94.80% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61317      +/-   ##
==========================================
- Coverage   88.54%   88.52%   -0.03%     
==========================================
  Files         704      704              
  Lines      208753   208796      +43     
  Branches    40283    40285       +2     
==========================================
- Hits       184849   184835      -14     
- Misses      15907    15979      +72     
+ Partials     7997     7982      -15     
Files with missing lines Coverage Δ
lib/internal/fs/glob.js 91.72% <94.80%> (+0.33%) ⬆️

... and 46 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.


describe('glob follow', () => {
test('should return matched files in symlinked directory when follow is true', async () => {
if (common.isWindows) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why we completely bail on this test if we're on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The setup function excluded it specifically as well. I did not question why.

From what I am understanding, symlinks need admin permissions or developer mode enabled on Windows which is perhaps why the test does not exist for it.

Comment on lines +1118 to +1119
* `followSymlinks` {boolean} `true` to traverse matching symbolic links to directories,
`false` otherwise. **Default:** `false`.
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to update the changes entry above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should be the version tag for the change?

Comment on lines +19 to +20
const { lstatSync, readdirSync, statSync: fsStatSync } = require('fs');
const { lstat, readdir, stat: fsStat } = require('fs/promises');
Copy link
Member

Choose a reason for hiding this comment

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

Why are these being renamed?

Copy link
Contributor Author

@MatricalDefunkt MatricalDefunkt Jan 9, 2026

Choose a reason for hiding this comment

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

Oh that was for my reference. I will rename and push. Sorry!
I won't be pushing. Many locations in the file refer to a variable named stat. keeping the function name as the same would reduce readability.

If you believe that I should make the change, do let me know, I'll commit and push ASAP :)

Comment on lines 436 to 441
try {
const stat = fsStatSync(join(fullpath, entry.name));
isDirectory = stat.isDirectory();
} catch {
// ignore
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't an error here be bubbled up? If the user explicitly asked for us to follow symlinks, and we can't do that, wouldn't they expect some kind of indication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, we should inform the user. Sorry for the oversight

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should emit a warning or an error would be more appropriate? I believe an error is better.

@MatricalDefunkt MatricalDefunkt force-pushed the feature/glob-recurse-symlinks branch from e611924 to 7b0c22d Compare January 9, 2026 14:30
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.

Allow fs.glob to traverse symbolic links to directories

4 participants