(childArgs, inspectHost, inspectPort,
childOutput, options = { __proto__: null })
| 134 | } |
| 135 | |
| 136 | async function launchChildProcess(childArgs, inspectHost, inspectPort, |
| 137 | childOutput, options = { __proto__: null }) { |
| 138 | if (!options.skipPortPreflight) { |
| 139 | await portIsFree(inspectHost, inspectPort); |
| 140 | } |
| 141 | |
| 142 | const args = [`--inspect-brk=${inspectPort}`]; |
| 143 | ArrayPrototypePushApply(args, childArgs); |
| 144 | |
| 145 | const child = spawn(process.execPath, args); |
| 146 | child.stdout.setEncoding('utf8'); |
| 147 | child.stderr.setEncoding('utf8'); |
| 148 | child.stdout.on('data', (chunk) => childOutput(chunk, 'stdout')); |
| 149 | child.stderr.on('data', (chunk) => childOutput(chunk, 'stderr')); |
| 150 | |
| 151 | let stderrOutput = ''; |
| 152 | return new Promise((resolve, reject) => { |
| 153 | function rejectLaunch(message) { |
| 154 | reject(new ERR_DEBUGGER_STARTUP_ERROR(message, { childStderr: stderrOutput })); |
| 155 | } |
| 156 | |
| 157 | function onExit(code, signal) { |
| 158 | const suffix = signal !== null ? ` (${signal})` : ` (code ${code})`; |
| 159 | rejectLaunch(`Target exited before the inspector was ready${suffix}`); |
| 160 | } |
| 161 | |
| 162 | function onError(error) { |
| 163 | rejectLaunch(error.message); |
| 164 | } |
| 165 | |
| 166 | function onStderr(text) { |
| 167 | stderrOutput += text; |
| 168 | const debug = RegExpPrototypeExec(debugRegex, stderrOutput); |
| 169 | if (debug) { |
| 170 | child.stderr.removeListener('data', onStderr); |
| 171 | child.removeListener('exit', onExit); |
| 172 | child.removeListener('error', onError); |
| 173 | resolve([child, Number(debug[2]), debug[1]]); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | child.once('exit', onExit); |
| 178 | child.once('error', onError); |
| 179 | child.stderr.on('data', onStderr); |
| 180 | }); |
| 181 | } |
| 182 | |
| 183 | module.exports = { |
| 184 | ensureTrailingNewline, |
no test coverage detected