From 7209f6f3cb89b38850a527de3a12a9cd248fc67b Mon Sep 17 00:00:00 2001
From: Jakob Moosbrugger <jak.moo54@gmail.com>
Date: Tue, 25 Apr 2017 17:55:23 +0200
Subject: [PATCH] bugfix, where env variables were muted

---
 lib/index.js | 6 ++++--
 src/index.js | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/index.js b/lib/index.js
index 7a0c861..50627f6 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -9,6 +9,7 @@ var path = require("path"),
     worker = path.join(__dirname, "worker.js"),
     events = /^(error|message)$/,
     defaultPorts = { inspect: 9229, debug: 5858 };
+var forkedChilds = 0;
 
 var Worker = function () {
 	function Worker(arg) {
@@ -34,7 +35,7 @@ var Worker = function () {
 		if (debugVars.length > 0 && !options.noDebugRedirection) {
 			if (!options.execArgv) {
 				//if no execArgs are given copy all arguments
-				debugVars = process.execArgv;
+				debugVars = Array.from(process.execArgv);
 				options.execArgv = [];
 			}
 
@@ -58,7 +59,8 @@ var Worker = function () {
 				if (match[2]) {
 					port = parseInt(match[2]);
 				}
-				debugVars[portIndex] = "--" + match[1] + "=" + (port + 1); //new parameter
+				debugVars[portIndex] = "--" + match[1] + "=" + (port + 1 + forkedChilds); //new parameter
+				forkedChilds++;
 
 				if (debugIndex >= 0 && debugIndex !== portIndex) {
 					//remove "-brk" from debug if there
diff --git a/src/index.js b/src/index.js
index cd9e6f3..f18b2b7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,6 +3,7 @@ const path = require("path"),
 	worker = path.join(__dirname, "worker.js"),
 	events = /^(error|message)$/,
 	defaultPorts = {inspect: 9229, debug: 5858};
+let forkedChilds = 0;
 
 class Worker {
 	constructor (arg, args = undefined, options = {cwd: process.cwd()}) {
@@ -19,7 +20,7 @@ class Worker {
 		});
 		if (debugVars.length > 0 && !options.noDebugRedirection) {
 			if (!options.execArgv) { //if no execArgs are given copy all arguments
-				debugVars = process.execArgv;
+				debugVars = Array.from(process.execArgv);
 				options.execArgv = [];
 			}
 
@@ -39,7 +40,8 @@ class Worker {
 				if (match[2]) {
 					port = parseInt(match[2]);
 				}
-				debugVars[portIndex] = "--" + match[1] + "=" + (port + 1); //new parameter
+				debugVars[portIndex] = "--" + match[1] + "=" + (port + 1 + forkedChilds); //new parameter
+				forkedChilds++;
 
 				if (debugIndex >= 0 && debugIndex !== portIndex) { //remove "-brk" from debug if there
 					match = (/^(--debug)(?:-brk)?(.*)/).exec(debugVars[debugIndex]);
-- 
GitLab