epiphany/node_modules/read-pkg/index.js
2023-12-09 22:48:07 -08:00

26 lines
704 B
JavaScript

import fs, {promises as fsAsync} from 'fs';
import path from 'path';
import parseJson from 'parse-json';
import normalizePackageData from 'normalize-package-data';
export async function readPackageAsync({cwd = process.cwd(), normalize = true} = {}) {
const filePath = path.resolve(cwd, 'package.json');
const json = parseJson(await fsAsync.readFile(filePath, 'utf8'));
if (normalize) {
normalizePackageData(json);
}
return json;
}
export function readPackageSync({cwd = process.cwd(), normalize = true} = {}) {
const filePath = path.resolve(cwd, 'package.json');
const json = parseJson(fs.readFileSync(filePath, 'utf8'));
if (normalize) {
normalizePackageData(json);
}
return json;
}