findRoot
findRoot(
startDir,marker,options?):Promise<string|undefined>
Defined in: find-root.ts:95
The nearest ancestor of startDir (itself first) that contains marker —
a file or directory name, or a list of names where any one counts. For
example ".git", "pnpm-workspace.yaml", or ["turbo.json", "nx.json"].
Each marker must be a bare name (no separators, ., .. or empty) or a
TypeError is thrown; so is any filesystem error other than “not there”.
Resolves to undefined when nothing is found, unless options.fallback is
"start". See FindRootOptions; findRootSync is the
synchronous twin. Built on findUpward.
Parameters
Section titled “Parameters”startDir
Section titled “startDir”string
marker
Section titled “marker”string | readonly string[]
options?
Section titled “options?”FindRootOptions = {}
Returns
Section titled “Returns”Promise<string | undefined>
Example
Section titled “Example”import { findRoot, findRootSync } from "@theholocron/fs-utils";
const repoRoot = await findRoot(process.cwd(), ".git");const workspaceRoot = await findRoot(process.cwd(), ["pnpm-workspace.yaml", "turbo.json"]);
// never throws, never undefined: the git root, or the start dir when there is noneconst root = findRootSync(cwd, ".git", { fallback: "start", realpath: true });