UNPKG

workspace-tools

Version:

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

54 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageInfosAsync = exports.getPackageInfos = void 0; const getWorkspaces_1 = require("./workspaces/getWorkspaces"); const getPackageInfo_1 = require("./getPackageInfo"); /** * Read all the package.json files in a monorepo. Only works for monorepos which * use a supported workspace manager. * @param cwd Start looking for the workspace manager config from here */ function getPackageInfos(cwd) { const packageInfos = {}; const workspacePackages = (0, getWorkspaces_1.getWorkspaces)(cwd); if (workspacePackages.length) { for (const pkg of workspacePackages) { packageInfos[pkg.name] = pkg.packageJson; } } else { const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd); if (rootInfo) { packageInfos[rootInfo.name] = rootInfo; } } return packageInfos; } exports.getPackageInfos = getPackageInfos; /** * Read all the package.json files in a monorepo. Only works for monorepos which * use a supported workspace manager. * * NOTE: As of writing, this will start promises to read all package.json files in parallel, * without direct concurrency control. * * @param cwd Start looking for the workspace manager config from here */ async function getPackageInfosAsync(cwd) { const packageInfos = {}; const workspacePackages = await (0, getWorkspaces_1.getWorkspacesAsync)(cwd); if (workspacePackages.length) { for (const pkg of workspacePackages) { packageInfos[pkg.name] = pkg.packageJson; } } else { const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd); if (rootInfo) { packageInfos[rootInfo.name] = rootInfo; } } return packageInfos; } exports.getPackageInfosAsync = getPackageInfosAsync; //# sourceMappingURL=getPackageInfos.js.map