glob-parent
Extract the non-magic parent path from a glob pattern
Repository Health
Technical Analysis
glob-parent is a tiny utility maintained by the Gulp team that takes a glob pattern (like foo/*/bar.js or src/{a,b}/**) and returns the deepest directory path that contains no glob syntax — the part of the path a file watcher or glob engine can safely treat as a real, existing directory to scan or watch.
It is a foundational dependency in the JavaScript build-tooling ecosystem, used internally by chokidar, globby, fast-glob, and dozens of other packages to determine which real filesystem directories need to be watched or read before glob matching is applied against the files found there.
What You Get
- A single function that returns the static parent directory of any glob pattern
- Correct handling of brace
{}and bracket[]enclosures that contain path separators - Windows path separator normalization (backslash-to-slash flipping) via an opt-out
flipBackslashesoption - Escape-character handling so escaped glob metacharacters in the input don’t get misinterpreted
- Zero-dependency-adjacent design (only depends on
is-glob)
Common Use Cases
- Determining which directories a file watcher (like chokidar) needs to subscribe to before running glob matching
- Resolving the real base directory for glob-based file inclusion/exclusion in build tools (Gulp, Webpack loaders, linters)
- Powering glob-matching libraries (fast-glob, globby) that need to know where to start a filesystem walk
- Validating or normalizing user-supplied glob patterns before they’re passed to a full glob engine
Under The Hood
Architecture - The entire implementation lives in a single index.js file exporting one function. It first normalizes Windows path separators, appends a dummy path segment to preserve trailing-separator information through Node’s path.posix.dirname, then repeatedly calls dirname() in a loop, checking each resulting path with an isGlobby() helper (which detects unbalanced parens, leading brace/bracket characters, and delegates to the is-glob package for anything else) until it lands on a segment containing no glob syntax. A separate isEnclosure() helper special-cases patterns ending in a {...} or [...] block that itself contains a path separator, so cases like foo/{bar,baz/qux} resolve correctly.
Tech Stack - Plain, dependency-light Node.js (CommonJS) with a single runtime dependency (is-glob). Testing uses Mocha with nyc for coverage and ESLint (eslint-config-gulp) enforced as a pretest step.
Code Quality - The test/ suite covers a wide matrix of glob patterns (braces, brackets, escaped characters, Windows paths, edge cases like trailing separators) given the deceptively tricky nature of correctly parsing glob syntax boundaries. The code itself is compact, well-commented at each branch, and has remained essentially unchanged for years, reflecting a stable, correctly-solved narrow problem rather than active feature development.
API Design - The API is a single function taking a string and an optional options object, returning a string — about as low-friction as an API surface can get. The one configurable option (flipBackslashes) is scoped tightly to a real cross-platform edge case rather than general-purpose configuration, keeping the surface minimal and predictable.
Used by 2 apps in this directory
APITable
Low Code Platforms · Databases
API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.
TinaCMS
CMS
An open-source, Git-backed headless CMS that gives editors a live visual editing UI over Markdown, MDX, JSON, and YAML content while developers keep everything in version control.