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