import fs from "fs"; import path from "path"; import { StringDictionary } from "../types"; export const getPackageJson = function(projectPath: string): StringDictionary { const packagePath = path.join(projectPath, "package.json"); let packageJson: string = ""; try { packageJson = fs.readFileSync(packagePath, "utf-8"); } catch (err) { throw new Error(`${packagePath} not exist`); } let packageJsonParsed: StringDictionary = {}; try { packageJsonParsed = JSON.parse(packageJson); } catch (err) { throw new Error("The package.json is malformed"); } return packageJsonParsed; };