From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <samuel.r.attard@gmail.com>
Date: Mon, 3 Jun 2019 01:05:58 -0700
Subject: chore: allow the node entrypoint to be a builtin module

This floats two patches onto the node 12 branch that I don't think we can upstream.

The default behavior of node is to `path.resolve(firstArg)` to figure out what JS file to load.  Issue here is that we use that for `browser/init.js` which now doesn't exist on disk.  This adds an exception that won't affect user code to allow node to boot-up internal modules (in this case anything in the `electron/js2c` scope.

Similar to the above, the loader uses `process.argv[1]` to figure out when to break for `--inspect-brk` this updates the logic to use an Electron provided `process._firstFileName`

diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 072e614fca05197fb2b259914711033981f6e2f2..dd7b6496e23efe0b73c6c9919c3780abeecdcec3 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -71,8 +71,10 @@ function patchProcessObject(expandArgv1) {
 
   if (expandArgv1 && process.argv[1] && !process.argv[1].startsWith('-')) {
     // Expand process.argv[1] into a full path.
+    if (!process.argv[1] || !process.argv[1].startsWith('electron/js2c')) {
     const path = require('path');
     process.argv[1] = path.resolve(process.argv[1]);
+    }
   }
 
   // TODO(joyeecheung): most of these should be deprecated and removed,
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 2a7ffbff213f23536b94664c3ecffa18eb812849..6e73d0b57a11620b1fcec8b9b716b66673438864 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -845,6 +845,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]) {
         resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
       } else {
