Rename variables in `stdio` file (#306)
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 85a54d5 · Browse files · 3 files·+16 added−16 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+16 added−16 removed
- tests:+4 added−4 removed
- other:+12 added−12 removed
Provenance
- Commit
a9fa13f- Tree
41cf55b- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
85a54d5
3 files changed+16 added−16 removed
modified:lib/stdio.js+9 added-9 removed
12345667891018 unmodified lines2930313233333435363737383939404142434443444546474847484950515152'use strict';const aliases = ['stdin', 'stdout', 'stderr'];
const hasAlias = opts => aliases.some(alias => opts[alias] !== undefined);
const stdio = opts => {const normalizeStdio = opts => { if (!opts) { return; }
18 unmodified lines const length = Math.max(stdio.length, aliases.length); return Array.from({length}, (value, index) => stdio[index]);};
module.exports = stdio;module.exports = normalizeStdio;
// `ipc` is pushed unless it is already presentmodule.exports.node = opts => { const stdioOption = stdio(opts); const stdio = normalizeStdio(opts);
if (stdioOption === 'ipc') { if (stdio === 'ipc') { return 'ipc'; }
if (stdioOption === undefined || typeof stdioOption === 'string') { return [stdioOption, stdioOption, stdioOption, 'ipc']; if (stdio === undefined || typeof stdio === 'string') { return [stdio, stdio, stdio, 'ipc']; }
if (stdioOption.includes('ipc')) { return stdioOption; if (stdio.includes('ipc')) { return stdio; }
return [...stdioOption, 'ipc']; return [...stdio, 'ipc'];};modified:test/stdio.js+4 added-4 removed
12334567889101112131415161718181920212223 unmodified lines4647484950505152535412 unmodified linesimport util from 'util';import test from 'ava';import stdio from '../lib/stdio';import normalizeStdio from '../lib/stdio';
const macro = (t, input, expected, func) => { if (expected instanceof Error) { t.throws(() => { stdio(input); normalizeStdio(input); }, expected.message); return; }
t.deepEqual(func(input), expected);};
const macroTitle = name => (title, input) => `${name} ${(util.inspect(input))}`;
const stdioMacro = (...args) => macro(...args, stdio);const stdioMacro = (...args) => macro(...args, normalizeStdio);stdioMacro.title = macroTitle('execa()');
test(stdioMacro, undefined, undefined);test(stdioMacro, null, undefined);23 unmodified linestest(stdioMacro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));test(stdioMacro, {stdin: 'inherit', stdio: [undefined, 'pipe']}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));test(stdioMacro, {stdin: 0, stdio: 'pipe'}, new Error('It\'s not possible to provide `stdio` in combination with one of `stdin`, `stdout`, `stderr`'));
const forkMacro = (...args) => macro(...args, stdio.node);const forkMacro = (...args) => macro(...args, normalizeStdio.node);forkMacro.title = macroTitle('execa.fork()');
test(forkMacro, undefined, [undefined, undefined, undefined, 'ipc']);test(forkMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore', 'ipc']);12 unmodified linesmodified:index.js+3 added-3 removed
9 unmodified lines10 const getStream = require('get-stream');11 const mergeStream = require('merge-stream');12 const pFinally = require('p-finally');13 const onExit = require('signal-exit');14-const stdio = require('./lib/stdio');14+const normalizeStdio = require('./lib/stdio');15 16 const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;17 const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;18 31 unmodified lines50 cwd: options.localDir51 });52 }53 54- options.stdio = stdio(options);54+ options.stdio = normalizeStdio(options);55 56 if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {57 // #11658 args.unshift('/q');473 unmodified lines532 options = args;533 args = [];534 }535 536- const stdioOption = stdio.node(options);536+ const stdioOption = normalizeStdio.node(options);537 538 const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;539 540 return execa(16 unmodified lines