aboutsummaryrefslogtreecommitdiff
path: root/node_modules/execa
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/execa
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
downloadwallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/execa')
-rw-r--r--node_modules/execa/index.js275
-rw-r--r--node_modules/execa/lib/errname.js37
-rw-r--r--node_modules/execa/license21
-rw-r--r--node_modules/execa/package.json79
-rw-r--r--node_modules/execa/readme.md150
5 files changed, 562 insertions, 0 deletions
diff --git a/node_modules/execa/index.js b/node_modules/execa/index.js
new file mode 100644
index 000000000..0219cfa73
--- /dev/null
+++ b/node_modules/execa/index.js
@@ -0,0 +1,275 @@
+'use strict';
+const childProcess = require('child_process');
+const util = require('util');
+const crossSpawn = require('cross-spawn');
+const stripEof = require('strip-eof');
+const npmRunPath = require('npm-run-path');
+const isStream = require('is-stream');
+const _getStream = require('get-stream');
+const pFinally = require('p-finally');
+const onExit = require('signal-exit');
+const errname = require('./lib/errname');
+
+const TEN_MEGABYTES = 1000 * 1000 * 10;
+
+function handleArgs(cmd, args, opts) {
+ let parsed;
+
+ if (opts && opts.__winShell === true) {
+ delete opts.__winShell;
+ parsed = {
+ command: cmd,
+ args,
+ options: opts,
+ file: cmd,
+ original: cmd
+ };
+ } else {
+ parsed = crossSpawn._parse(cmd, args, opts);
+ }
+
+ opts = Object.assign({
+ maxBuffer: TEN_MEGABYTES,
+ stripEof: true,
+ preferLocal: true,
+ encoding: 'utf8',
+ reject: true,
+ cleanup: true
+ }, parsed.options);
+
+ if (opts.preferLocal) {
+ opts.env = npmRunPath.env(opts);
+ }
+
+ return {
+ cmd: parsed.command,
+ args: parsed.args,
+ opts
+ };
+}
+
+function handleInput(spawned, opts) {
+ const 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 (val && opts.stripEof) {
+ val = stripEof(val);
+ }
+
+ return val;
+}
+
+function handleShell(fn, cmd, opts) {
+ let file = '/bin/sh';
+ let args = ['-c', cmd];
+
+ opts = Object.assign({}, opts);
+
+ if (process.platform === 'win32') {
+ opts.__winShell = true;
+ file = process.env.comspec || 'cmd.exe';
+ args = ['/s', '/c', `"${cmd}"`];
+ opts.windowsVerbatimArguments = true;
+ }
+
+ if (opts.shell) {
+ file = opts.shell;
+ delete opts.shell;
+ }
+
+ return fn(file, args, opts);
+}
+
+function getStream(process, stream, encoding, maxBuffer) {
+ if (!process[stream]) {
+ return null;
+ }
+
+ let ret;
+
+ if (encoding) {
+ ret = _getStream(process[stream], {
+ encoding,
+ maxBuffer
+ });
+ } else {
+ ret = _getStream.buffer(process[stream], {maxBuffer});
+ }
+
+ return ret.catch(err => {
+ err.stream = stream;
+ err.message = `${stream} ${err.message}`;
+ throw err;
+ });
+}
+
+module.exports = (cmd, args, opts) => {
+ let joinedCmd = cmd;
+
+ if (Array.isArray(args) && args.length > 0) {
+ joinedCmd += ' ' + args.join(' ');
+ }
+
+ const parsed = handleArgs(cmd, args, opts);
+ const encoding = parsed.opts.encoding;
+ const maxBuffer = parsed.opts.maxBuffer;
+
+ let spawned;
+ try {
+ spawned = childProcess.spawn(parsed.cmd, parsed.args, parsed.opts);
+ } catch (err) {
+ return Promise.reject(err);
+ }
+
+ let removeExitHandler;
+ if (parsed.opts.cleanup) {
+ removeExitHandler = onExit(() => {
+ spawned.kill();
+ });
+ }
+
+ let timeoutId = null;
+ let timedOut = false;
+
+ const cleanupTimeout = () => {
+ if (timeoutId) {
+ clearTimeout(timeoutId);
+ timeoutId = null;
+ }
+ };
+
+ if (parsed.opts.timeout > 0) {
+ timeoutId = setTimeout(() => {
+ timeoutId = null;
+ timedOut = true;
+ spawned.kill(parsed.killSignal);
+ }, parsed.opts.timeout);
+ }
+
+ const processDone = new Promise(resolve => {
+ spawned.on('exit', (code, signal) => {
+ cleanupTimeout();
+ resolve({code, signal});
+ });
+
+ spawned.on('error', err => {
+ cleanupTimeout();
+ resolve({err});
+ });
+ });
+
+ function destroy() {
+ if (spawned.stdout) {
+ spawned.stdout.destroy();
+ }
+
+ if (spawned.stderr) {
+ spawned.stderr.destroy();
+ }
+ }
+
+ const promise = pFinally(Promise.all([
+ processDone,
+ getStream(spawned, 'stdout', encoding, maxBuffer),
+ getStream(spawned, 'stderr', encoding, maxBuffer)
+ ]).then(arr => {
+ const result = arr[0];
+ const stdout = arr[1];
+ const stderr = arr[2];
+
+ let err = result.err;
+ const code = result.code;
+ const signal = result.signal;
+
+ if (removeExitHandler) {
+ removeExitHandler();
+ }
+
+ if (err || code !== 0 || signal !== null) {
+ if (!err) {
+ err = new Error(`Command failed: ${joinedCmd}\n${stderr}${stdout}`);
+ err.code = code < 0 ? errname(code) : code;
+ }
+
+ // TODO: missing some timeout logic for killed
+ // https://github.com/nodejs/node/blob/master/lib/child_process.js#L203
+ // err.killed = spawned.killed || killed;
+ err.killed = err.killed || spawned.killed;
+
+ err.stdout = stdout;
+ err.stderr = stderr;
+ err.failed = true;
+ err.signal = signal || null;
+ err.cmd = joinedCmd;
+ err.timedOut = timedOut;
+
+ if (!parsed.opts.reject) {
+ return err;
+ }
+
+ throw err;
+ }
+
+ return {
+ stdout: handleOutput(parsed.opts, stdout),
+ stderr: handleOutput(parsed.opts, stderr),
+ code: 0,
+ failed: false,
+ killed: false,
+ signal: null,
+ cmd: joinedCmd,
+ timedOut: false
+ };
+ }), destroy);
+
+ crossSpawn._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(x => x.stdout);
+};
+
+module.exports.stderr = function () {
+ // TODO: set `stdout: 'ignore'` when that option is implemented
+ return module.exports.apply(null, arguments).then(x => x.stderr);
+};
+
+module.exports.shell = (cmd, opts) => handleShell(module.exports, cmd, opts);
+
+module.exports.sync = (cmd, args, opts) => {
+ const parsed = handleArgs(cmd, args, opts);
+
+ if (isStream(parsed.opts.input)) {
+ throw new TypeError('The `input` option cannot be a stream in sync mode');
+ }
+
+ const result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts);
+
+ result.stdout = handleOutput(parsed.opts, result.stdout);
+ result.stderr = handleOutput(parsed.opts, result.stderr);
+
+ return result;
+};
+
+module.exports.shellSync = (cmd, opts) => handleShell(module.exports.sync, cmd, opts);
+
+module.exports.spawn = util.deprecate(module.exports, 'execa.spawn() is deprecated. Use execa() instead.');
diff --git a/node_modules/execa/lib/errname.js b/node_modules/execa/lib/errname.js
new file mode 100644
index 000000000..a99d7500c
--- /dev/null
+++ b/node_modules/execa/lib/errname.js
@@ -0,0 +1,37 @@
+'use strict';
+// The Node team wants to deprecate `process.bind(...)`.
+// https://github.com/nodejs/node/pull/2768
+//
+// However, we need the 'uv' binding for errname support.
+// This is a defensive wrapper around it so `execa` will not fail entirely if it stops working someday.
+//
+// If this ever stops working. See: https://github.com/sindresorhus/execa/issues/31#issuecomment-215939939 for another possible solution.
+let uv;
+
+try {
+ uv = process.binding('uv');
+
+ if (typeof uv.errname !== 'function') {
+ throw new Error('uv.errname is not a function');
+ }
+} catch (err) {
+ console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', err);
+ uv = null;
+}
+
+function errname(uv, code) {
+ if (uv) {
+ return uv.errname(code);
+ }
+
+ if (!(code < 0)) {
+ throw new Error('err >= 0');
+ }
+
+ return `Unknown system error ${code}`;
+}
+
+module.exports = code => errname(uv, code);
+
+// used for testing the fallback behavior
+module.exports.__test__ = errname;
diff --git a/node_modules/execa/license b/node_modules/execa/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/execa/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/node_modules/execa/package.json b/node_modules/execa/package.json
new file mode 100644
index 000000000..e53f99235
--- /dev/null
+++ b/node_modules/execa/package.json
@@ -0,0 +1,79 @@
+{
+ "name": "execa",
+ "version": "0.5.1",
+ "description": "A better `child_process`",
+ "license": "MIT",
+ "repository": "sindresorhus/execa",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "maintainers": [
+ {
+ "name": "James Talmage",
+ "email": "james@talmage.io",
+ "url": "github.com/jamestalmage"
+ }
+ ],
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && nyc ava"
+ },
+ "files": [
+ "index.js",
+ "lib"
+ ],
+ "keywords": [
+ "exec",
+ "child",
+ "process",
+ "execute",
+ "fork",
+ "execfile",
+ "spawn",
+ "file",
+ "shell",
+ "bin",
+ "binary",
+ "binaries",
+ "npm",
+ "path",
+ "local"
+ ],
+ "dependencies": {
+ "cross-spawn": "^4.0.0",
+ "get-stream": "^2.2.0",
+ "is-stream": "^1.1.0",
+ "npm-run-path": "^2.0.0",
+ "p-finally": "^1.0.0",
+ "signal-exit": "^3.0.0",
+ "strip-eof": "^1.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "cat-names": "^1.0.2",
+ "coveralls": "^2.11.9",
+ "delay": "^1.3.1",
+ "is-running": "^2.0.0",
+ "nyc": "^8.3.0",
+ "xo": "*"
+ },
+ "nyc": {
+ "reporter": [
+ "text",
+ "lcov"
+ ],
+ "exclude": [
+ "node_modules",
+ "**/fixtures/**",
+ "**/test.js",
+ "**/test/**"
+ ]
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/node_modules/execa/readme.md b/node_modules/execa/readme.md
new file mode 100644
index 000000000..16189acb2
--- /dev/null
+++ b/node_modules/execa/readme.md
@@ -0,0 +1,150 @@
+# execa [![Build Status: Linux](https://travis-ci.org/sindresorhus/execa.svg?branch=master)](https://travis-ci.org/sindresorhus/execa) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/x5ajamxtjtt93cqv/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/execa/branch/master) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/execa/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/execa?branch=master)
+
+> A better [`child_process`](https://nodejs.org/api/child_process.html)
+
+
+## Why
+
+- Promise interface.
+- [Strips EOF](https://github.com/sindresorhus/strip-eof) from the output so you don't have to `stdout.trim()`.
+- Supports [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) binaries cross-platform.
+- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)
+- Higher max buffer. 10 MB instead of 200 KB.
+- [Executes locally installed binaries by name.](#preferlocal)
+- [Cleans up spawned processes when the parent process dies.](#cleanup)
+
+
+## Install
+
+```
+$ npm install --save execa
+```
+
+
+## Usage
+
+```js
+const execa = require('execa');
+
+execa('echo', ['unicorns']).then(result => {
+ console.log(result.stdout);
+ //=> 'unicorns'
+});
+
+// pipe the child process stdout to the current stdout
+execa('echo', ['unicorns']).stdout.pipe(process.stdout);
+
+execa.shell('echo unicorns').then(result => {
+ console.log(result.stdout);
+ //=> 'unicorns'
+});
+
+// example of catching an error
+execa.shell('exit 3').catch(error => {
+ console.log(error);
+ /*
+ {
+ message: 'Command failed: /bin/sh -c exit 3'
+ killed: false,
+ code: 3,
+ signal: null,
+ cmd: '/bin/sh -c exit 3',
+ stdout: '',
+ stderr: '',
+ timedOut: false
+ }
+ */
+});
+```
+
+
+## API
+
+### execa(file, [arguments], [options])
+
+Execute a file.
+
+Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback).
+
+Think of this as a mix of `child_process.execFile` and `child_process.spawn`.
+
+Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties.
+
+### execa.stdout(file, [arguments], [options])
+
+Same as `execa()`, but returns only `stdout`.
+
+### execa.stderr(file, [arguments], [options])
+
+Same as `execa()`, but returns only `stderr`.
+
+### execa.shell(command, [options])
+
+Execute a command through the system shell. Prefer `execa()` whenever possible, as it's both faster and safer.
+
+Same options as [`child_process.exec`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback).
+
+Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess).
+
+The `child_process` instance is enhanced to also be promise for a result object with `stdout` and `stderr` properties.
+
+### execa.sync(file, [arguments], [options])
+
+Execute a file synchronously.
+
+Same options as [`child_process.execFileSync`](https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options), except the default encoding is `utf8` instead of `buffer`.
+
+Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
+
+### execa.shellSync(file, [options])
+
+Execute a command synchronously through the system shell.
+
+Same options as [`child_process.execSync`](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options), except the default encoding is `utf8` instead of `buffer`.
+
+Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).
+
+### options
+
+Additional options:
+
+#### stripEof
+
+Type: `boolean`<br>
+Default: `true`
+
+[Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.
+
+#### preferLocal
+
+Type: `boolean`<br>
+Default: `true`
+
+Prefer locally installed binaries when looking for a binary to execute.<br>
+If you `$ npm install foo`, you can then `execa('foo')`.
+
+#### input
+
+Type: `string` `Buffer` `ReadableStream`
+
+Write some input to the `stdin` of your binary.<br>
+Streams are not allowed when using the synchronous methods.
+
+#### reject
+
+Type: `boolean`<br>
+Default: `true`
+
+Setting this to `false` resolves the promise with the error instead of rejecting it.
+
+#### cleanup
+
+Type: `boolean`<br>
+Default: `true`
+
+Keep track of the spawned process and `kill` it when the parent process exits.
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)