Replace `null` by `undefined` (#193)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 7f8d911 · Browse files · 7 files·+32 added−34 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+32 added−34 removed
- tests:+14 added−14 removed
- other:+18 added−20 removed
Provenance
- Commit
dca1504- Tree
42b30e3- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
7f8d911
7 files changed+32 added−34 removed
modified:lib/errname.js+2 added-2 removed
14 unmodified lines1516171819192021222324252627282929303132336 unmodified lines14 unmodified lines throw new TypeError('uv.errname is not a function'); } } catch (error) { console.error('execa/lib/errname: unable to establish process.binding(\'uv\')', error); uv = null; uv = undefined; }
module.exports = code => errname(uv, code);}
// Used for testing the fallback behaviormodule.exports.__test__ = errname;
function errname(uv, code) { if (uv) { if (uv !== undefined) { return uv.errname(code); }
if (!(code < 0)) {6 unmodified linesmodified:lib/stdio.js+2 added-2 removed
3 unmodified lines456788910111212 unmodified lines252627282929303132338 unmodified lines3 unmodified linesconst hasAlias = opts => alias.some(x => Boolean(opts[x]));
module.exports = opts => { if (!opts) { return null; return; }
if (opts.stdio && hasAlias(opts)) { throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${alias.map(x => `\`${x}\``).join(', ')}`);12 unmodified lines const result = []; const len = Math.max(stdio.length, alias.length);
for (let i = 0; i < len; i++) { let value = null; let value;
if (stdio[i] !== undefined) { value = stdio[i]; } else if (opts[alias[i]] !== undefined) {8 unmodified linesmodified:test/errname.js+1 added-1 removed
2 unmodified lines34567789101115 unmodified lines2 unmodified lines
const isWindows = process.platform === 'win32';
// Simulates failure to capture `process.binding('uv');`const fallback = code => errname.__test__(null, code);const fallback = code => errname.__test__(undefined, code);
function makeTests(name, m, expected) { test(`${name}: >=0 exit codes`, t => { // Throws >= 015 unmodified linesmodified:test/stdio.js+13 added-13 removed
19 unmodified lines2021222324252425262728293031323334353632333435363738394038394041424344424344454647482 unmodified lines19 unmodified lines}
macro.title = (providedTitle, input) => providedTitle || util.inspect(input, {colors: true});
test(macro, undefined, null);test(macro, null, null);test(macro, undefined, undefined);test(macro, null, undefined);
test(macro, {stdio: 'inherit'}, 'inherit');test(macro, {stdio: 'pipe'}, 'pipe');test(macro, {stdio: 'ignore'}, 'ignore');test(macro, {stdio: [0, 1, 2]}, [0, 1, 2]);
test(macro, {}, [null, null, null]);test(macro, {stdio: []}, [null, null, null]);test(macro, {stdin: 'pipe'}, ['pipe', null, null]);test(macro, {stdout: 'ignore'}, [null, 'ignore', null]);test(macro, {stderr: 'inherit'}, [null, null, 'inherit']);test(macro, {}, [undefined, undefined, undefined]);test(macro, {stdio: []}, [undefined, undefined, undefined]);test(macro, {stdin: 'pipe'}, ['pipe', undefined, undefined]);test(macro, {stdout: 'ignore'}, [undefined, 'ignore', undefined]);test(macro, {stderr: 'inherit'}, [undefined, undefined, 'inherit']);test(macro, {stdin: 'pipe', stdout: 'ignore', stderr: 'inherit'}, ['pipe', 'ignore', 'inherit']);test(macro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', null]);test(macro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', null, 'inherit']);test(macro, {stdout: 'ignore', stderr: 'inherit'}, [null, 'ignore', 'inherit']);test(macro, {stdin: 'pipe', stdout: 'ignore'}, ['pipe', 'ignore', undefined]);test(macro, {stdin: 'pipe', stderr: 'inherit'}, ['pipe', undefined, 'inherit']);test(macro, {stdout: 'ignore', stderr: 'inherit'}, [undefined, 'ignore', 'inherit']);test(macro, {stdin: 0, stdout: 1, stderr: 2}, [0, 1, 2]);test(macro, {stdin: 0, stdout: 1}, [0, 1, null]);test(macro, {stdin: 0, stderr: 2}, [0, null, 2]);test(macro, {stdout: 1, stderr: 2}, [null, 1, 2]);test(macro, {stdin: 0, stdout: 1}, [0, 1, undefined]);test(macro, {stdin: 0, stderr: 2}, [0, undefined, 2]);test(macro, {stdout: 1, stderr: 2}, [undefined, 1, 2]);
test(macro, {stdio: {foo: 'bar'}}, new TypeError('Expected `stdio` to be of type `string` or `Array`, got `object`'));
test(macro, {stdin: 'inherit', stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));2 unmodified linesmodified:index.js+9 added-9 removed
92 unmodified lines93 }94 95 function makeAllStream(spawned) {96 if (!spawned.stdout && !spawned.stderr) {97- return null;97+ return;98 }99 100 const mixed = mergeStream();101 9 unmodified lines111 }112 113 function getStream(process, stream, {encoding, buffer, maxBuffer}) {114 if (!process[stream]) {115- return null;115+ return;116 }117 118 let ret;119 40 unmodified lines160 error.exitCodeName = exitCodeName;161 error.stdout = stdout;162 error.stderr = stderr;163 error.failed = true;164+ // `signal` emitted on `spawned.on('exit')` event can be `null`. We normalize165+ // it to `undefined`164- error.signal = signal || null;166+ error.signal = signal || undefined;167 error.cmd = joinedCommand;168 error.timedOut = Boolean(timedOut);169 170 if ('all' in result) {67 unmodified lines238 spawned.kill();239 });240 }241 240- let timeoutId = null;242+ let timeoutId;243 let timedOut = false;244 245 const cleanup = () => {244- if (timeoutId) {246+ if (timeoutId !== undefined) {247 clearTimeout(timeoutId);246- timeoutId = null;248+ timeoutId = undefined;249 }250 251 if (removeExitHandler) {252 removeExitHandler();1 unmodified line254 };255 256 if (parsed.options.timeout > 0) {257 timeoutId = setTimeout(() => {256- timeoutId = null;258+ timeoutId = undefined;259 timedOut = true;260 spawned.kill(parsed.options.killSignal);261 }, parsed.options.timeout);262 }70 unmodified lines333 exitCode: 0,334 exitCodeName: 'SUCCESS',335 failed: false,336 killed: false,335- signal: null,337 cmd: joinedCommand,338 timedOut: false339 };340 }), destroy);60 unmodified lines401 code: 0,402 exitCode: 0,403 exitCodeName: 'SUCCESS',404 failed: false,404- signal: null,405 cmd: joinedCommand,406 timedOut: false407 };408 };2 unmodified linesmodified:readme.md-2 removed
66 unmodified lines67 stdout: '',68 stderr: '',69 all: '',70 failed: true,71- signal: null,71 cmd: 'exit 3',72 timedOut: false,73 killed: false74 }14 unmodified lines89 exitCodeName: 'ESRCH',90 stdout: '',91 stderr: '',92 failed: true,94- signal: null,93 cmd: 'exit 3',94 timedOut: false95 }96 */244 unmodified linesmodified:test.js+5 added-5 removed
208 unmodified lines209 const {stdout} = await execa('stdin', {210 input: 'hello',211 stdio: [null, 'ignore', null]212 });213- t.is(stdout, null);213+ t.is(stdout, undefined);214 });215 216 test('helpful error trying to provide an input stream in sync mode', t => {217 t.throws(148 unmodified lines366 t.is(error.signal, 'SIGHUP');367 });368 }369 370-test('result.signal is null for successful execution', async t => {371- t.is((await execa('noop')).signal, null);370+test('result.signal is undefined for successful execution', async t => {371+ t.is((await execa('noop')).signal, undefined);372 });373 374-test('result.signal is null if process failed, but was not killed', async t => {374+test('result.signal is undefined if process failed, but was not killed', async t => {375 const error = await t.throwsAsync(execa('exit', [2]), {message: getExitRegExp('2')});376- t.is(error.signal, null);376+ t.is(error.signal, undefined);377 });378 379 async function code(t, num) {380 const error = await t.throwsAsync(execa('exit', [`${num}`]), {code: num, message: getExitRegExp(num)});208 unmodified lines