@@ -5,16 +5,38 @@ Subject: fix: do not resolve electron entrypoints
55
66This wastes fs cycles and can result in strange behavior if this path actually exists on disk
77
8+ diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
9+ index 8406e8ca319533d6186c5d457e951b7a845b6b72..caa34187e17d9a0addcc8c94e46823ea4e05c590 100644
10+ --- a/lib/internal/modules/esm/load.js
11+ +++ b/lib/internal/modules/esm/load.js
12+ @@ -131,7 +131,7 @@ async function defaultLoad(url, context = kEmptyObject) {
13+ format ??= 'builtin';
14+ } else {
15+ let contextToPass = context;
16+ - if (source == null) {
17+ + if (format !== 'electron' && source == null) {
18+ ({ responseURL, source } = await getSource(urlInstance, context));
19+ contextToPass = { __proto__: context, source };
20+ }
21+ @@ -139,7 +139,7 @@ async function defaultLoad(url, context = kEmptyObject) {
22+ // Now that we have the source for the module, run `defaultGetFormat` again in case we detect ESM syntax.
23+ format ??= await defaultGetFormat(urlInstance, contextToPass);
24+
25+ - if ((format === 'commonjs' || format === 'electron') && contextToPass !== context) {
26+ + if (format === 'electron' || format === 'commonjs' && contextToPass !== context) {
27+ // For backward compatibility reasons, we need to discard the source in
28+ // order for the CJS loader to re-fetch it.
29+ source = null;
830diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
9- index dbbe37474c70addfbf8cf805c29732dcd38c74f6..f422a97b77f633020aed830a87a1c51bbb898acf 100644
31+ index dbbe37474c70addfbf8cf805c29732dcd38c74f6..96ffb2b0b051163d8a777ed3d1b5bc2c83fc37c5 100644
1032--- a/lib/internal/modules/esm/translators.js
1133+++ b/lib/internal/modules/esm/translators.js
1234@@ -376,6 +376,9 @@ function cjsPreparseModuleExports(filename, source) {
1335 if (cached) {
1436 return { module, exportNames: cached.exportNames };
1537 }
1638+ if (filename === 'electron') {
17- + return { module };
39+ + return { module, exportNames: new SafeSet(['default', ...Object.keys(module.exports)]) };
1840+ }
1941 }
2042 const loaded = Boolean(module);
0 commit comments