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": {