版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

50 строки
1.1 KiB

  1. const aliases = ['stdin', 'stdout', 'stderr'];
  2. const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
  3. export const normalizeStdio = options => {
  4. if (!options) {
  5. return;
  6. }
  7. const {stdio} = options;
  8. if (stdio === undefined) {
  9. return aliases.map(alias => options[alias]);
  10. }
  11. if (hasAlias(options)) {
  12. throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
  13. }
  14. if (typeof stdio === 'string') {
  15. return stdio;
  16. }
  17. if (!Array.isArray(stdio)) {
  18. throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
  19. }
  20. const length = Math.max(stdio.length, aliases.length);
  21. return Array.from({length}, (value, index) => stdio[index]);
  22. };
  23. // `ipc` is pushed unless it is already present
  24. export const normalizeStdioNode = options => {
  25. const stdio = normalizeStdio(options);
  26. if (stdio === 'ipc') {
  27. return 'ipc';
  28. }
  29. if (stdio === undefined || typeof stdio === 'string') {
  30. return [stdio, stdio, stdio, 'ipc'];
  31. }
  32. if (stdio.includes('ipc')) {
  33. return stdio;
  34. }
  35. return [...stdio, 'ipc'];
  36. };