import { cwd } from "node:process"; import { fileURLToPath, pathToFileURL } from "node:url"; import escalade from "escalade"; export function local(file: string) { return fileURLToPath( new URL(`../node_modules/.bin/${file}`, import.meta.url), ); } export async function getPackageJSONPath(): Promise { const pkgPath = await escalade(cwd(), (dir, files) => { return files.find((file) => file === "package.json"); }); if (!pkgPath) { throw new Error("No package.json found"); } return pkgPath; } export async function getPackageJSON() { const pkg = await escalade(cwd(), (dir, files) => { return files.find((file) => file === "package.json"); }); if (!pkg) { throw new Error("No package.json found"); } const pkgPath = pathToFileURL(pkg); const { default: json } = await import(pkgPath.toString(), { with: { type: "json" }, }); return json; }