glob-all extends the functionality of the popular `node-glob` library by allowing developers to provide an array of multiple glob patterns instead of a single one. This enables more complex file selection logic, including robust pattern-level exclusion patterns (e.g., `!files/x/**`) that are evaluated sequentially, a feature not natively available in `node-glob`'s single-pattern API. It provides both asynchronous and synchronous APIs, mirroring `node-glob`'s interface. The current stable version is 3.3.1, with the latest release (in 2024) primarily focusing on dependency updates, indicating a maintenance-level release cadence. A key differentiator is its sophisticated handling of pattern precedence for duplicate files, where the result from a more precise pattern takes priority. Additionally, it optimizes performance across multiple patterns by internally leveraging `node-glob`'s `statCache` option, preventing redundant file system lookups. This makes it suitable for build systems and manifest generation where complex, ordered file selections are required.
npm install glob-allVerified import paths — ran on the pinned version, not inferred.
Demonstrates synchronous file matching with multiple include and exclude patterns, showing how to re-include specific files within an excluded directory.
Understand that `glob-all`'s `!` prefix on a pattern (e.g., `!files/x/**`) provides pattern-level exclusion, which differs from `node-glob`'s in-pattern `!` negation. Patterns are processed in order, so later patterns can re-include files previously excluded.
Order your patterns carefully if you need specific files to appear at the top of the results. Place more precise patterns earlier in the array if their matches should take precedence.
Use the `mark: true` option in glob options to append a `/` to directory paths, then filter results manually: `files.filter(f => !/\/$/.test(f));`
For CommonJS, use `const glob = require('glob-all');` and then `glob.sync(...)` or `glob(...)`. For ESM, use `import glob from 'glob-all';` and then `glob.sync(...)` or `glob(...)`, ensuring your environment supports CJS-to-ESM interop.Verify patterns against your actual file structure. Ensure your current working directory (CWD) is where you expect the patterns to resolve from. Test simpler patterns first to isolate issues, and remember that `glob-all` processes patterns sequentially, meaning exclusions can override previous inclusions.