1import { join, resolve, dirname } from "path"; 2import { existsSync } from "fs"; 3import url from "url"; 4 5const __filename = url.fileURLToPath(new URL(import.meta.url)); 6const __dirname = dirname(__filename); 7 8// search directories upward to avoid hard-wired paths based on the 9// build tree (same as src/harness/findUpDir.ts) 10 11/** 12 * @param {string} name 13 * @returns {string} 14 */ 15export function findUpFile(name) { 16 let dir = __dirname; 17 while (true) { 18 const fullPath = join(dir, name); 19 if (existsSync(fullPath)) return fullPath; 20 const up = resolve(dir, ".."); 21 if (up === dir) return name; // it'll fail anyway 22 dir = up; 23 } 24} 25 26/** @type {string | undefined} */ 27let findUpRootCache; 28 29export const findUpRoot = () => findUpRootCache || (findUpRootCache = dirname(findUpFile("Gulpfile.mjs"))); 30