in src/docgen/view/_npm.ts [111:141]
private async runCommand<T = Buffer>(
command: string,
args: readonly string[],
outputTransform: (stderr: readonly Buffer[]) => T,
options?: SpawnOptionsWithoutStdio,
): Promise<CommandResult<T>> {
return new Promise<CommandResult<T>>((ok, ko) => {
const child = spawn(command, args, { ...options, stdio: ['inherit', 'pipe', 'pipe'] });
const stdout = new Array<Buffer>();
child.stdout.on('data', (chunk) => {
stdout.push(Buffer.from(chunk));
});
child.stderr.on('data', (chunk) => {
stdout.push(Buffer.from(chunk));
});
child.once('error', ko);
child.once('close', (exitCode, signal) => {
try {
ok({
command: `${command} ${args.join(' ')}`,
exitCode,
signal,
stdout: outputTransform(stdout),
});
} catch (error) {
ko(error);
}
});
});
}