From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Wed, 22 May 2019 13:34:18 -0700
Subject: chore: allow the node entrypoint to be a builtin_module

This allows embedders to tell Node.js what the first "real" file is  when
they use themselves as the entry point. We should try to upstream some form
of this.

diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 9b5772fe9b8babbb892c7a5ec79258472da55a76..3568fd6ea0816f62d97d46f5d497bb1b23bf4e25 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1555,6 +1555,13 @@ Module.prototype._compile = function(content, filename, format) {
   this[kIsExecuting] = true;
   if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {
     const { callAndPauseOnStart } = internalBinding('inspector');
+    // process._firstFileName is used by Embedders to tell node what
+    // the first "real" file is when they use themselves as the entry
+    // point
+    if (process._firstFileName) {
+      resolvedArgv = process._firstFileName;
+      delete process._firstFileName;
+    }
     result = callAndPauseOnStart(compiledWrapper, thisValue, exports,
                                  require, module, filename, dirname,
                                  process, localGlobal, localBuffer);
diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js
index d1c05d1717cdc825c4e48885c963c9ed65bcf51c..278665921c5160ff10b3178db27d4df319fab6b3 100644
--- a/lib/internal/process/pre_execution.js
+++ b/lib/internal/process/pre_execution.js
@@ -243,12 +243,14 @@ function patchProcessObject(expandArgv1) {
   // the entry point.
   if (expandArgv1 && process.argv[1] && process.argv[1][0] !== '-') {
     // Expand process.argv[1] into a full path.
-    const path = require('path');
-    try {
-      mainEntry = path.resolve(process.argv[1]);
-      process.argv[1] = mainEntry;
-    } catch {
-      // Continue regardless of error.
+    if (!process.argv[1] || !process.argv[1].startsWith('electron/js2c')) {
+      const path = require('path');
+      try {
+        mainEntry = path.resolve(process.argv[1]);
+        process.argv[1] = mainEntry;
+      } catch {
+        // Continue regardless of error.
+      }
     }
   }
 
