Fix passing `undefined` options (#712)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent ed8b2ce · Browse files · 2 files·+51 added−26 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+51 added−26 removed
- tests:+13 added−7 removed
- other:+38 added−19 removed
Provenance
- Commit
472c065- Tree
63cf653- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
ed8b2ce
2 files changed+51 added−26 removed
modified:test/test.js+13 added-7 removed
74 unmodified lines75 });76 77 const testStripFinalNewline = async (t, index, stripFinalNewline, execaCommand) => {78 const {stdio} = await execaCommand('noop-fd.js', [`${index}`, 'foobar\n'], {...fullStdio, stripFinalNewline});79- t.is(stdio[index], `foobar${stripFinalNewline ? '' : '\n'}`);79+ t.is(stdio[index], `foobar${stripFinalNewline === false ? '\n' : ''}`);80 };81 82-test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, undefined, execa);82+test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);83+test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);84 test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, execa);84-test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, undefined, execa);85+test('stripFinalNewline: undefined with stderr', testStripFinalNewline, 2, undefined, execa);86+test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, execa);87 test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, execa);86-test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, undefined, execa);88+test('stripFinalNewline: undefined with stdio[*]', testStripFinalNewline, 3, undefined, execa);89+test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, execa);90 test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, execa);88-test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);91+test('stripFinalNewline: undefined with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);92+test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, true, execaSync);93 test('stripFinalNewline: false with stdout - sync', testStripFinalNewline, 1, false, execaSync);90-test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);94+test('stripFinalNewline: undefined with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);95+test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, true, execaSync);96 test('stripFinalNewline: false with stderr - sync', testStripFinalNewline, 2, false, execaSync);92-test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);97+test('stripFinalNewline: undefined with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);98+test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, true, execaSync);99 test('stripFinalNewline: false with stdio[*] - sync', testStripFinalNewline, 3, false, execaSync);100 101 test('stripFinalNewline is not used in objectMode', async t => {102 const {stdout} = await execa('noop-fd.js', ['1', 'foobar\n'], {stripFinalNewline: true, stdout: noopGenerator(true)});214 unmodified linesmodified:index.js+38 added-19 removed
47 unmodified lines48 const escapedCommand = getEscapedCommand(filePath, rawArgs);49 50 const {command: file, args, options: initialOptions} = crossSpawn._parse(filePath, rawArgs, rawOptions);51 52- const options = {53- maxBuffer: DEFAULT_MAX_BUFFER,54- buffer: true,55- stripFinalNewline: true,56- extendEnv: true,57- preferLocal: false,58- localDir: initialOptions.cwd || process.cwd(),59- execPath: process.execPath,60- encoding: 'utf8',61- reject: true,62- cleanup: true,63- all: false,64- windowsHide: true,65- verbose: verboseDefault,66- killSignal: 'SIGTERM',67- ...initialOptions,68- shell: normalizeFileUrl(initialOptions.shell),69- };70-52+ const options = addDefaultOptions(initialOptions);53+ options.shell = normalizeFileUrl(options.shell);54 options.env = getEnv(options);55 56 if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {57 // #1164 unmodified lines62 63 return {file, args, command, escapedCommand, options};64 };65 66+const addDefaultOptions = ({67+ maxBuffer = DEFAULT_MAX_BUFFER,68+ buffer = true,69+ stripFinalNewline = true,70+ extendEnv = true,71+ preferLocal = false,72+ cwd = process.cwd(),73+ localDir = cwd,74+ execPath = process.execPath,75+ encoding = 'utf8',76+ reject = true,77+ cleanup = true,78+ all = false,79+ windowsHide = true,80+ verbose = verboseDefault,81+ killSignal = 'SIGTERM',82+ ...options83+}) => ({84+ ...options,85+ maxBuffer,86+ buffer,87+ stripFinalNewline,88+ extendEnv,89+ preferLocal,90+ cwd,91+ localDir,92+ execPath,93+ encoding,94+ reject,95+ cleanup,96+ all,97+ windowsHide,98+ verbose,99+ killSignal,100+});101+102 const handleOutput = (options, value) => {103 if (value === undefined || value === null) {104 return;105 }234 unmodified lines