+72
-25
@@ -10,32 +10,59 @@ 'use strict'; | ||
| module.exports = function (cmd, args, opts) { | ||
| return new Promise(function (resolve, reject) { | ||
| var parsed = crossSpawnAsync._parse(cmd, args, opts); | ||
| function handleArgs(cmd, args, opts) { | ||
| var parsed; | ||
| opts = objectAssign({ | ||
| maxBuffer: TEN_MEBIBYTE, | ||
| stripEof: true, | ||
| preferLocal: true | ||
| }, parsed.options); | ||
| 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); | ||
| } | ||
| var handle = function (val) { | ||
| if (opts.stripEof) { | ||
| val = stripEof(val); | ||
| } | ||
| opts = objectAssign({ | ||
| maxBuffer: TEN_MEBIBYTE, | ||
| stripEof: true, | ||
| preferLocal: true, | ||
| encoding: 'utf8' | ||
| }, parsed.options); | ||
| return val; | ||
| }; | ||
| if (opts.preferLocal) { | ||
| opts.env = objectAssign({}, opts.env || process.env); | ||
| opts.env[pathKey] = npmRunPath({ | ||
| cwd: opts.cwd, | ||
| path: opts.env[pathKey] | ||
| }); | ||
| } | ||
| 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 | ||
| }; | ||
| } | ||
| var spawned = childProcess.execFile(parsed.command, parsed.args, opts, function (err, stdout, stderr) { | ||
| function handleOutput(opts, val) { | ||
| if (opts.stripEof) { | ||
| val = stripEof(val); | ||
| } | ||
| return val; | ||
| } | ||
| 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); | ||
@@ -46,4 +73,4 @@ return; | ||
| resolve({ | ||
| stdout: handle(stdout), | ||
| stderr: handle(stderr) | ||
| stdout: handleOutput(parsed.opts, stdout), | ||
| stderr: handleOutput(parsed.opts, stderr) | ||
| }); | ||
@@ -54,2 +81,7 @@ }); | ||
| }); | ||
| promise.kill = spawned.kill.bind(spawned); | ||
| promise.pid = spawned.pid; | ||
| return promise; | ||
| }; | ||
@@ -64,2 +96,3 @@ | ||
| if (process.platform === 'win32') { | ||
| opts.__winShell = true; | ||
| file = process.env.comspec || 'cmd.exe'; | ||
@@ -80,2 +113,16 @@ args = ['/s', '/c', '"' + cmd + '"']; | ||
| module.exports.spawn = crossSpawnAsync; | ||
| 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); | ||
| var out = childProcess.execFileSync(parsed.cmd, parsed.args, parsed.opts); | ||
| return handleOutput(parsed.opts, out); | ||
| }; |
+8
-4
| { | ||
| "name": "execa", | ||
| "version": "0.2.2", | ||
| "version": "0.3.0", | ||
| "description": "A better `child_process`", | ||
@@ -16,3 +16,4 @@ "license": "MIT", | ||
| "scripts": { | ||
| "test": "xo && ava" | ||
| "test": "xo && nyc ava", | ||
| "coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
| }, | ||
@@ -24,6 +25,6 @@ "files": [ | ||
| "exec", | ||
| "child", | ||
| "process", | ||
| "execute", | ||
| "fork", | ||
| "child", | ||
| "process", | ||
| "execfile", | ||
@@ -50,4 +51,7 @@ "spawn", | ||
| "cat-names": "^1.0.2", | ||
| "coveralls": "^2.11.9", | ||
| "get-stream": "^2.0.0", | ||
| "nyc": "^6.4.0", | ||
| "xo": "*" | ||
| } | ||
| } |
+16
-4
@@ -1,2 +0,2 @@ | ||
| # execa [](https://travis-ci.org/sindresorhus/execa) | ||
| # execa [](https://travis-ci.org/sindresorhus/execa) [](https://ci.appveyor.com/project/sindresorhus/execa/branch/master) [](https://coveralls.io/github/sindresorhus/execa?branch=master) | ||
@@ -60,3 +60,3 @@ > A better [`child_process`](https://nodejs.org/api/child_process.html) | ||
| Execute a file directly. | ||
| Execute a file. | ||
@@ -67,2 +67,4 @@ Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback). | ||
| The promise instance has a `pid` property (ID of the child process) and a `kill` method (for sending signals to the child process). | ||
| ### execa.shell(command, [options]) | ||
@@ -76,2 +78,4 @@ | ||
| The promise instance has a `pid` property (ID of the child process) and a `kill` method (for sending signals to the child process). | ||
| ### execa.spawn(file, [arguments], [options]) | ||
@@ -83,5 +87,13 @@ | ||
| ### 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_execfile_file_args_options_callback), except that the default encoding is `utf8` instead of `buffer`. | ||
| Returns `stdout`. | ||
| ### options | ||
| Additional exposed options: | ||
| Additional options: | ||
@@ -106,2 +118,2 @@ #### stripEof | ||
| MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
| MIT © [Sindre Sorhus](https://sindresorhus.com) |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
8171
33.1%99
59.68%115
11.65%6
100%