Permalink
Cannot retrieve contributors at this time
49 lines (36 sloc)
1.13 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/execa/lib/stdio.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const aliases = ['stdin', 'stdout', 'stderr']; | |
const hasAlias = options => aliases.some(alias => options[alias] !== undefined); | |
export const normalizeStdio = options => { | |
if (!options) { | |
return; | |
} | |
const {stdio} = options; | |
if (stdio === undefined) { | |
return aliases.map(alias => options[alias]); | |
} | |
if (hasAlias(options)) { | |
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`); | |
} | |
if (typeof stdio === 'string') { | |
return stdio; | |
} | |
if (!Array.isArray(stdio)) { | |
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``); | |
} | |
const length = Math.max(stdio.length, aliases.length); | |
return Array.from({length}, (value, index) => stdio[index]); | |
}; | |
// `ipc` is pushed unless it is already present | |
export const normalizeStdioNode = options => { | |
const stdio = normalizeStdio(options); | |
if (stdio === 'ipc') { | |
return 'ipc'; | |
} | |
if (stdio === undefined || typeof stdio === 'string') { | |
return [stdio, stdio, stdio, 'ipc']; | |
} | |
if (stdio.includes('ipc')) { | |
return stdio; | |
} | |
return [...stdio, 'ipc']; | |
}; |