Registry / http-networking / glob-all

glob-all

JSON →
library3.3.1jsnpmunverified

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-all
INSTALL
IMPORT
SIG · GLOB-ALL
G
glob-all
http-networkingjavascriptv3.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

glob (async)
const glob = require('glob-all'); glob(patterns, options, callback);
import { glob } from 'glob-all';
The primary asynchronous function, exposed as the module's default export in CommonJS environments.
glob.sync
const glob = require('glob-all'); const files = glob.sync(patterns, options);
import { sync } from 'glob-all';
The synchronous version of the globbing function, available as a property on the default export.
default (ESM)
import glob from 'glob-all';
import * as globAll from 'glob-all';
While primarily a CommonJS module, this is the correct way to import if your environment supports CJS-to-ESM interop. The default import provides the async `glob` function, with `sync` available as a property.

Demonstrates synchronous file matching with multiple include and exclude patterns, showing how to re-include specific files within an excluded directory.

const glob = require('glob-all'); const fs = require('fs'); const path = require('path'); // Create dummy files for demonstration fs.mkdirSync('files/x', { recursive: true }); fs.writeFileSync('files/a.txt', 'a'); fs.writeFileSync('files/b.txt', 'b'); fs.writeFileSync('files/c.txt', 'c'); fs.writeFileSync('files/x/y.txt', 'y'); fs.writeFileSync('files/x/z.txt', 'z'); const files = glob.sync([ 'files/**', // include all files/ '!files/x/**', // then, exclude files/x/ 'files/x/z.txt' // then, reinclude files/x/z.txt ]); console.log(files); // Clean up dummy files fs.rmSync('files', { recursive: true, force: true });
Debug
Known issues
gotchaCustom Exclude Pattern Behavior: `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 the order they are provided.
fix
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.
affects: >=1.0.0
gotchaFile Order and Precision: When a file matches multiple patterns, the result from the *more precise* pattern takes precedence. This can affect the final order of files in the output array.
fix
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.
affects: >=1.0.0
gotchaFiltering Directories from Results: By default, `glob-all` returns both files and directories. To exclude directories, you need an extra step.
fix
Use the `mark: true` option in glob options to append a `/` to directory paths, then filter results manually: `files.filter(f => !/\/$/.test(f));`
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'sync')
Attempting to use `glob-all`'s `sync` method (or the default `glob` function) with incorrect import syntax, often when mixing CommonJS `require` with ESM `import` expectations, or destructuring incorrectly.
fix
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.
No files found for pattern(s)
Glob patterns are incorrect, paths are relative to an unexpected working directory, or exclusion patterns are too broad and accidentally exclude all intended files.
fix
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.
Upgrade
Version history
3.3.1latest on npm
Audit
Dependencies
globrequiredCore globbing logic is delegated to node-glob; glob-all acts as a multi-pattern wrapper.
Agent activity
4 hits · last 30 days
node
4
Resources