Node.js filesystem utility
@stackline/find-parent-dir
Find the nearest parent containing a file or directory. Keep the established callback and sync API, or use native ESM and Promise support with correct filesystem errors.
npm install @stackline/find-parent-dir
Executable example builder
Traversal planner
Distinct candidate paths
nearest first
Generated program
Compatibility boundary
Textual traversal stays textual.
The supplied path is checked first, then reduced one path part at a time. Results retain upstream separators and symlink aliases; the implementation does not call realpath or normalize the returned directory.
findParentDir(start, clue, callback)
findParentDir.sync(start, clue)
findParentDir.promise(start, clue)
ENOENT and ENOTDIR continue traversal. Access denial, symlink loops, and other filesystem errors stop at the failing boundary and retain the original error object.
Public surface
Three APIs, one traversal contract
| API | Result | Error | Availability |
|---|---|---|---|
findParentDir(start, clue, cb) | cb(null, directory | null) | cb(error) | Historical |
findParentDir.sync(start, clue) | string | null | throws | Historical |
findParentDir.promise(start, clue) | Promise<string | null> | rejects | Additive |
Release evidence
Compatibility is measured.
The release gate checks behavior, package shape, compiler boundaries, platforms, and the installed artifact.
- 600
- differential path searches against the frozen upstream release
- 100%
- core statements, branches, functions, and lines
- 3 OS
- Linux, macOS, and Windows filesystem behavior in CI
- 0
- runtime dependencies in the published package
Drop-in adoption
Keep existing imports.
Use an npm alias when changing application source is not desirable. The installed implementation is Stackline while the dependency key remains find-parent-dir.
npm install find-parent-dir@npm:@stackline/find-parent-dir
Open the migration guide
Inspect the release