function findProjectRoot
findProjectRoot(cwd?: string): Task<string, ProjectRootNotFoundFailure>

Walks up from the working directory to the nearest package.json and resolves to its directory.

Missing it is a declared outcome, not a crash. This used to console.log a hint and process.exit(1) from inside a library function — untestable, and unanswerable by the daemon, which serves many projects and must not die because one of them lacks a manifest.

cwd defaults to the working directory, which is what the CLI wants. It is a parameter so the JS API can resolve a project other than the one the host process happens to sit in.

import { findProjectRoot } from './find-project-root.ts';
import * as Failure from '../result/failure.ts';

// Defined, not invoked: walks the real filesystem.
async function resolveRoot() {
  const root = await findProjectRoot().result();
  return Failure.is(root) ? root.code : root; // 'ProjectRootNotFound', or '/home/user/project'
}

Parameters

optional
cwd: string

Return Type

Usage

import { findProjectRoot } from "lib/utils/find-project-root.ts";