"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPackageJson = getPackageJson;

var _fs = require("fs");

var _path = _interopRequireDefault(require("path"));

var _constants = require("../constants");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Reads and parses the package.json file in the specified directory or returns undefined if it doesn't exist
 *
 * @param cwd The working directory
 */
async function getPackageJson(cwd) {
  try {
    const packageJsonRaw = await _fs.promises.readFile(_path.default.join(cwd, _constants.PACKAGE_JSON_FILENAME), "utf-8");
    return JSON.parse(packageJsonRaw);
  } catch (error) {
    if (error.code !== "ENOENT") {
      throw error;
    } // If the file is not available, packageJson will
    // be undefined in the coatManifest

  }
}