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
36 lines
894 B
JavaScript
36 lines
894 B
JavaScript
import { spawnSync } from 'node:child_process';
|
|
|
|
const formatCommand = (command, args) => [command, ...(args || [])].join(' ');
|
|
|
|
export const runCommand = (command, args = [], options = {}) => {
|
|
const spawnOptions = { 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) {
|
|
throw new Error(
|
|
[
|
|
'Command failed:',
|
|
` command: ${output.command}`,
|
|
` cwd: ${output.cwd}`,
|
|
` exitCode: ${String(output.code)}`,
|
|
` stdout:\n${output.stdout}`,
|
|
` stderr:\n${output.stderr}`,
|
|
].join('\n')
|
|
);
|
|
}
|
|
|
|
return output;
|
|
};
|