patch-pulse
Version:
Check for outdated npm dependencies
22 lines • 787 B
JavaScript
import { existsSync, readFileSync } from 'fs';
export async function readPackageJson(path) {
if (!existsSync(path)) {
throw new Error(`package.json not found at ${path}`);
}
try {
const contents = readFileSync(path, 'utf-8');
const parsed = JSON.parse(contents);
// Validate that it's actually a package.json
if (typeof parsed !== 'object' || parsed === null) {
throw new Error('package.json must be a valid JSON object');
}
return parsed;
}
catch (error) {
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON in package.json: ${error.message}`);
}
throw new Error(`Error reading package.json: ${error}`);
}
}
//# sourceMappingURL=package.js.map