[BREAKING] for consistency return a result object from `execa.sync()` instead of string (#22)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
fixes #19
authored by James Talmage · committed by Sindre Sorhus · parent 99f10ba · Browse files · 3 files·+13 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+13 added−8 removed
- other:+13 added−8 removed
Provenance
- Commit
a8f2100- Tree
53f8746- Author
James Talmage <james.talmage@jrtechnical.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
99f10ba
3 files changed+13 added−8 removed
modified:index.js+7 added-2 removed
141 unmodified linesExpand all142143144145146146147148148149150151152153154155156157158141 unmodified linesExpand all if (isStream(parsed.opts.input)) { 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) { return handleShell(module.exports.sync, cmd, opts);};modified:readme.md+2 added-2 removed
85 unmodified lines86 Execute a file synchronously.87 88 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`.89 90-Returns `stdout`.90+Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).91 92 ### execa.shellSync(file, [options])93 94 Execute a command synchronously through the system shell.95 96 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`.97 98-Returns `stdout`.98+Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).99 100 ### options101 102 Additional options:27 unmodified linesmodified:test.js+4 added-4 removed
37 unmodified lines38 t.is((await getStream(m.spawn('noop', ['foo']).stdout)).trim(), 'foo');39 });40 41 test('execa.sync()', t => {42- const stdout = m.sync('noop', ['foo']);42+ const {stdout} = m.sync('noop', ['foo']);43 t.is(stdout, 'foo');44 });45 46 test('execa.shellSync()', t => {47- const stdout = m.shellSync('node fixtures/noop foo');47+ const {stdout} = m.shellSync('node fixtures/noop foo');48 t.is(stdout, 'foo');49 });50 51 test('stripEof option', async t => {40 unmodified lines92 t.is((await child).stdout, 'unicorns');93 });94 95 test('input option can be a String - sync', async t => {96- const stdout = m.sync('stdin', {input: 'foobar'});96+ const {stdout} = m.sync('stdin', {input: 'foobar'});97 t.is(stdout, 'foobar');98 });99 100 test('input option can be a Buffer - sync', async t => {101- const stdout = m.sync('stdin', {input: new Buffer('testing12', 'utf8')});101+ const {stdout} = m.sync('stdin', {input: new Buffer('testing12', 'utf8')});102 t.is(stdout, 'testing12');103 });104 105 test('helpful error trying to provide an input stream in sync mode', t => {11 unmodified lines