(cmd, ...allArgs)
| 56 | } |
| 57 | |
| 58 | const spawn = async (cmd, ...allArgs) => { |
| 59 | const { |
| 60 | args, |
| 61 | opts: { ok, input, out, lines, quiet, env, ...opts }, |
| 62 | } = getArgs(allArgs) |
| 63 | |
| 64 | log.info('spawn', `${cmd} ${args.join(' ')}`) |
| 65 | |
| 66 | let res = null |
| 67 | try { |
| 68 | const spawnOpts = { |
| 69 | stdio: quiet || out || lines ? 'pipe' : 'inherit', |
| 70 | cwd: CWD, |
| 71 | env: { ...process.env, ...env }, |
| 72 | ...opts, |
| 73 | } |
| 74 | const proc = cmd === 'git' ? npmGit.spawn(args, spawnOpts) : promiseSpawn(cmd, args, spawnOpts) |
| 75 | if (input && proc.stdin) { |
| 76 | log.silly('input', input) |
| 77 | proc.stdin.write(input) |
| 78 | proc.stdin.end() |
| 79 | } |
| 80 | res = await proc |
| 81 | } catch (err) { |
| 82 | if (!ok) { |
| 83 | throw err |
| 84 | } |
| 85 | log.silly('suppressed error', err) |
| 86 | } |
| 87 | |
| 88 | if (res?.stdout) { |
| 89 | res.stdout = res.stdout.toString().trim() |
| 90 | if (res.stdout && !quiet) { |
| 91 | log.silly('stdout', res.stdout) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (res?.stderr) { |
| 96 | res.stderr = res.stderr.toString().trim() |
| 97 | if (res.stderr) { |
| 98 | log.silly('stderr', res.stderr) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (lines) { |
| 103 | return (res?.stdout || '') |
| 104 | .split('\n') |
| 105 | .map(l => l.trim()) |
| 106 | .filter(Boolean) |
| 107 | } |
| 108 | |
| 109 | if (out) { |
| 110 | return res?.stdout || '' |
| 111 | } |
| 112 | |
| 113 | return res |
| 114 | } |
| 115 |
no test coverage detected