Skip to content

Commit

Permalink
chore: update fix_expose_the_built-in_electron_module_via_the_esm_loa…
Browse files Browse the repository at this point in the history
…der.patch

Xref: nodejs/node#47824

chore: upstream func throwIfUnsupportedURLProtocol() has been removed, so no need to patch it
  • Loading branch information
ckerr committed Aug 7, 2023
1 parent a5e0c20 commit 9b86c00
Showing 1 changed file with 8 additions and 17 deletions.
Expand Up @@ -6,7 +6,7 @@ Subject: fix: expose the built-in electron module via the ESM loader
This allows usage of `import { app } from 'electron'` and `import('electron')` natively in the browser + non-sandboxed renderer

diff --git a/lib/internal/modules/esm/get_format.js b/lib/internal/modules/esm/get_format.js
index eb5f0be49395b0192f18738d549241ae98793df7..522fd5cc6bea3e7fe4089eb25d64d65d2e8784ca 100644
index 219ef03a21..7749b37001 100644
--- a/lib/internal/modules/esm/get_format.js
+++ b/lib/internal/modules/esm/get_format.js
@@ -30,6 +30,7 @@ const protocolHandlers = {
Expand All @@ -18,10 +18,10 @@ index eb5f0be49395b0192f18738d549241ae98793df7..522fd5cc6bea3e7fe4089eb25d64d65d

/**
diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js
index fd7d2feada9bbbba589fe89230e45954fa2dd3be..3c9b1ad93f2c6b5fde5e9ed2a8bf1dc01d94a8de 100644
index 2cac6f2d45..ce2d851da2 100644
--- a/lib/internal/modules/esm/resolve.js
+++ b/lib/internal/modules/esm/resolve.js
@@ -824,6 +824,8 @@ function parsePackageName(specifier, base) {
@@ -822,6 +822,8 @@ function parsePackageName(specifier, base) {
return { packageName, packageSubpath, isScoped };
}

Expand All @@ -30,7 +30,7 @@ index fd7d2feada9bbbba589fe89230e45954fa2dd3be..3c9b1ad93f2c6b5fde5e9ed2a8bf1dc0
/**
* @param {string} specifier
* @param {string | URL | undefined} base
@@ -836,6 +838,10 @@ function packageResolve(specifier, base, conditions) {
@@ -834,6 +836,10 @@ function packageResolve(specifier, base, conditions) {
return new URL('node:' + specifier);
}

Expand All @@ -41,17 +41,8 @@ index fd7d2feada9bbbba589fe89230e45954fa2dd3be..3c9b1ad93f2c6b5fde5e9ed2a8bf1dc0
const { packageName, packageSubpath, isScoped } =
parsePackageName(specifier, base);

@@ -1034,7 +1040,7 @@ function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {

function throwIfUnsupportedURLProtocol(url) {
if (url.protocol !== 'file:' && url.protocol !== 'data:' &&
- url.protocol !== 'node:') {
+ url.protocol !== 'node:' && url.protocol !== 'electron:') {
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url);
}
}
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
index a425749e82acd7593c9fb1ceffedc119a4e416f2..1ceb89da21610c703f4a18be5888373c7feaa370 100644
index a425749e82..1ceb89da21 100644
--- a/lib/internal/modules/esm/translators.js
+++ b/lib/internal/modules/esm/translators.js
@@ -154,7 +154,7 @@ translators.set('commonjs', async function commonjsStrategy(url, source,
Expand All @@ -77,12 +68,12 @@ index a425749e82acd7593c9fb1ceffedc119a4e416f2..1ceb89da21610c703f4a18be5888373c
// We might trigger a getter -> dont fail.
let value;
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 7b2e0b4ffa6cc71b78dd1a1f64f7f491a6669383..41327e0f33828b1a3f276c9054293d89a7956e1d 100644
index 51688b8403..36604c9de2 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -1221,6 +1221,8 @@ function fileURLToPath(path) {
@@ -1399,6 +1399,8 @@ function fileURLToPath(path) {
path = new URL(path);
else if (!isURLInstance(path))
else if (!isURL(path))
throw new ERR_INVALID_ARG_TYPE('path', ['string', 'URL'], path);
+ if (path.protocol === 'electron:')
+ return 'electron';
Expand Down

0 comments on commit 9b86c00

Please sign in to comment.