mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
76794ac27a
* chore: add additional testing to esm and cjs smoke * test: updated test suite to include module tests * fix: esm test smoke import * fix: cubic feedback * fix: failing cjs * fix: cjs timeout
42 lines
999 B
JavaScript
42 lines
999 B
JavaScript
const { spawnSync } = require('child_process');
|
|
|
|
const formatCommand = (command, args) => [command].concat(args || []).join(' ');
|
|
|
|
const runCommand = (command, args, options) => {
|
|
const spawnOptions = Object.assign({ encoding: 'utf8' }, options || {});
|
|
const result = spawnSync(command, args || [], spawnOptions);
|
|
|
|
const output = {
|
|
code: result.status,
|
|
stdout: result.stdout || '',
|
|
stderr: result.stderr || '',
|
|
command: formatCommand(command, args),
|
|
cwd: spawnOptions.cwd || process.cwd(),
|
|
};
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
|
|
if (output.code !== 0) {
|
|
const error = new Error(
|
|
[
|
|
'Command failed:',
|
|
` command: ${output.command}`,
|
|
` cwd: ${output.cwd}`,
|
|
` exitCode: ${String(output.code)}`,
|
|
` stdout:\n${output.stdout}`,
|
|
` stderr:\n${output.stderr}`,
|
|
].join('\n')
|
|
);
|
|
error.commandResult = output;
|
|
throw error;
|
|
}
|
|
|
|
return output;
|
|
};
|
|
|
|
module.exports = {
|
|
runCommand,
|
|
};
|