| 10 | const debugLog = (...args: unknown[]) => { if (debug) console.log(...args); }; |
| 11 | |
| 12 | async function startDebuggedProcess(): Promise<{ proc: ChildProcess, port: number }>{ |
| 13 | const proc = spawn('node', ['--inspect-brk=0', scriptPath], { |
| 14 | stdio: ['ignore', 'pipe', 'pipe'], |
| 15 | env: { ...process.env, NODE_OPTIONS: '' } |
| 16 | }); |
| 17 | |
| 18 | const port: number = await new Promise((resolve, reject) => { |
| 19 | let resolved = false; |
| 20 | proc.stderr?.on('data', (data: Buffer) => { |
| 21 | const msg = data.toString(); |
| 22 | const match = msg.match(/ws:\/\/127\.0\.0\.1:(\d+)/); |
| 23 | if (match) { |
| 24 | resolved = true; |
| 25 | resolve(Number(match[1])); |
| 26 | } |
| 27 | }); |
| 28 | proc.on('exit', () => { |
| 29 | if (!resolved) reject(new Error('process exited early')); |
| 30 | }); |
| 31 | }); |
| 32 | |
| 33 | return { proc, port }; |
| 34 | } |
| 35 | |
| 36 | function resolveFrameUrl(frame: any, parsedScripts: any[]): string { |
| 37 | const sid = frame && frame.location && frame.location.scriptId; |