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/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 25a8464e4833ff4655db2fe37f4bd482dc147865..4b1f1b05b6c67f206f87618792fa528deb238d8d 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -122,11 +122,13 @@ function patchProcessObject(expandArgv1) {
   if (expandArgv1 && process.argv[1] &&
       !StringPrototypeStartsWith(process.argv[1], '-')) {
     // Expand process.argv[1] into a full path.
-    const path = require('path');
-    try {
-      process.argv[1] = path.resolve(process.argv[1]);
-    } catch {
-      // Continue regardless of error.
+    if (!process.argv[1] || !process.argv[1].startsWith('electron/js2c')) {
+      const path = require('path');
+      try {
+        process.argv[1] = path.resolve(process.argv[1]);
+      } catch {
+        // Continue regardless of error.
+      }
     }
   }
 
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 3a536aab1bdeea6829d76d6af48fdefe0e08908d..4e3388b0b1fe69f8aaff15e651f7f0201208a40f 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1100,6 +1100,13 @@ Module.prototype._compile = function(content, filename) {
   if (getOptionValue('--inspect-brk') && process._eval == null) {
     if (!resolvedArgv) {
       // We enter the repl if we're not given a filename argument.
+      // 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
+      } else
       if (process.argv[1]) {
         try {
           resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
