add `execa.shellSync()`
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 · parent f786349 · Browse files · 3 files·+42 added−21 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+42 added−21 removed
- other:+42 added−21 removed
Provenance
- Commit
71a58ee- Tree
d1db542- Author
Sindre Sorhus <sindresorhus@gmail.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
f786349
3 files changed+42 added−21 removed
modified:index.js+28 added-20 removed
51 unmodified lines5253545556575859606162636465666768697071727374757677787980818223 unmodified lines106107108109878889909192939495969798991001011021031041051061101111121131149 unmodified lines12412512612712812913013151 unmodified lines
return val;}
function handleShell(fn, cmd, opts) { var file; var args;
opts = objectAssign({}, opts);
if (process.platform === 'win32') { opts.__winShell = true; 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 fn(file, args, opts);}
module.exports = function (cmd, args, opts) { var spawned;
var promise = new Promise(function (resolve, reject) {23 unmodified lines return promise;};
module.exports.shell = function (cmd, opts) { var file; var args;
opts = objectAssign({}, opts);
if (process.platform === 'win32') { opts.__winShell = true; 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); return handleShell(module.exports, cmd, opts);};
module.exports.spawn = function (cmd, args, opts) { var parsed = handleArgs(cmd, args, opts);9 unmodified lines var out = childProcess.execFileSync(parsed.cmd, parsed.args, parsed.opts);
return handleOutput(parsed.opts, out);};
module.exports.shellSync = function (cmd, opts) { return handleShell(module.exports.sync, cmd, opts);};modified:readme.md+9 added-1 removed
83 unmodified lines84 ### execa.sync(file, [arguments], [options])85 86 Execute a file synchronously.87 88-Same options as [`child_process.execFileSync`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback), except that the default encoding is `utf8` instead of `buffer`.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`.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`.99+100 ### options101 102 Additional options:103 19 unmodified linesmodified:test.js+5 added
40 unmodified lines41 const stdout = m.sync('noop', ['foo']);42 t.is(stdout, 'foo');43 });44 45+test('execa.shellSync()', t => {46+ const stdout = m.shellSync('node fixtures/noop foo');47+ t.is(stdout, 'foo');48+});49+50 test('stripEof option', async t => {51 const {stdout} = await m('noop', ['foo'], {stripEof: false});52 t.is(stdout, 'foo\n');53 });21 unmodified lines