Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] for consistency return a result object from execa.sync() instead of string - fixes #19 #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -87,12 +87,12 @@ test('input can be a Stream', 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