TypeScript/src/harness/findUpDir.ts
Eli Barzilay fa2ad1a35a Fix findUpDir.ts and uses
Missed a bunch of stuff in #46414 (556098e).
2021-11-01 16:45:49 -04:00

22 lines
804 B
TypeScript

namespace Utils {
const { join, resolve, dirname } = require("path") as typeof import("path");
const { existsSync } = require("fs") as typeof import("fs");
// search directories upward to avoid hard-wired paths based on the
// build tree (same as scripts/build/findUpDir.js)
export function findUpFile(name: string): string {
let dir = __dirname;
while (true) {
const fullPath = join(dir, name);
if (existsSync(fullPath)) return fullPath;
const up = resolve(dir, "..");
if (up === dir) return name; // it'll fail anyway
dir = up;
}
}
export const findUpRoot: { (): string; cached?: string; } = () =>
findUpRoot.cached ||= dirname(findUpFile("Gulpfile.js"));
}