( command, args, opts, prefix, cmdDryRun = false )
| 129 | */ |
| 130 | // istanbul ignore next |
| 131 | export function spawnStreaming( |
| 132 | command, |
| 133 | args, |
| 134 | opts, |
| 135 | prefix, |
| 136 | cmdDryRun = false |
| 137 | ) { |
| 138 | const options = { |
| 139 | ...opts, |
| 140 | nodeOptions: { |
| 141 | stdio: ['pipe', 'inherit', 'inherit'], |
| 142 | }, |
| 143 | }; |
| 144 | |
| 145 | if (cmdDryRun) { |
| 146 | return logExecDryRunCommand(command, args); |
| 147 | } |
| 148 | const spawned = spawnProcess(command, args, options, cmdDryRun); |
| 149 | |
| 150 | const stdoutOpts = {}; |
| 151 | const stderrOpts = {}; // mergeMultiline causes escaped newlines :P |
| 152 | |
| 153 | if (prefix) { |
| 154 | const color = c['magenta']; |
| 155 | stdoutOpts.tag = `${color.bold(prefix)}:`; |
| 156 | stderrOpts.tag = `${color(prefix)}:`; |
| 157 | } |
| 158 | |
| 159 | // Avoid 'Possible EventEmitter memory leak detected' warning due to piped stdio |
| 160 | if (children.size > process.stdout.listenerCount('close')) { |
| 161 | process.stdout.setMaxListeners(children.size); |
| 162 | process.stderr.setMaxListeners(children.size); |
| 163 | } |
| 164 | |
| 165 | spawned.stdout?.pipe(createLogPrefixer(stdoutOpts)).pipe(process.stdout); |
| 166 | spawned.stderr?.pipe(createLogPrefixer(stderrOpts)).pipe(process.stderr); |
| 167 | |
| 168 | return wrapError(spawned); |
| 169 | } |
| 170 | |
| 171 | // -- |
| 172 | // private functions |
no test coverage detected