execa
Advanced tools
Comparing version 0.1.1 to 0.2.0
28
index.js
@@ -6,2 +6,4 @@ 'use strict'; | ||
var objectAssign = require('object-assign'); | ||
var npmRunPath = require('npm-run-path'); | ||
var pathKey = require('path-key')(); | ||
var TEN_MEBIBYTE = 1024 * 1024 * 10; | ||
@@ -11,10 +13,12 @@ | ||
return new Promise(function (resolve, reject) { | ||
var parsed = crossSpawnAsync._parse(cmd, args, opts); | ||
opts = objectAssign({ | ||
maxBuffer: TEN_MEBIBYTE | ||
}, opts); | ||
maxBuffer: TEN_MEBIBYTE, | ||
stripEof: true, | ||
preferLocal: true | ||
}, parsed.options); | ||
var parsed = crossSpawnAsync._parse(cmd, args, opts); | ||
var handle = function (val) { | ||
if (parsed.options.stripEof !== false) { | ||
if (opts.stripEof) { | ||
val = stripEof(val); | ||
@@ -26,4 +30,14 @@ } | ||
var spawned = childProcess.execFile(parsed.command, parsed.args, parsed.options, function (err, stdout, stderr) { | ||
if (opts.preferLocal) { | ||
opts.env = opts.env || {}; | ||
opts.env[pathKey] = npmRunPath({ | ||
cwd: parsed.cwd, | ||
path: opts.env[pathKey] | ||
}); | ||
} | ||
var spawned = childProcess.execFile(parsed.command, parsed.args, opts, function (err, stdout, stderr) { | ||
if (err) { | ||
err.stdout = stdout; | ||
err.stderr = stderr; | ||
reject(err); | ||
@@ -64,1 +78,3 @@ return; | ||
}; | ||
module.exports.spawn = crossSpawnAsync; |
{ | ||
"name": "execa", | ||
"version": "0.1.1", | ||
"description": "A better child_process.{execFile,exec}", | ||
"version": "0.2.0", | ||
"description": "A better `child_process`", | ||
"license": "MIT", | ||
@@ -28,9 +28,17 @@ "repository": "sindresorhus/execa", | ||
"execfile", | ||
"spawn", | ||
"file", | ||
"shell", | ||
"bin", | ||
"binary" | ||
"binary", | ||
"binaries", | ||
"npm", | ||
"path", | ||
"local" | ||
], | ||
"dependencies": { | ||
"cross-spawn-async": "^2.1.1", | ||
"npm-run-path": "^1.0.0", | ||
"object-assign": "^4.0.1", | ||
"path-key": "^1.0.0", | ||
"strip-eof": "^1.0.0" | ||
@@ -40,9 +48,5 @@ }, | ||
"ava": "*", | ||
"cat-names": "^1.0.2", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"ignores": [ | ||
"test.js" | ||
] | ||
} | ||
} |
# execa [![Build Status](https://travis-ci.org/sindresorhus/execa.svg?branch=master)](https://travis-ci.org/sindresorhus/execa) | ||
> A better [`child_process.{execFile,exec}`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback) | ||
> A better [`child_process`](https://nodejs.org/api/child_process.html) | ||
@@ -13,2 +13,3 @@ | ||
- Higher max buffer. 10 MB instead of 200 KB. | ||
- [Executes locally installed binaries by name.](#preferlocal) | ||
@@ -37,2 +38,18 @@ | ||
}); | ||
// 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: '' | ||
} | ||
*/ | ||
}); | ||
``` | ||
@@ -59,2 +76,8 @@ | ||
### execa.spawn(file, [arguments], [options]) | ||
Spawn a file. | ||
Same API as [`child_process.spawn`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). | ||
### options | ||
@@ -66,3 +89,3 @@ | ||
Type: `boolean` | ||
Type: `boolean`<br> | ||
Default: `true` | ||
@@ -72,5 +95,13 @@ | ||
#### 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')`. | ||
## License | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
6114
62
103
5
3
+ Addednpm-run-path@^1.0.0
+ Addedpath-key@^1.0.0
+ Addednpm-run-path@1.0.0(transitive)
+ Addedpath-key@1.0.0(transitive)