You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support negated pattern-list syntax in fs.glob #63959
Node's fs.glob() accepts an array of patterns, but entries beginning with ! are not interpreted as exclusions:
globSync(['src/**/*.js','!src/generated/**',]);
Node.js does support negative extglobs such as !(pattern), but that is a different feature. An extglob negates part of a single pattern while negated pattern-list syntax applies an exclusion to the matches (based on other entries in the array).
Node.js also provides options.exclude, but it cannot fully represent ordered pattern lists where a later positive pattern re-includes a path.
Ecosystem
Leading-! entries are supported by packages such as globby and tinyglobby:
Supporting this syntax would make migration to the built-in API easier and allow existing pattern arrays from configuration files and CLI arguments to be reused unchanged.
What feature are you proposing?
When pattern is an array, interpret entries beginning with ! as negated pattern-list entries:
globSync(['src/**/*.js','!src/generated/**',]);
Patterns should be processed in order:
A positive pattern adds matching paths.
A negated pattern removes matching paths.
A later positive pattern can re-include previously removed paths.
I came across this request recently, while attempting to replace an outdated dependency with the Node.js built-in function. I worked around the issue with a custom callback as shown below...
... and the need to reconstruct cwd-relative paths. I'd be glad to see negated pattern-list syntax supported in node:js directly — or an easier way to handle the situation above. Thank you!
Aside, for anyone trying to use my globCompat function above: I also had to replace some trailing ** suffixes in my patterns, such as:
I'm not sure if that's a bug, or non-standard syntax... our project previously used the ** syntax in globby, and had to update it for node:fs. Easy fix but also easy to miss.
Activity
Delapouite commentedon Jun 18, 2026
Related PR adding documentation on supported patterns that should probably adjusted and merged afterwards?
#58988
avivkeller commentedon Jun 19, 2026
@TheAlexLichter Node.js supports that functionality with
!(my_negated_pattern), not!my_negated_pattern.e.g.,
TheAlexLichter commentedon Jun 20, 2026
@avivkeller it does support negative extglobs but not the negated pattern-list syntax (e.g.
globSync(['src/**/*.js', '!src/generated/**'])🤔Happy to raise a new issue or update this one with a more precise description.
[-]Support negation patterns in `fs.glob`[/-][+]Support negated pattern-list syntax in `fs.glob`[/+]donmccurdy commentedon Sep 1, 2026
I came across this request recently, while attempting to replace an outdated dependency with the Node.js built-in function. I worked around the issue with a custom callback as shown below...
... but it took me several tries to get this right with order-sensitive inputs ...
... and the need to reconstruct cwd-relative paths. I'd be glad to see negated pattern-list syntax supported in
node:jsdirectly — or an easier way to handle the situation above. Thank you!Aside, for anyone trying to use my
globCompatfunction above: I also had to replace some trailing**suffixes in my patterns, such as:I'm not sure if that's a bug, or non-standard syntax... our project previously used the
**syntax in globby, and had to update it fornode:fs. Easy fix but also easy to miss.