script.js 1015 B

12345678910111213141516171819202122
  1. // Sets `$.sync` and `$.s`
  2. export const setScriptSync = (boundExeca, createNested, boundOptions) => {
  3. boundExeca.sync = createNested(mapScriptSync, boundOptions);
  4. boundExeca.s = boundExeca.sync;
  5. };
  6. // Main logic for `$`
  7. export const mapScriptAsync = ({options}) => getScriptOptions(options);
  8. // Main logic for `$.sync`
  9. const mapScriptSync = ({options}) => ({...getScriptOptions(options), isSync: true});
  10. // `$` is like `execa` but with script-friendly options: `{stdin: 'inherit', preferLocal: true}`
  11. const getScriptOptions = options => ({options: {...getScriptStdinOption(options), ...options}});
  12. const getScriptStdinOption = ({input, inputFile, stdio}) => input === undefined && inputFile === undefined && stdio === undefined
  13. ? {stdin: 'inherit'}
  14. : {};
  15. // When using $(...).pipe(...), most script-friendly options should apply to both commands.
  16. // However, some options (like `stdin: 'inherit'`) would create issues with piping, i.e. cannot be deep.
  17. export const deepScriptOptions = {preferLocal: true};