Skip to content

Commit

Permalink
I reject your reality and replace it with mine
Browse files Browse the repository at this point in the history
Newer versions of Node appear to be injecting two flags to
workers when inspect or debug is activated. We need to strip
all those flags, then inject ours, so to avoid any kind of
overrides.
  • Loading branch information
stelcheck committed Oct 19, 2017
1 parent efb79d6 commit 7a65cd7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions bin/mage-console
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ debug.setDebugPortForFlag(DEBUG_FLAG_NAME);
*/
var fork = cp.fork;
cp.fork = function (modulePath, args, options) {
var execArgv = options.execArgv;
var debugFlag = DEBUG_FLAG_NAME + '=' + DEBUG_FLAG_HOST + ':' + debug.incrementDebugPort();
debug.applyCPForkFlagsHack(execArgv, debugFlag);
options.execArgv = debug.applyCPForkFlagsHack(options.execArgv, debugFlag);

return fork.call(cp, modulePath, args, options);
};
Expand Down
5 changes: 2 additions & 3 deletions bin/ts-mage-console
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ debug.setDebugPortForFlag(DEBUG_FLAG_NAME);
*/
var fork = cp.fork;
cp.fork = function (modulePath, args, options) {
var execArgv = options.execArgv;
var debugFlag = DEBUG_FLAG_NAME + '=' + DEBUG_FLAG_HOST + ':' + debug.incrementDebugPort();
debug.applyCPForkFlagsHack(execArgv, debugFlag);
options.execArgv = debug.applyCPForkFlagsHack(options.execArgv, debugFlag);

// This is needed to make sure that our worker also compiles the
// TypeScript code properly
//
// See: https://github.com/TypeStrong/ts-node/blob/8e3c7e55bbea4b60b184079a522bae3ace250ffc/src/_bin.ts#L176
execArgv.push('./node_modules/ts-node/dist/_bin.js');
options.execArgv.push('./node_modules/ts-node/dist/_bin.js');

return fork.call(cp, modulePath, args, options);
};
Expand Down
17 changes: 6 additions & 11 deletions debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,14 @@ exports.getWorkerDebugPort = function () {
};

exports.incrementDebugPort = function () {
workerPort += 1;
return this.getWorkerDebugPort();
return workerPort += 1;
};

exports.applyCPForkFlagsHack = function (execArgv, debugFlag) {
for (var i = 0; i < execArgv.length; i++) {
var match = execArgv[i].match(
/^(--inspect|--debug)=(\d+)?$/
);
execArgv = execArgv.filter(function (flag) {
return !flag.match(/^(--inspect|--debug)/);
});

if (match) {
execArgv[i] = debugFlag;
break;
}
}
execArgv.unshift(debugFlag);
return execArgv;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage-console",
"version": "0.3.1",
"version": "0.3.2",
"description": "Alternative MAGE development console, with REPL interface",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 7a65cd7

Please sign in to comment.