@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
22 lines (21 loc) • 670 B
JavaScript
import { runShellCommand } from '../terminal/shell.js';
/**
* Get a list of all NPM workspaces in the given mono-repo directory using npm's CLI.
*
* @category Node : Npm
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export async function queryNpmWorkspace(cwd) {
const queryOutput = await runShellCommand('npm query .workspace', {
cwd,
rejectOnError: true,
});
try {
return JSON.parse(queryOutput.stdout);
/* node:coverage ignore next 3 */
}
catch {
throw new Error(`Failed to read npm workspace data for '${cwd}'`);
}
}