Skip to content

Commit b3bfca7

Browse files
codebyterejkleinsc
authored andcommitted
esm: do not call getSource when format is commonjs
nodejs/node#50465
1 parent 4ec93b8 commit b3bfca7

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

patches/node/fix_do_not_resolve_electron_entrypoints.patch

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,18 @@ Subject: fix: do not resolve electron entrypoints
66
This wastes fs cycles and can result in strange behavior if this path actually exists on disk
77

88
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
9-
index 8406e8ca319533d6186c5d457e951b7a845b6b72..caa34187e17d9a0addcc8c94e46823ea4e05c590 100644
9+
index 1d94cbeb771375243f58e544c583f612c3f4385c..97146f38a5478afeaded03c16e44ffb56fbe8087 100644
1010
--- a/lib/internal/modules/esm/load.js
1111
+++ b/lib/internal/modules/esm/load.js
12-
@@ -131,7 +131,7 @@ async function defaultLoad(url, context = kEmptyObject) {
12+
@@ -132,7 +132,7 @@ async function defaultLoad(url, context = kEmptyObject) {
13+
source = null;
1314
format ??= 'builtin';
14-
} else {
15-
let contextToPass = context;
15+
} else if (format !== 'commonjs' || defaultType === 'module') {
1616
- if (source == null) {
1717
+ if (format !== 'electron' && source == null) {
1818
({ responseURL, source } = await getSource(urlInstance, context));
19-
contextToPass = { __proto__: context, source };
19+
context = { __proto__: context, source };
2020
}
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;
3021
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
3122
index dbbe37474c70addfbf8cf805c29732dcd38c74f6..96ffb2b0b051163d8a777ed3d1b5bc2c83fc37c5 100644
3223
--- a/lib/internal/modules/esm/translators.js

patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ index 5239bc8ed883a54df206d73c5dc0b70942c4f3df..a111b5d7a6084caa61deb56bace5d91b
2626
format = await defaultGetFormat(urlInstance, context);
2727

2828
- if (format === 'commonjs') {
29-
+ if (format === 'commonjs' || format === 'electron') {
29+
+ if (format === 'electron' || format === 'commonjs') {
3030
// For backward compatibility reasons, we need to discard the source in
3131
// order for the CJS loader to re-fetch it.
3232
source = null;

0 commit comments

Comments
 (0)