diff options
Diffstat (limited to 'deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js')
-rw-r--r-- | deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js b/deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js index 0219cfa73f..74ba8ee2de 100644 --- a/deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js +++ b/deps/npm/node_modules/libnpx/node_modules/yargs/node_modules/os-locale/node_modules/execa/index.js @@ -9,12 +9,17 @@ const _getStream = require('get-stream'); const pFinally = require('p-finally'); const onExit = require('signal-exit'); const errname = require('./lib/errname'); +const stdio = require('./lib/stdio'); const TEN_MEGABYTES = 1000 * 1000 * 10; function handleArgs(cmd, args, opts) { let parsed; + if (opts && opts.env && opts.extendEnv !== false) { + opts.env = Object.assign({}, process.env, opts.env); + } + if (opts && opts.__winShell === true) { delete opts.__winShell; parsed = { @@ -32,19 +37,23 @@ function handleArgs(cmd, args, opts) { maxBuffer: TEN_MEGABYTES, stripEof: true, preferLocal: true, + localDir: parsed.options.cwd || process.cwd(), encoding: 'utf8', reject: true, cleanup: true }, parsed.options); + opts.stdio = stdio(opts); + if (opts.preferLocal) { - opts.env = npmRunPath.env(opts); + opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir})); } return { cmd: parsed.command, args: parsed.args, - opts + opts, + parsed }; } @@ -153,7 +162,7 @@ module.exports = (cmd, args, opts) => { timeoutId = setTimeout(() => { timeoutId = null; timedOut = true; - spawned.kill(parsed.killSignal); + spawned.kill(parsed.opts.killSignal); }, parsed.opts.timeout); } @@ -167,6 +176,13 @@ module.exports = (cmd, args, opts) => { cleanupTimeout(); resolve({err}); }); + + if (spawned.stdin) { + spawned.stdin.on('error', err => { + cleanupTimeout(); + resolve({err}); + }); + } }); function destroy() { @@ -198,7 +214,21 @@ module.exports = (cmd, args, opts) => { if (err || code !== 0 || signal !== null) { if (!err) { - err = new Error(`Command failed: ${joinedCmd}\n${stderr}${stdout}`); + let output = ''; + + if (Array.isArray(parsed.opts.stdio)) { + if (parsed.opts.stdio[2] !== 'inherit') { + output += output.length > 0 ? stderr : `\n${stderr}`; + } + + if (parsed.opts.stdio[1] !== 'inherit') { + output += `\n${stdout}`; + } + } else if (parsed.opts.stdio !== 'inherit') { + output = `\n${stderr}${stdout}`; + } + + err = new Error(`Command failed: ${joinedCmd}${output}`); err.code = code < 0 ? errname(code) : code; } @@ -233,7 +263,7 @@ module.exports = (cmd, args, opts) => { }; }), destroy); - crossSpawn._enoent.hookChildProcess(spawned, parsed); + crossSpawn._enoent.hookChildProcess(spawned, parsed.parsed); handleInput(spawned, parsed.opts); @@ -264,6 +294,10 @@ module.exports.sync = (cmd, args, opts) => { const result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts); + if (result.error || result.status !== 0) { + throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr)); + } + result.stdout = handleOutput(parsed.opts, result.stdout); result.stderr = handleOutput(parsed.opts, result.stderr); |