Skip to content

Commit

Permalink
Rename variables in stdio file (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed Jun 20, 2019
1 parent 85a54d5 commit a9fa13f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getStream = require('get-stream');
const mergeStream = require('merge-stream');
const pFinally = require('p-finally');
const onExit = require('signal-exit');
const stdio = require('./lib/stdio');
const normalizeStdio = require('./lib/stdio');

const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
Expand Down Expand Up @@ -51,7 +51,7 @@ const handleArgs = (file, args, options = {}) => {
});
}

options.stdio = stdio(options);
options.stdio = normalizeStdio(options);

if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
// #116
Expand Down Expand Up @@ -533,7 +533,7 @@ module.exports.node = (scriptPath, args, options = {}) => {
args = [];
}

const stdioOption = stdio.node(options);
const stdioOption = normalizeStdio.node(options);

const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;

Expand Down
18 changes: 9 additions & 9 deletions lib/stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const aliases = ['stdin', 'stdout', 'stderr'];

const hasAlias = opts => aliases.some(alias => opts[alias] !== undefined);

const stdio = opts => {
const normalizeStdio = opts => {
if (!opts) {
return;
}
Expand All @@ -30,23 +30,23 @@ const stdio = opts => {
return Array.from({length}, (value, index) => stdio[index]);
};

module.exports = stdio;
module.exports = normalizeStdio;

// `ipc` is pushed unless it is already present
module.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'];
};
8 changes: 4 additions & 4 deletions test/stdio.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 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;
}
Expand All @@ -15,7 +15,7 @@ const macro = (t, input, expected, func) => {

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);
Expand Down Expand Up @@ -47,7 +47,7 @@ test(stdioMacro, {stdin: 'inherit', stdio: ['pipe']}, new Error('It\'s not possi
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']);
Expand Down

0 comments on commit a9fa13f

Please sign in to comment.