From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <marshallofsound@electronjs.org>
Date: Wed, 26 Jul 2023 17:03:15 -0700
Subject: fix: do not resolve electron entrypoints

This wastes fs cycles and can result in strange behavior if this path actually exists on disk

diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
index a6fbcb6fd3c2413df96273d93b7339cad3f25f7a..130fe48b233691d8ee4c5d56f80d331924619008 100644
--- a/lib/internal/modules/esm/translators.js
+++ b/lib/internal/modules/esm/translators.js
@@ -392,6 +392,10 @@ function cjsPreparseModuleExports(filename, source, format) {
     return { module, exportNames: module[kModuleExportNames] };
   }
 
+  if (filename === 'electron') {
+    return { module, exportNames: new SafeSet(['default', ...Object.keys(module.exports)]) };
+  }
+
   if (source === undefined) {
     ({ source } = loadSourceForCJSWithHooks(module, filename, format));
   }
diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js
index 2974459755ec25139aefdab7f36811e036ac4204..593235acacd266ba7d6f1925032cd5ba455c29da 100644
--- a/lib/internal/modules/run_main.js
+++ b/lib/internal/modules/run_main.js
@@ -2,6 +2,7 @@
 
 const {
   StringPrototypeEndsWith,
+  StringPrototypeStartsWith,
   globalThis,
 } = primordials;
 
@@ -27,6 +28,13 @@ const {
  * @returns {string|undefined}
  */
 function resolveMainPath(main) {
+  // For built-in modules used as the main entry point we _never_
+  // want to waste cycles resolving them to file paths on disk
+  // that actually might exist
+  if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) {
+    return main;
+  }
+
   /** @type {string} */
   let mainPath;
   // Extension searching for the main entry point is supported for backward compatibility.
@@ -50,6 +58,13 @@ function resolveMainPath(main) {
  * @returns {boolean}
  */
 function shouldUseESMLoader(mainPath) {
+  // For built-in modules used as the main entry point we _never_
+  // want to waste cycles resolving them to file paths on disk
+  // that actually might exist
+  if (typeof mainPath === 'string' && StringPrototypeStartsWith(mainPath, 'electron/js2c')) {
+    return false;
+  }
+
   /**
    * @type {string[]} userLoaders A list of custom loaders registered by the user
    * (or an empty list when none have been registered).
