UNPKG

workspace-tools

Version:

A collection of tools that are useful in a git-controlled monorepo that is managed by one of these software:

28 lines (27 loc) 1.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const infoFromPackageJson_1 = require("./infoFromPackageJson"); const workspaces_1 = require("./workspaces/workspaces"); function getPackageInfos(cwd) { const packageJsonFiles = workspaces_1.getAllPackageJsonFiles(cwd); const packageInfos = {}; if (packageJsonFiles && packageJsonFiles.length > 0) { packageJsonFiles.forEach((packageJsonPath) => { try { const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8")); packageInfos[packageJson.name] = infoFromPackageJson_1.infoFromPackageJson(packageJson, packageJsonPath); } catch (e) { // Pass, the package.json is invalid throw new Error(`Invalid package.json file detected ${packageJsonPath}: ${e.message}`); } }); return packageInfos; } return {}; } exports.getPackageInfos = getPackageInfos;