Files
electron/patches/node/fix_do_not_resolve_electron_entrypoints.patch
2026-01-15 17:23:22 +01:00

63 lines
2.4 KiB
Diff

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 e4d5579565eea07013c8260fa3c4aa3b266a4b35..fbcef937b26023e0f6f97a0e58ac7350e7616f58 100644
--- a/lib/internal/modules/esm/translators.js
+++ b/lib/internal/modules/esm/translators.js
@@ -407,6 +407,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).