From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Mon, 30 Jul 2018 10:30:35 -0700
Subject: refactor: alter child_process.fork to use execute script with
 Electron

When forking a child script, we setup a special environment to make the Electron binary run like the upstream node. On Mac, we use the helper app as node binary.

diff --git a/lib/child_process.js b/lib/child_process.js
index 55e6b781cd00699921bf138b757fc3555942646b..1bc5f92181a48e1ee37e59220ad11a755b20c9f4 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -137,7 +137,18 @@ function fork(modulePath, args = [], options) {
     validateObject(options, 'options');
   }
   options = { ...options, shell: false };
+
+  // When forking a child script, we setup a special environment to make
+  // the electron binary run like upstream Node.js
+  options.env = Object.create(options.env || process.env)
+  options.env.ELECTRON_RUN_AS_NODE = 1;
+
+  if (!options.execPath && process.type && process.platform == 'darwin') {
+    options.execPath = process.helperExecPath;
+  }
+
   options.execPath = options.execPath || process.execPath;
+
   validateArgumentNullCheck(options.execPath, 'options.execPath');
 
   // Prepare arguments for fork:
