"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.safeReadPackageFromDir = exports.safeReadPackage = exports.fromDir = void 0;
const path = require("path");
const readPackageManifestCB = require("read-package-json");
const util_1 = require("util");
const readPackageManifest = util_1.promisify(readPackageManifestCB);
async function readPkg(pkgPath) {
    try {
        return await readPackageManifest(pkgPath);
    }
    catch (err) {
        if (err['code'])
            throw err; // tslint:disable-line
        const pnpmError = new Error(`${pkgPath}: ${err.message}`);
        pnpmError['code'] = 'ERR_PNPM_BAD_PACKAGE_JSON'; // tslint:disable-line
        throw pnpmError;
    }
}
exports.default = readPkg;
function fromDir(pkgPath) {
    return readPkg(path.join(pkgPath, 'package.json'));
}
exports.fromDir = fromDir;
async function safeReadPackage(pkgPath) {
    try {
        return await readPkg(pkgPath);
    }
    catch (err) {
        if (err.code !== 'ENOENT')
            throw err;
        return null;
    }
}
exports.safeReadPackage = safeReadPackage;
function safeReadPackageFromDir(pkgPath) {
    return safeReadPackage(path.join(pkgPath, 'package.json'));
}
exports.safeReadPackageFromDir = safeReadPackageFromDir;
//# sourceMappingURL=index.js.map