From 7a65cd7aed59a2da64a74fa2cb470e983b662fc5 Mon Sep 17 00:00:00 2001 From: stelcheck Date: Wed, 18 Oct 2017 20:22:12 +0900 Subject: [PATCH] I reject your reality and replace it with mine 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. --- bin/mage-console | 3 +-- bin/ts-mage-console | 5 ++--- debug.js | 17 ++++++----------- package.json | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/bin/mage-console b/bin/mage-console index e48599a..bbaab30 100755 --- a/bin/mage-console +++ b/bin/mage-console @@ -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); }; diff --git a/bin/ts-mage-console b/bin/ts-mage-console index f9078d3..4c05f40 100755 --- a/bin/ts-mage-console +++ b/bin/ts-mage-console @@ -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); }; diff --git a/debug.js b/debug.js index e7c4ac1..7887847 100755 --- a/debug.js +++ b/debug.js @@ -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; }; diff --git a/package.json b/package.json index ee28df7..a4a3a7b 100755 --- a/package.json +++ b/package.json @@ -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": {