Skip to content
Snippets Groups Projects
Commit 3fd62672 authored by Jakob Moosbrugger's avatar Jakob Moosbrugger
Browse files

support for --inspect

parent 9a1b1014
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons ...@@ -7,7 +7,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var path = require("path"), var path = require("path"),
fork = require("child_process").fork, fork = require("child_process").fork,
worker = path.join(__dirname, "worker.js"), worker = path.join(__dirname, "worker.js"),
events = /^(error|message)$/; events = /^(error|message)$/,
defaultPorts = { inspect: 9229, debug: 5858 };
var Worker = function () { var Worker = function () {
function Worker(arg) { function Worker(arg) {
...@@ -37,15 +38,33 @@ var Worker = function () { ...@@ -37,15 +38,33 @@ var Worker = function () {
options.execArgv = []; options.execArgv = [];
} }
var portIndex = debugVars.findIndex(function (debugArg) { var inspectIndex = debugVars.findIndex(function (debugArg) {
//get index of debug port specifier //get index of inspect parameter
return (/^--(debug|inspect)(-brk)?(=\d+)?$/.test(debugArg) return (/^--inspect(-brk)?(=\d+)?$/.test(debugArg)
); );
}); });
var debugIndex = debugVars.findIndex(function (debugArg) {
//get index of debug parameter
return (/^--debug(-brk)?(=\d+)?$/.test(debugArg)
);
});
var portIndex = inspectIndex >= 0 ? inspectIndex : debugIndex; //get index of port, inspect has higher priority
if (portIndex >= 0) { if (portIndex >= 0) {
//set new port, ignore "-brk", it doesn't work var match = /^--(debug|inspect)(?:-brk)?(?:=(\d+))?$/.exec(debugVars[portIndex]); //get port
debugVars[portIndex] = (/^--debug/.test(debugVars[portIndex]) ? "--debug=" : "--inspect=") + (process.debugPort + 1); var port = defaultPorts[match[1]];
if (match[2]) {
port = parseInt(match[2]);
}
debugVars[portIndex] = "--" + match[1] + "=" + (port + 1); //new parameter
if (debugIndex >= 0 && debugIndex !== portIndex) {
//remove "-brk" from debug if there
match = /^(--debug)(?:-brk)?(.*)/.exec(debugVars[debugIndex]);
debugVars[debugIndex] = match[1] + (match[2] ? match[2] : "");
}
} }
options.execArgv = options.execArgv.concat(debugVars); options.execArgv = options.execArgv.concat(debugVars);
} }
......
const path = require("path"), const path = require("path"),
fork = require("child_process").fork, fork = require("child_process").fork,
worker = path.join(__dirname, "worker.js"), worker = path.join(__dirname, "worker.js"),
events = /^(error|message)$/; events = /^(error|message)$/,
defaultPorts = {inspect: 9229, debug: 5858};
class Worker { class Worker {
constructor (arg, args = undefined, options = {cwd: process.cwd()}) { constructor (arg, args = undefined, options = {cwd: process.cwd()}) {
...@@ -22,12 +23,28 @@ class Worker { ...@@ -22,12 +23,28 @@ class Worker {
options.execArgv = []; options.execArgv = [];
} }
let portIndex = debugVars.findIndex(debugArg => { //get index of debug port specifier let inspectIndex = debugVars.findIndex(debugArg => { //get index of inspect parameter
return (/^--(debug|inspect)(-brk)?(=\d+)?$/).test(debugArg); return (/^--inspect(-brk)?(=\d+)?$/).test(debugArg);
}); });
if (portIndex >= 0) { //set new port, ignore "-brk", it doesn't work let debugIndex = debugVars.findIndex(debugArg => { //get index of debug parameter
debugVars[portIndex] = ((/^--debug/).test(debugVars[portIndex]) ? "--debug=" : "--inspect=") + (process.debugPort + 1); return (/^--debug(-brk)?(=\d+)?$/).test(debugArg);
});
let portIndex = inspectIndex >= 0 ? inspectIndex : debugIndex; //get index of port, inspect has higher priority
if (portIndex >= 0) {
var match = (/^--(debug|inspect)(?:-brk)?(?:=(\d+))?$/).exec(debugVars[portIndex]); //get port
var port = defaultPorts[match[1]];
if (match[2]) {
port = parseInt(match[2]);
}
debugVars[portIndex] = "--" + match[1] + "=" + (port + 1); //new parameter
if (debugIndex >= 0 && debugIndex !== portIndex) { //remove "-brk" from debug if there
match = (/^(--debug)(?:-brk)?(.*)/).exec(debugVars[debugIndex]);
debugVars[debugIndex] = match[1] + (match[2] ? match[2] : "");
}
} }
options.execArgv = options.execArgv.concat(debugVars); options.execArgv = options.execArgv.concat(debugVars);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment