Files
lcbp3.np-dms.work/frontend/node_modules/@antfu/ni/dist/shared/ni.C4mrCGPc.mjs
2025-09-21 20:29:15 +07:00

24 lines
558 B
JavaScript
Executable File

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 };