|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 | const aliases = ['stdin', 'stdout', 'stderr'];
|
|---|
| 3 |
|
|---|
| 4 | const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
|
|---|
| 5 |
|
|---|
| 6 | const normalizeStdio = options => {
|
|---|
| 7 | if (!options) {
|
|---|
| 8 | return;
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | const {stdio} = options;
|
|---|
| 12 |
|
|---|
| 13 | if (stdio === undefined) {
|
|---|
| 14 | return aliases.map(alias => options[alias]);
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | if (hasAlias(options)) {
|
|---|
| 18 | throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | if (typeof stdio === 'string') {
|
|---|
| 22 | return stdio;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | if (!Array.isArray(stdio)) {
|
|---|
| 26 | throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | const length = Math.max(stdio.length, aliases.length);
|
|---|
| 30 | return Array.from({length}, (value, index) => stdio[index]);
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | module.exports = normalizeStdio;
|
|---|
| 34 |
|
|---|
| 35 | // `ipc` is pushed unless it is already present
|
|---|
| 36 | module.exports.node = options => {
|
|---|
| 37 | const stdio = normalizeStdio(options);
|
|---|
| 38 |
|
|---|
| 39 | if (stdio === 'ipc') {
|
|---|
| 40 | return 'ipc';
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | if (stdio === undefined || typeof stdio === 'string') {
|
|---|
| 44 | return [stdio, stdio, stdio, 'ipc'];
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | if (stdio.includes('ipc')) {
|
|---|
| 48 | return stdio;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | return [...stdio, 'ipc'];
|
|---|
| 52 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.