What is the problem this feature will solve?
Currently, the fs.glob function in Node.js allows specifying advanced options such as exclude patterns, which not only exclude the specified path but also all its descendants from matching results. In contrast, path.matchesGlob only matches a glob pattern to an input string without supporting exclude patterns or additional options.
There is no way to replicate the full matching logic of fs.glob (including exclude semantics) using path.matchesGlob alone on a list of paths, such as when working with a virtual filesystem.
Example:
fs.glob({ include: '**/*', exclude: ['folder_a/folder_b'] }) will exclude folder_a/folder_b and all its contents.
- However, using only
path.matchesGlob, one cannot easily achieve the same exclusion behavior because the exclude pattern only matches the exact path, not its descendants.
What is the feature you are proposing to solve the problem?
- Allow
path.matchesGlob to accept an options argument (e.g., { exclude: [...] }, and/or other options supported by fs.glob).
- Ensure that exclusion patterns work the same way as in
fs.glob, i.e., they exclude the matched path and all its descendants.
- This will enable users to apply consistent glob-matching logic both for real file systems and for lists of paths (e.g., in virtual filesystems or in-memory path lists).
Example API:
const include = '**/*';
const exclude = ['folder_a/folder_b'];
const path = 'folder_a/folder_b/file.js';
path.matchesGlob(path, include, { exclude }); // returns false
What alternatives have you considered?
- Manually replicating exclusion logic by writing custom code to check if a path is a descendant of any excluded folder. This approach is error-prone and leads to code duplication.
The proposed enhancement would provide parity and consistency between fs.glob and path.matchesGlob, improving developer experience and flexibility.
What is the problem this feature will solve?
Currently, the
fs.globfunction in Node.js allows specifying advanced options such asexcludepatterns, which not only exclude the specified path but also all its descendants from matching results. In contrast,path.matchesGlobonly matches a glob pattern to an input string without supporting exclude patterns or additional options.There is no way to replicate the full matching logic of
fs.glob(including exclude semantics) usingpath.matchesGlobalone on a list of paths, such as when working with a virtual filesystem.Example:
fs.glob({ include: '**/*', exclude: ['folder_a/folder_b'] })will excludefolder_a/folder_band all its contents.path.matchesGlob, one cannot easily achieve the same exclusion behavior because the exclude pattern only matches the exact path, not its descendants.What is the feature you are proposing to solve the problem?
path.matchesGlobto accept an options argument (e.g.,{ exclude: [...] }, and/or other options supported byfs.glob).fs.glob, i.e., they exclude the matched path and all its descendants.Example API:
What alternatives have you considered?
The proposed enhancement would provide parity and consistency between
fs.globandpath.matchesGlob, improving developer experience and flexibility.