mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
983 B
35 lines
983 B
'use strict';
|
|
|
|
const common = require('../common');
|
|
const spawn = require('child_process').spawn;
|
|
|
|
var procStderr = '';
|
|
var agentStdout = '';
|
|
var needToSpawnAgent = true;
|
|
var needToExit = true;
|
|
|
|
const procArgs = [`--debug-brk=${common.PORT}`, '-e', '0'];
|
|
const proc = spawn(process.execPath, procArgs);
|
|
proc.stderr.setEncoding('utf8');
|
|
|
|
const exitAll = common.mustCall((processes) => {
|
|
processes.forEach((myProcess) => { myProcess.kill(); });
|
|
});
|
|
|
|
proc.stderr.on('data', (chunk) => {
|
|
procStderr += chunk;
|
|
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
|
|
needToSpawnAgent = false;
|
|
const agentArgs = ['debug', `localhost:${common.PORT}`];
|
|
const agent = spawn(process.execPath, agentArgs);
|
|
agent.stdout.setEncoding('utf8');
|
|
|
|
agent.stdout.on('data', (chunk) => {
|
|
agentStdout += chunk;
|
|
if (/connecting to .+ ok/.test(agentStdout) && needToExit) {
|
|
needToExit = false;
|
|
exitAll([proc, agent]);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|