@@ -6,22 +6,22 @@ Subject: fix: expose the built-in electron module via the ESM loader
6
6
This allows usage of `import { app } from 'electron'` and `import('electron')` natively in the browser + non-sandboxed renderer
7
7
8
8
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
10
10
--- a/lib/internal/modules/esm/get_format.js
11
11
+++ 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 ,
15
15
'node:'() { return 'builtin'; },
16
16
+ 'electron:'() { return 'electron'; },
17
17
};
18
18
19
19
/**
20
20
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
22
22
--- a/lib/internal/modules/esm/load.js
23
23
+++ 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) {
25
25
// Now that we have the source for the module, run `defaultGetFormat` to detect its format.
26
26
format = await defaultGetFormat(urlInstance, context);
27
27
@@ -30,37 +30,35 @@ index 7b77af35a1dfebf6ad45ace521f1a55b5fa18293..ac24cf305bd5995ad13b37ee36f9e1fe
30
30
// For backward compatibility reasons, we need to discard the source in
31
31
// order for the CJS loader to re-fetch it.
32
32
source = null;
33
- @@ -234,6 +234,7 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports ) {
33
+ @@ -218,12 +218,13 @@ function throwIfUnsupportedURLScheme(parsed) {
34
34
protocol !== 'file:' &&
35
35
protocol !== 'data:' &&
36
36
protocol !== 'node:' &&
37
37
+ protocol !== 'electron:' &&
38
38
(
39
- !experimentalNetworkImports ||
40
- (
41
- @@ -242,7 +243,7 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
42
- )
39
+ protocol !== 'https:' &&
40
+ protocol !== 'http:'
43
41
)
44
42
) {
45
43
- const schemes = ['file', 'data', 'node'];
46
44
+ 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
+ }
50
48
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
52
50
--- a/lib/internal/modules/esm/resolve.js
53
51
+++ 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 } ;
56
54
}
57
55
58
56
+ const electronTypes = ['electron', 'electron/main', 'electron/common', 'electron/renderer'];
59
57
+
60
58
/**
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) {
64
62
return new URL('node:' + specifier);
65
63
}
66
64
@@ -96,17 +94,17 @@ index 8f4b6b25d8889686d00613fd9821b0aa822a946a..89ca269294ee1afa7f5aeb0ac6b8958f
96
94
continue;
97
95
}
98
96
// 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) => {
100
98
return createCJSModuleWrap(url, source);
101
99
});
102
100
103
101
+ translators.set('electron', () => {
104
102
+ return createCJSModuleWrap('electron', '');
105
103
+ });
106
104
+
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) => {
110
108
diff --git a/lib/internal/url.js b/lib/internal/url.js
111
109
index e6ed5466b8807a52633d8406824058bdc8c2ce13..e055facddf086eb8fb456b865ce006cdb7602b0a 100644
112
110
--- a/lib/internal/url.js
0 commit comments