24 lines
558 B
JavaScript
Raw Normal View History

2026-05-31 13:21:13 +02:00
import fs from 'node:fs';
import { resolve } from 'node:path';
import process from 'node:process';
function getPackageJSON(ctx) {
const cwd = ctx?.cwd ?? process.cwd();
const path = resolve(cwd, "package.json");
if (fs.existsSync(path)) {
try {
const raw = fs.readFileSync(path, "utf-8");
const data = JSON.parse(raw);
return data;
} catch (e) {
if (!ctx?.programmatic) {
console.warn("Failed to parse package.json");
process.exit(1);
}
throw e;
}
}
}
export { getPackageJSON as g };