init
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sindre Sorhus · committed by Sindre Sorhus · the first commit · Browse files · 9 files·+243 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+243 added−0 removed
- other:+243 added−0 removed
Provenance
- Commit
bc16d6b- Tree
01246e5- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>
9 files changed+243 added−0 removed
added:.editorconfig+15 added
1+root = true2+3+[*]4+indent_style = tab5+end_of_line = lf6+charset = utf-87+trim_trailing_whitespace = true8+insert_final_newline = true9+10+[{package.json,*.yml}]11+indent_style = space12+indent_size = 213+14+[*.md]15+trim_trailing_whitespace = falseadded:.gitattributes+1 added
1+* text=autoadded:.gitignore+1 added
1+node_modulesadded:.travis.yml+4 added
1234language: node_jsnode_js: - 'stable' - '0.12'added:index.js+61 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061'use strict';var childProcess = require('child_process');var parse = require('cross-spawn-async/lib/parse');var enoent = require('cross-spawn-async/lib/enoent');var stripEof = require('strip-eof');var objectAssign = require('object-assign');var TEN_MEBIBYTE = 1024 * 1024 * 10;
module.exports = function (cmd, args, opts) { return new Promise(function (resolve, reject) { opts = objectAssign({ maxBuffer: TEN_MEBIBYTE }, opts);
var parsed = parse(cmd, args, opts);
var handle = function (val) { if (parsed.options.stripEof !== false) { val = stripEof(val); }
return val; };
var spawned = childProcess.execFile(parsed.command, parsed.args, parsed.options, function (err, stdout, stderr) { if (err) { reject(err); return; }
resolve({ stdout: handle(stdout), stderr: handle(stderr) }); });
enoent.hookChildProcess(spawned, parsed); });};
module.exports.shell = function (cmd, opts) { var file; var args;
opts = objectAssign({}, opts);
if (process.platform === 'win32') { 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 module.exports(file, args, opts);};added:license+21 added
1+The MIT License (MIT)2+3+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)4+5+Permission is hereby granted, free of charge, to any person obtaining a copy6+of this software and associated documentation files (the "Software"), to deal7+in the Software without restriction, including without limitation the rights8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9+copies of the Software, and to permit persons to whom the Software is10+furnished to do so, subject to the following conditions:11+12+The above copyright notice and this permission notice shall be included in13+all copies or substantial portions of the Software.14+15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21+THE SOFTWARE.added:package.json+46 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546{ "name": "execa", "version": "0.0.0", "description": "A better child_process.{execFile,exec}", "license": "MIT", "repository": "sindresorhus/execa", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=0.12" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "exec", "execute", "fork", "child", "process", "execfile", "file", "bin", "binary" ], "dependencies": { "cross-spawn-async": "2.0.1", "object-assign": "^4.0.1", "strip-eof": "^1.0.0" }, "devDependencies": { "ava": "*", "xo": "*" }, "xo": { "ignores": [ "test.js" ] }}added:readme.md+71 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071# execa [](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)
## 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-async#why)- Higher max buffer. 10 MB instead of 200 KB.
## Install
```$ npm install --save execa```
## Usage
```jsconst execa = require('execa');
execa('echo', ['unicorns']).then(result => { console.log(result.stdout); //=> 'unicorns'});
execa.shell('echo unicorns').then(result => { console.log(result.stdout); //=> 'unicorns'});```
## API
### execa(file, [arguments], [options])
Execute a file directly.
Same options as [`child_process.execFile`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback).
Returns a promise for a result object with `stdout` and `stderr` properties.
### 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 promise for a result object with `stdout` and `stderr` properties.
### options
Additional exposed options:
#### stripEof
Type: `boolean` Default: `true`
[Strip EOF](https://github.com/sindresorhus/strip-eof) (last newline) from the output.
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)added:test.js+23 added
1+import test from 'ava';2+import fn from './';3+4+test('execa()', async t => {5+ const {stdout} = await fn('echo', ['foo']);6+ t.is(stdout, 'foo');7+});8+9+test('buffer', async t => {10+ const {stdout} = await fn('echo', ['foo'], {encoding: null});11+ t.true(Buffer.isBuffer(stdout));12+ t.is(stdout.toString(), 'foo');13+});14+15+test('stripEof option', async t => {16+ const {stdout} = await fn('echo', ['foo'], {stripEof: false});17+ t.is(stdout, 'foo\n');18+});19+20+test('execa.shell()', async t => {21+ const {stdout} = await fn.shell('echo foo');22+ t.is(stdout, 'foo');23+});