Closed theoludwig closed 1 week ago
@MoLow
Maybe just expose the dirent insstead of its name to exclude which would enable:
fs.promises.glob("foo/**", { exclude(entry) { return entry.isFile(); })
Maybe just expose the dirent insstead of its name to exclude which would enable:
fs.promises.glob("foo/**", { exclude(entry) { return entry.isFile(); })
You mean exclude
take as argument (entry
) the await fs.promises.stat(entry)
?
That would work, fs.promises.glob("foo/**", { exclude(entry) { return entry.isDirectory(); })
to only get files.
However, that would be a BREAKING CHANGE, probably fine, as it's still experimental, but still worth to point out.
But then we don't have information about filename/path.
Maybe the argument in exclude
should be an object with multiple information about the file/directory (name, relativePath, absolutePath, stats, etc.).
we should probably just add a withFileTypes
option like fs.readDir
has
What is the problem this feature will solve?
Since Node.js v22, with this PR: https://github.com/nodejs/node/pull/51912, it is possible to use
fs.promises.glob
for matching file paths based on specified patterns.However, the results of entries also includes directories, but other famous userland library (e.g: globby) only returns files (not directories).
Example
With a file structure like the following:
And the following code:
It prints:
What is the feature you are proposing to solve the problem?
Add 2 options to
fs.glob
:onlyDirectories
, boolean, default tofalse
.onlyFiles
, boolean, default tofalse
.Both default to
false
, to keep same behavior, so no breaking changes is introduced.Options based on the fast-glob library which
globby
uses under the hood.What alternatives have you considered?