diff options
author | Rebecca Turner <me@re-becca.org> | 2017-04-12 21:47:49 -0700 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2017-04-25 10:52:01 -0400 |
commit | 00842604483e4c2e622dfdb3a97440e07646158f (patch) | |
tree | f3346902636a44b6037652523767636bf7e4f2c9 /deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js | |
parent | 061c5da010e0d249379618382a499840d38247b8 (diff) | |
download | android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.gz android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.tar.bz2 android-node-v8-00842604483e4c2e622dfdb3a97440e07646158f.zip |
deps: upgrade npm to 4.5.0
PR-URL: https://github.com/nodejs/node/pull/12480
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js')
-rw-r--r-- | deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js new file mode 100644 index 0000000000..5f3714a084 --- /dev/null +++ b/deps/npm/node_modules/update-notifier/node_modules/boxen/node_modules/term-size/node_modules/execa/index.js @@ -0,0 +1,172 @@ +'use strict'; +var childProcess = require('child_process'); +var crossSpawnAsync = require('cross-spawn-async'); +var stripEof = require('strip-eof'); +var objectAssign = require('object-assign'); +var npmRunPath = require('npm-run-path'); +var isStream = require('is-stream'); +var pathKey = require('path-key')(); +var TEN_MEBIBYTE = 1024 * 1024 * 10; + +function handleArgs(cmd, args, opts) { + var parsed; + + if (opts && opts.__winShell === true) { + delete opts.__winShell; + parsed = { + command: cmd, + args: args, + options: opts, + file: cmd, + original: cmd + }; + } else { + parsed = crossSpawnAsync._parse(cmd, args, opts); + } + + opts = objectAssign({ + maxBuffer: TEN_MEBIBYTE, + stripEof: true, + preferLocal: true, + encoding: 'utf8' + }, parsed.options); + + if (opts.preferLocal) { + opts.env = objectAssign({}, opts.env || process.env); + opts.env[pathKey] = npmRunPath({ + cwd: opts.cwd, + path: opts.env[pathKey] + }); + } + + return { + cmd: parsed.command, + args: parsed.args, + opts: opts + }; +} + +function handleInput(spawned, opts) { + var input = opts.input; + + if (input === null || input === undefined) { + return; + } + + if (isStream(input)) { + input.pipe(spawned.stdin); + } else { + spawned.stdin.end(input); + } +} + +function handleOutput(opts, val) { + if (opts.stripEof) { + val = stripEof(val); + } + + return val; +} + +function handleShell(fn, cmd, opts) { + var file; + var args; + + opts = objectAssign({}, opts); + + if (process.platform === 'win32') { + opts.__winShell = true; + file = process.env.comspec || 'cmd.exe'; + args = ['/s', '/c', '"' + cmd + '"']; + opts.windowsVerbatimArguments = true; + } else { + file = '/bin/sh'; + args = ['-c', cmd]; + } + + if (opts.shell) { + file = opts.shell; + } + + return fn(file, args, opts); +} + +module.exports = function (cmd, args, opts) { + var spawned; + + var promise = new Promise(function (resolve, reject) { + var parsed = handleArgs(cmd, args, opts); + + spawned = childProcess.execFile(parsed.cmd, parsed.args, parsed.opts, function (err, stdout, stderr) { + if (err) { + err.stdout = stdout; + err.stderr = stderr; + err.message += stdout; + reject(err); + return; + } + + resolve({ + stdout: handleOutput(parsed.opts, stdout), + stderr: handleOutput(parsed.opts, stderr) + }); + }); + + crossSpawnAsync._enoent.hookChildProcess(spawned, parsed); + + handleInput(spawned, parsed.opts); + }); + + spawned.then = promise.then.bind(promise); + spawned.catch = promise.catch.bind(promise); + + return spawned; +}; + +module.exports.stdout = function () { + // TODO: set `stderr: 'ignore'` when that option is implemented + return module.exports.apply(null, arguments).then(function (x) { + return x.stdout; + }); +}; + +module.exports.stderr = function () { + // TODO: set `stdout: 'ignore'` when that option is implemented + return module.exports.apply(null, arguments).then(function (x) { + return x.stderr; + }); +}; + +module.exports.shell = function (cmd, opts) { + return handleShell(module.exports, cmd, opts); +}; + +module.exports.spawn = function (cmd, args, opts) { + var parsed = handleArgs(cmd, args, opts); + var spawned = childProcess.spawn(parsed.cmd, parsed.args, parsed.opts); + + crossSpawnAsync._enoent.hookChildProcess(spawned, parsed); + + return spawned; +}; + +module.exports.sync = function (cmd, args, opts) { + var parsed = handleArgs(cmd, args, opts); + + if (isStream(parsed.opts.input)) { + throw new TypeError('The `input` option cannot be a stream in sync mode'); + } + + var result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts); + + if (parsed.opts.stripEof) { + result.stdout = stripEof(result.stdout); + result.stderr = stripEof(result.stderr); + } + + return result; +}; + +module.exports.shellSync = function (cmd, opts) { + return handleShell(module.exports.sync, cmd, opts); +}; |