diff options
Diffstat (limited to 'node_modules/cross-spawn/lib/enoent.js')
-rw-r--r-- | node_modules/cross-spawn/lib/enoent.js | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/node_modules/cross-spawn/lib/enoent.js b/node_modules/cross-spawn/lib/enoent.js index d0a193aec..14df9b623 100644 --- a/node_modules/cross-spawn/lib/enoent.js +++ b/node_modules/cross-spawn/lib/enoent.js @@ -1,43 +1,37 @@ 'use strict'; -var isWin = process.platform === 'win32'; -var resolveCommand = require('./util/resolveCommand'); - -var isNode10 = process.version.indexOf('v0.10.') === 0; - -function notFoundError(command, syscall) { - var err; - - err = new Error(syscall + ' ' + command + ' ENOENT'); - err.code = err.errno = 'ENOENT'; - err.syscall = syscall + ' ' + command; - - return err; +const isWin = process.platform === 'win32'; + +function notFoundError(original, syscall) { + return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), { + code: 'ENOENT', + errno: 'ENOENT', + syscall: `${syscall} ${original.command}`, + path: original.command, + spawnargs: original.args, + }); } function hookChildProcess(cp, parsed) { - var originalEmit; - if (!isWin) { return; } - originalEmit = cp.emit; - cp.emit = function (name, arg1) { - var err; + const originalEmit = cp.emit; + cp.emit = function (name, arg1) { // If emitting "exit" event and exit code is 1, we need to check if // the command exists and emit an "error" instead - // See: https://github.com/IndigoUnited/node-cross-spawn/issues/16 + // See https://github.com/IndigoUnited/node-cross-spawn/issues/16 if (name === 'exit') { - err = verifyENOENT(arg1, parsed, 'spawn'); + const err = verifyENOENT(arg1, parsed, 'spawn'); if (err) { return originalEmit.call(cp, 'error', err); } } - return originalEmit.apply(cp, arguments); + return originalEmit.apply(cp, arguments); // eslint-disable-line prefer-rest-params }; } @@ -54,20 +48,12 @@ function verifyENOENTSync(status, parsed) { return notFoundError(parsed.original, 'spawnSync'); } - // If we are in node 10, then we are using spawn-sync; if it exited - // with -1 it probably means that the command does not exist - if (isNode10 && status === -1) { - parsed.file = isWin ? parsed.file : resolveCommand(parsed.original); - - if (!parsed.file) { - return notFoundError(parsed.original, 'spawnSync'); - } - } - return null; } -module.exports.hookChildProcess = hookChildProcess; -module.exports.verifyENOENT = verifyENOENT; -module.exports.verifyENOENTSync = verifyENOENTSync; -module.exports.notFoundError = notFoundError; +module.exports = { + hookChildProcess, + verifyENOENT, + verifyENOENTSync, + notFoundError, +}; |