Skip to content
Myr

Improve validation of `$.sync` options binding (#551)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 5fa61d8 · Browse files · 2 files+12 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−4 removed

  • tests:+4 added−0 removed
  • other:+8 added−4 removed

2 files+12 added−4 removed

modified:test/command.js+4 added
194 unmodified lines
195 const {stdout} = $({stripFinalNewline: true}).sync`noop.js foo`;196 t.is(stdout, 'foo');197});198199test('$.sync must be used after options binding, not before', t => {200 t.throws(() => $.sync({})`noop.js`, {message: /Please use/});201});202203test('$.sync allows execa return value interpolation', t => {204 const foo = $.sync`echo.js foo`;205 const {stdout} = $.sync`echo.js ${foo} bar`;206 t.is(stdout, 'foo\nbar');
69 unmodified lines
modified:index.js+8 added-4 removed
232 unmodified lines
233}234235function create$(options) {236 function $(templatesOrOptions, ...expressions) {237 if (Array.isArray(templatesOrOptions)) {238 const [file, ...args] = parseTemplates(templatesOrOptions, expressions);239 return execa(file, args, options);237 if (!Array.isArray(templatesOrOptions)) {238 return create$({...options, ...templatesOrOptions});239 }240242 return create$({...options, ...templatesOrOptions});241 const [file, ...args] = parseTemplates(templatesOrOptions, expressions);242 return execa(file, args, options);243 }244245 $.sync = (templates, ...expressions) => {246 if (!Array.isArray(templates)) {247 throw new TypeError('Please use $(options).sync`command` instead of $.sync(options)`command`.');248 }249250 const [file, ...args] = parseTemplates(templates, expressions);251 return execaSync(file, args, options);252 };253
46 unmodified lines