https://github.com/Microsoft/TypeScript
Raw File
Tip revision: 55e13e9115b3cc5458d76c39da1211dc28d7b51f authored by TypeScript Bot on 20 January 2022, 00:53:53 UTC
Bump version to 4.5.5 and LKG
Tip revision: 55e13e9
findUpDir.ts
namespace findUpDir {
    import { join, resolve, dirname } from "path";
    import { existsSync } from "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) {
        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"));
}
back to top