glob-all

3.3.1 · maintenance · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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 });

view raw JSON →