• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { existsSync } from "fs";
2import { dirname, join, resolve } from "path";
3
4// search directories upward to avoid hard-wired paths based on the
5// build tree (same as scripts/build/findUpDir.js)
6
7export function findUpFile(name: string): string {
8    let dir = __dirname;
9    while (true) {
10        const fullPath = join(dir, name);
11        if (existsSync(fullPath)) return fullPath;
12        const up = resolve(dir, "..");
13        if (up === dir) return name; // it'll fail anyway
14        dir = up;
15    }
16}
17
18export const findUpRoot: { (): string; cached?: string; } = () =>
19    findUpRoot.cached ||= dirname(findUpFile("Herebyfile.mjs"));
20