Skip to content

Commit 37b39f8

Browse files
authored
lib,src: drop --experimental-network-imports
nodejs/node#53822
1 parent 8083ee2 commit 37b39f8

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

patches/node/fix_expose_the_built-in_electron_module_via_the_esm_loader.patch

+22-24
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ Subject: fix: expose the built-in electron module via the ESM loader
66
This allows usage of `import { app } from 'electron'` and `import('electron')` natively in the browser + non-sandboxed renderer
77

88
diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js
9-
index 1fe5564545dbc86d7f2968274a25ee1579bcbf28..b876af21a0e97ae06dc344d9f78c8f5c7e403d43 100644
9+
index a89446df710a941390c15171fea63c551776fc93..912f03bfa96c3aa12bfa6e709746642452568bb7 100644
1010
--- a/lib/internal/modules/esm/get_format.js
1111
+++ b/lib/internal/modules/esm/get_format.js
12-
@@ -31,6 +31,7 @@ const protocolHandlers = {
13-
'http:': getHttpProtocolModuleFormat,
14-
'https:': getHttpProtocolModuleFormat,
12+
@@ -26,6 +26,7 @@ const protocolHandlers = {
13+
'data:': getDataProtocolModuleFormat,
14+
'file:': getFileProtocolModuleFormat,
1515
'node:'() { return 'builtin'; },
1616
+ 'electron:'() { return 'electron'; },
1717
};
1818

1919
/**
2020
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
21-
index 7b77af35a1dfebf6ad45ace521f1a55b5fa18293..ac24cf305bd5995ad13b37ee36f9e1fe3589c5d7 100644
21+
index 8b157f0f461c7b92c567fffe4d99357dbc09aee7..605e812d515fc467001e4ab88fc15b4af3fd4aa2 100644
2222
--- a/lib/internal/modules/esm/load.js
2323
+++ b/lib/internal/modules/esm/load.js
24-
@@ -142,7 +142,7 @@ async function defaultLoad(url, context = kEmptyObject) {
24+
@@ -121,7 +121,7 @@ async function defaultLoad(url, context = kEmptyObject) {
2525
// Now that we have the source for the module, run `defaultGetFormat` to detect its format.
2626
format = await defaultGetFormat(urlInstance, context);
2727

@@ -30,37 +30,35 @@ index 7b77af35a1dfebf6ad45ace521f1a55b5fa18293..ac24cf305bd5995ad13b37ee36f9e1fe
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;
33-
@@ -234,6 +234,7 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
33+
@@ -218,12 +218,13 @@ function throwIfUnsupportedURLScheme(parsed) {
3434
protocol !== 'file:' &&
3535
protocol !== 'data:' &&
3636
protocol !== 'node:' &&
3737
+ protocol !== 'electron:' &&
3838
(
39-
!experimentalNetworkImports ||
40-
(
41-
@@ -242,7 +243,7 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
42-
)
39+
protocol !== 'https:' &&
40+
protocol !== 'http:'
4341
)
4442
) {
4543
- const schemes = ['file', 'data', 'node'];
4644
+ const schemes = ['file', 'data', 'node', 'electron'];
47-
if (experimentalNetworkImports) {
48-
ArrayPrototypePush(schemes, 'https', 'http');
49-
}
45+
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
46+
}
47+
}
5048
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
51-
index e73a8ad60a13925d6773c32cead8d04ec9d96ee7..52cdb7d5e14a18ed7b1b65e429729cf47dce3f98 100644
49+
index 1fbbb6773c9479128408fa1f27cf19f1a7786ba6..f05c6f99c0037193c5802024be46a967d6cf47a0 100644
5250
--- a/lib/internal/modules/esm/resolve.js
5351
+++ b/lib/internal/modules/esm/resolve.js
54-
@@ -741,6 +741,8 @@ function packageImportsResolve(name, base, conditions) {
55-
throw importNotDefined(name, packageJSONUrl, base);
52+
@@ -772,6 +772,8 @@ function parsePackageName(specifier, base) {
53+
return { packageName, packageSubpath, isScoped };
5654
}
5755

5856
+const electronTypes = ['electron', 'electron/main', 'electron/common', 'electron/renderer'];
5957
+
6058
/**
61-
* Returns the package type for a given URL.
62-
* @param {URL} url - The URL to get the package type for.
63-
@@ -801,6 +803,11 @@ function packageResolve(specifier, base, conditions) {
59+
* Resolves a package specifier to a URL.
60+
* @param {string} specifier - The package specifier to resolve.
61+
@@ -785,6 +787,11 @@ function packageResolve(specifier, base, conditions) {
6462
return new URL('node:' + specifier);
6563
}
6664

@@ -96,17 +94,17 @@ index 8f4b6b25d8889686d00613fd9821b0aa822a946a..89ca269294ee1afa7f5aeb0ac6b8958f
9694
continue;
9795
}
9896
// We might trigger a getter -> dont fail.
99-
@@ -329,6 +329,10 @@ translators.set('require-commonjs', (url, source, isMain) => {
97+
@@ -304,6 +304,10 @@ translators.set('require-commonjs', (url, source, isMain) => {
10098
return createCJSModuleWrap(url, source);
10199
});
102100

103101
+translators.set('electron', () => {
104102
+ return createCJSModuleWrap('electron', '');
105103
+});
106104
+
107-
// Handle CommonJS modules referenced by `import` statements or expressions,
108-
// or as the initial entry point when the ESM loader handles a CommonJS entry.
109-
translators.set('commonjs', async function commonjsStrategy(url, source,
105+
// Handle CommonJS modules referenced by `require` calls.
106+
// This translator function must be sync, as `require` is sync.
107+
translators.set('require-commonjs-typescript', (url, source, isMain) => {
110108
diff --git a/lib/internal/url.js b/lib/internal/url.js
111109
index e6ed5466b8807a52633d8406824058bdc8c2ce13..e055facddf086eb8fb456b865ce006cdb7602b0a 100644
112110
--- a/lib/internal/url.js

0 commit comments

Comments
 (0)