fix: do not load source for electron
module in ESM loader synchronous flow (#46810)
This commit is contained in:
parent
158176f0f3
commit
508c601996
3 changed files with 33 additions and 15 deletions
|
@ -5,19 +5,6 @@ Subject: fix: do not resolve electron entrypoints
|
||||||
|
|
||||||
This wastes fs cycles and can result in strange behavior if this path actually exists on disk
|
This wastes fs cycles and can result in strange behavior if this path actually exists on disk
|
||||||
|
|
||||||
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
|
||||||
index c9d4a3536d0f60375ae623b48ca2fa7095c88d42..d818320fbbc430d06a0c2852e4723981d6e1a844 100644
|
|
||||||
--- a/lib/internal/modules/esm/load.js
|
|
||||||
+++ b/lib/internal/modules/esm/load.js
|
|
||||||
@@ -109,7 +109,7 @@ async function defaultLoad(url, context = kEmptyObject) {
|
|
||||||
source = null;
|
|
||||||
format ??= 'builtin';
|
|
||||||
} else if (format !== 'commonjs' || defaultType === 'module') {
|
|
||||||
- if (source == null) {
|
|
||||||
+ if (format !== 'electron' && source == null) {
|
|
||||||
({ responseURL, source } = await getSource(urlInstance, context));
|
|
||||||
context = { __proto__: context, source };
|
|
||||||
}
|
|
||||||
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
|
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
|
||||||
index 49aacb6262502ced54e817f99dd596db85b9659c..f9f065bb743275e9b2ce71375e6a9f06e00c0f36 100644
|
index 49aacb6262502ced54e817f99dd596db85b9659c..f9f065bb743275e9b2ce71375e6a9f06e00c0f36 100644
|
||||||
--- a/lib/internal/modules/esm/translators.js
|
--- a/lib/internal/modules/esm/translators.js
|
||||||
|
|
|
@ -18,9 +18,18 @@ index 9519f947b8dfdc69808839948c9cb8434a0acf0e..23ce72d479f638c33edffcea7c35f5da
|
||||||
|
|
||||||
/**
|
/**
|
||||||
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
||||||
index 5ba13096b98047ff33e4d44167c2a069ccc5e69d..a00b5979e3b5deb4ba315b4635c7e5d2801c376e 100644
|
index 5ba13096b98047ff33e4d44167c2a069ccc5e69d..09a332c0999086b30fd952d9456f788925240e27 100644
|
||||||
--- a/lib/internal/modules/esm/load.js
|
--- a/lib/internal/modules/esm/load.js
|
||||||
+++ b/lib/internal/modules/esm/load.js
|
+++ b/lib/internal/modules/esm/load.js
|
||||||
|
@@ -106,7 +106,7 @@ async function defaultLoad(url, context = kEmptyObject) {
|
||||||
|
|
||||||
|
throwIfUnsupportedURLScheme(urlInstance);
|
||||||
|
|
||||||
|
- if (urlInstance.protocol === 'node:') {
|
||||||
|
+ if (urlInstance.protocol === 'node:' || format === 'electron') {
|
||||||
|
source = null;
|
||||||
|
format ??= 'builtin';
|
||||||
|
} else if (format !== 'commonjs' || defaultType === 'module') {
|
||||||
@@ -119,7 +119,7 @@ async function defaultLoad(url, context = kEmptyObject) {
|
@@ -119,7 +119,7 @@ async function defaultLoad(url, context = kEmptyObject) {
|
||||||
// Now that we have the source for the module, run `defaultGetFormat` to detect its format.
|
// Now that we have the source for the module, run `defaultGetFormat` to detect its format.
|
||||||
format = await defaultGetFormat(urlInstance, context);
|
format = await defaultGetFormat(urlInstance, context);
|
||||||
|
@ -30,6 +39,15 @@ index 5ba13096b98047ff33e4d44167c2a069ccc5e69d..a00b5979e3b5deb4ba315b4635c7e5d2
|
||||||
// For backward compatibility reasons, we need to discard the source in
|
// For backward compatibility reasons, we need to discard the source in
|
||||||
// order for the CJS loader to re-fetch it.
|
// order for the CJS loader to re-fetch it.
|
||||||
source = null;
|
source = null;
|
||||||
|
@@ -167,7 +167,7 @@ function defaultLoadSync(url, context = kEmptyObject) {
|
||||||
|
|
||||||
|
throwIfUnsupportedURLScheme(urlInstance, false);
|
||||||
|
|
||||||
|
- if (urlInstance.protocol === 'node:') {
|
||||||
|
+ if (urlInstance.protocol === 'node:' || format === 'electron') {
|
||||||
|
source = null;
|
||||||
|
} else if (source == null) {
|
||||||
|
({ responseURL, source } = getSourceSync(urlInstance, context));
|
||||||
@@ -200,12 +200,13 @@ function throwIfUnsupportedURLScheme(parsed) {
|
@@ -200,12 +200,13 @@ function throwIfUnsupportedURLScheme(parsed) {
|
||||||
protocol !== 'file:' &&
|
protocol !== 'file:' &&
|
||||||
protocol !== 'data:' &&
|
protocol !== 'data:' &&
|
||||||
|
@ -45,6 +63,19 @@ index 5ba13096b98047ff33e4d44167c2a069ccc5e69d..a00b5979e3b5deb4ba315b4635c7e5d2
|
||||||
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
|
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js
|
||||||
|
index fdecd0c926c953d33117d3d05366261ccf034a21..2e1ddd821ea6254fe00c52292620c3a58a62c046 100644
|
||||||
|
--- a/lib/internal/modules/esm/loader.js
|
||||||
|
+++ b/lib/internal/modules/esm/loader.js
|
||||||
|
@@ -426,7 +426,7 @@ class ModuleLoader {
|
||||||
|
}
|
||||||
|
|
||||||
|
const cjsModule = wrap[imported_cjs_symbol];
|
||||||
|
- if (cjsModule) {
|
||||||
|
+ if (cjsModule && finalFormat !== 'electron') {
|
||||||
|
assert(finalFormat === 'commonjs-sync');
|
||||||
|
// Check if the ESM initiating import CJS is being required by the same CJS module.
|
||||||
|
if (cjsModule?.[kIsExecuting]) {
|
||||||
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
|
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
|
||||||
index bfd9bd3d127404de1cbb6f30c43ab0342590759d..9e7d8ef0adef3b68a3ec186e4b218f591aa69266 100644
|
index bfd9bd3d127404de1cbb6f30c43ab0342590759d..9e7d8ef0adef3b68a3ec186e4b218f591aa69266 100644
|
||||||
--- a/lib/internal/modules/esm/resolve.js
|
--- a/lib/internal/modules/esm/resolve.js
|
||||||
|
|
|
@ -6,7 +6,7 @@ Subject: fix: lazyload fs in esm loaders to apply asar patches
|
||||||
Changes { foo } from fs to just "fs.foo" so that our patching of fs is applied to esm loaders
|
Changes { foo } from fs to just "fs.foo" so that our patching of fs is applied to esm loaders
|
||||||
|
|
||||||
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
||||||
index a00b5979e3b5deb4ba315b4635c7e5d2801c376e..c9d4a3536d0f60375ae623b48ca2fa7095c88d42 100644
|
index 09a332c0999086b30fd952d9456f788925240e27..910ac85cdc86e7fb3f850f7edf0b95ea09d464dc 100644
|
||||||
--- a/lib/internal/modules/esm/load.js
|
--- a/lib/internal/modules/esm/load.js
|
||||||
+++ b/lib/internal/modules/esm/load.js
|
+++ b/lib/internal/modules/esm/load.js
|
||||||
@@ -10,7 +10,7 @@ const {
|
@@ -10,7 +10,7 @@ const {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue