Skip to content

path: add exclude option to matchesGlob method #59061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mag123c
Copy link

@mag123c mag123c commented Jul 14, 2025

This PR enhances the path.matchesGlob() method by adding comprehensive exclude pattern support to provide feature parity with fs.glob() and improve developer experience when filtering paths.

In the current implementation, path.matchesGlob() lacks advanced filtering capabilities, making it difficult for developers to exclude specific paths or directory trees without writing complex, error-prone manual exclusion logic. This limitation creates inconsistency between path matching utilities and forces code duplication across projects.

The updated implementation now includes:

  • Enhanced API with exclude option supporting flexible exclusion patterns through strings, arrays, or custom functions that can filter out matching paths and their descendants
  • Comprehensive exclude pattern types covering simple string exclusions, multiple pattern arrays for complex filtering scenarios, and function-based exclusion logic for advanced use cases
  • Consistent behavior with fs.glob() ensuring unified glob matching experience across file system operations and virtual path filtering
  • Improved developer ergonomics eliminating the need for manual exclusion logic and reducing code complexity when working with path pattern matching
  • Robust test coverage demonstrating exclude functionality across various pattern combinations, edge cases, and integration scenarios

This change resolves #59015 by providing the requested exclude functionality that allows developers to efficiently filter paths without manually implementing complex exclusion patterns, bringing path.matchesGlob() to feature parity with other Node.js glob utilities.

Add support for exclude patterns in path.matchesGlob() to provide consistency with fs.glob().
The exclude option accepts strings, arrays, or functions to filter out matching paths.

Fixes: nodejs#59015
@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. path Issues and PRs related to the path subsystem. labels Jul 14, 2025
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. path Issues and PRs related to the path subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance path.matchesGlob to support exclusion patterns and options (parity with fs.glob)
2 participants