mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-13 04:57:55 -06:00
This eliminates a significant number of dependencies, eliminating all npm audit issues, speeding up `npm ci` by 20%, and overall making the build faster (faster startup, direct code is faster than streams, etc) and clearer to understand. I'm finding it much easier to make build changes for the module transform with this; I can more clearly indicate task dependencies and prevent running tasks that don't need to be run. Given we're changing our build process entirely (new deps, new steps), it seems like this is a good time to change things up.
30 lines
870 B
JavaScript
30 lines
870 B
JavaScript
import { join, resolve, dirname } from "path";
|
|
import { existsSync } from "fs";
|
|
import url from "url";
|
|
|
|
const __filename = url.fileURLToPath(new URL(import.meta.url));
|
|
const __dirname = dirname(__filename);
|
|
|
|
// search directories upward to avoid hard-wired paths based on the
|
|
// build tree (same as src/harness/findUpDir.ts)
|
|
|
|
/**
|
|
* @param {string} name
|
|
* @returns {string}
|
|
*/
|
|
export function findUpFile(name) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
/** @type {string | undefined} */
|
|
let findUpRootCache;
|
|
|
|
export const findUpRoot = () => findUpRootCache || (findUpRootCache = dirname(findUpFile("Herebyfile.mjs")));
|