mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Avoid hard-wired build-tree paths
Instead, search for stuff up the directory tree, with the main functionality being to look for `Gulpfile.js` and assume the resulting directory is the root. (Unfortunatley, this is implemented twice, one in `scripts` and another in `src`. It's not possible to use a single implementation for both since that would require assuming a directory structure which this is intended to avoid.) Also, in `scripts/build/projects.js`, abstracdt common exec functionality into a local helper, and use full paths based on the above search instead of assuming relative paths assuming CWD being in the project root.
This commit is contained in:
21
src/harness/findUpDir.ts
Normal file
21
src/harness/findUpDir.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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"));
|
||||
}
|
||||
Reference in New Issue
Block a user