{"id":10952,"library":"glob-all","title":"glob-all","description":"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.","status":"maintenance","version":"3.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/jpillora/node-glob-all","tags":["javascript","glob","multi","all","manifest","generation","file"],"install":[{"cmd":"npm install glob-all","lang":"bash","label":"npm"},{"cmd":"yarn add glob-all","lang":"bash","label":"yarn"},{"cmd":"pnpm add glob-all","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core globbing logic is delegated to node-glob; glob-all acts as a multi-pattern wrapper.","package":"glob","optional":false}],"imports":[{"note":"The primary asynchronous function, exposed as the module's default export in CommonJS environments.","wrong":"import { glob } from 'glob-all';","symbol":"glob (async)","correct":"const glob = require('glob-all');\nglob(patterns, options, callback);"},{"note":"The synchronous version of the globbing function, available as a property on the default export.","wrong":"import { sync } from 'glob-all';","symbol":"glob.sync","correct":"const glob = require('glob-all');\nconst files = glob.sync(patterns, options);"},{"note":"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.","wrong":"import * as globAll from 'glob-all';","symbol":"default (ESM)","correct":"import glob from 'glob-all';"}],"quickstart":{"code":"const glob = require('glob-all');\nconst fs = require('fs');\nconst path = require('path');\n\n// Create dummy files for demonstration\nfs.mkdirSync('files/x', { recursive: true });\nfs.writeFileSync('files/a.txt', 'a');\nfs.writeFileSync('files/b.txt', 'b');\nfs.writeFileSync('files/c.txt', 'c');\nfs.writeFileSync('files/x/y.txt', 'y');\nfs.writeFileSync('files/x/z.txt', 'z');\n\nconst files = glob.sync([\n  'files/**',      // include all files/\n  '!files/x/**',   // then, exclude files/x/\n  'files/x/z.txt'  // then, reinclude files/x/z.txt\n]);\n\nconsole.log(files);\n\n// Clean up dummy files\nfs.rmSync('files', { recursive: true, force: true });","lang":"javascript","description":"Demonstrates synchronous file matching with multiple include and exclude patterns, showing how to re-include specific files within an excluded directory."},"warnings":[{"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.","message":"Custom 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"File 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the `mark: true` option in glob options to append a `/` to directory paths, then filter results manually: `files.filter(f => !/\\/$/.test(f));`","message":"Filtering Directories from Results: By default, `glob-all` returns both files and directories. To exclude directories, you need an extra step.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'sync')"},{"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.","cause":"Glob patterns are incorrect, paths are relative to an unexpected working directory, or exclusion patterns are too broad and accidentally exclude all intended files.","error":"No files found for pattern(s)"}],"ecosystem":"npm"}