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 415010241cdabac42ea79601c464bae4a2081c78..5c202237ecdf32afe89b5a5b4dfc2cf648fb9d23 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -160,6 +160,15 @@ function fork(modulePath, args = [], options) {
     throw new ERR_CHILD_PROCESS_IPC_REQUIRED('options.stdio');
   }
 
+  // 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;
   options.shell = false;
 
