/
githubmirror
/
TypeScript
Обзор
Документация
Войти
/
githubmirror
/
TypeScript
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/build/findUpDir.mjs
33 строки
887 B
Jake Bailey
Update dprint, don't force multiline imports for imports of single name (#58038)
02 апр 2024, 20:58
Не верифицирован
02 апр 2024, 20:58
4cedfe4
Код
Авторство
О чём код?
import { existsSync } from "fs"; import { dirname, join, resolve, } from "path"; 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")));