Skip to content

Commit

Permalink
[BREAKING] for consistency return a result object from execa.sync()
Browse files Browse the repository at this point in the history
… instead of string (#22)

fixes #19
  • Loading branch information
jamestalmage authored and sindresorhus committed Apr 24, 2016
1 parent 99f10ba commit a8f2100
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,14 @@ module.exports.sync = function (cmd, args, opts) {
throw new TypeError('The `input` option cannot be a stream in sync mode');
}

var out = childProcess.execFileSync(parsed.cmd, parsed.args, parsed.opts);
var result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts);

return handleOutput(parsed.opts, out);
if (parsed.opts.stripEof) {
result.stdout = stripEof(result.stdout);
result.stderr = stripEof(result.stderr);
}

return result;
};

module.exports.shellSync = function (cmd, opts) {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ 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 `stdout`.
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 `stdout`.
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

Expand Down
8 changes: 4 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ test('execa.spawn()', async t => {
});

test('execa.sync()', t => {
const stdout = m.sync('noop', ['foo']);
const {stdout} = m.sync('noop', ['foo']);
t.is(stdout, 'foo');
});

test('execa.shellSync()', t => {
const stdout = m.shellSync('node fixtures/noop foo');
const {stdout} = m.shellSync('node fixtures/noop foo');
t.is(stdout, 'foo');
});

Expand Down Expand Up @@ -93,12 +93,12 @@ test('you can write to child.stdin', async t => {
});

test('input option can be a String - sync', async t => {
const stdout = m.sync('stdin', {input: 'foobar'});
const {stdout} = m.sync('stdin', {input: 'foobar'});
t.is(stdout, 'foobar');
});

test('input option can be a Buffer - sync', async t => {
const stdout = m.sync('stdin', {input: new Buffer('testing12', 'utf8')});
const {stdout} = m.sync('stdin', {input: new Buffer('testing12', 'utf8')});
t.is(stdout, 'testing12');
});

Expand Down

0 comments on commit a8f2100

Please sign in to comment.