3 const isWin = process.platform === 'win32';
5 function notFoundError(original, syscall) {
6 return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
9 syscall: `${syscall} ${original.command}`,
10 path: original.command,
11 spawnargs: original.args,
15 function hookChildProcess(cp, parsed) {
20 const originalEmit = cp.emit;
22 cp.emit = function (name, arg1) {
23 // If emitting "exit" event and exit code is 1, we need to check if
24 // the command exists and emit an "error" instead
25 // See https://github.com/IndigoUnited/node-cross-spawn/issues/16
26 if (name === 'exit') {
27 const err = verifyENOENT(arg1, parsed, 'spawn');
30 return originalEmit.call(cp, 'error', err);
34 return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params
38 function verifyENOENT(status, parsed) {
39 if (isWin && status === 1 && !parsed.file) {
40 return notFoundError(parsed.original, 'spawn');
46 function verifyENOENTSync(status, parsed) {
47 if (isWin && status === 1 && !parsed.file) {
48 return notFoundError(parsed.original, 'spawnSync');