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 77b9ff35ff6ea780121aa1f4bb71850b9245965a..2a91c4820bebf55068c4d54a2e1133176de77a6d 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -161,6 +161,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;
 
