UNPKG

yarn-changed-workspaces

Version:

An utility to show changed workspaces and their dependants

20 lines (17 loc) 663 B
const { resolve } = require("path"); const { readJSONFile } = require("./readJSONFile"); const { findWorkspaces } = require("./findWorkspaces"); const { keyById } = require("./keyById"); const getWorkspaces = async (rootPath) => { const pkgPath = resolve(rootPath, "package.json"); const pkg = await readJSONFile(pkgPath); const patterns = (Array.isArray(pkg.workspaces) ? pkg.workspaces : pkg.workspaces.packages) || []; const workspaces = await Promise.all( patterns.map(async (pattern) => findWorkspaces({ pattern, rootPath })) ); return workspaces.flat().reduce(keyById, {}); }; module.exports.getWorkspaces = getWorkspaces;