2023-07-26 22:10:58 -07:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Samuel Attard <marshallofsound@electronjs.org>
|
|
|
|
Date: Wed, 26 Jul 2023 17:03:15 -0700
|
|
|
|
Subject: fix: do not resolve electron entrypoints
|
|
|
|
|
|
|
|
This wastes fs cycles and can result in strange behavior if this path actually exists on disk
|
|
|
|
|
2023-12-11 21:09:50 +01:00
|
|
|
diff --git a/lib/internal/modules/esm/load.js b/lib/internal/modules/esm/load.js
|
2025-02-14 15:53:34 +01:00
|
|
|
index c9d4a3536d0f60375ae623b48ca2fa7095c88d42..d818320fbbc430d06a0c2852e4723981d6e1a844 100644
|
2023-12-11 21:09:50 +01:00
|
|
|
--- a/lib/internal/modules/esm/load.js
|
|
|
|
+++ b/lib/internal/modules/esm/load.js
|
2025-02-14 15:53:34 +01:00
|
|
|
@@ -109,7 +109,7 @@ async function defaultLoad(url, context = kEmptyObject) {
|
2024-01-18 16:16:45 -05:00
|
|
|
source = null;
|
2023-12-11 21:09:50 +01:00
|
|
|
format ??= 'builtin';
|
2024-01-18 16:16:45 -05:00
|
|
|
} else if (format !== 'commonjs' || defaultType === 'module') {
|
2023-12-11 21:09:50 +01:00
|
|
|
- if (source == null) {
|
|
|
|
+ if (format !== 'electron' && source == null) {
|
|
|
|
({ responseURL, source } = await getSource(urlInstance, context));
|
2024-01-18 16:16:45 -05:00
|
|
|
context = { __proto__: context, source };
|
2023-12-11 21:09:50 +01:00
|
|
|
}
|
2023-11-30 15:51:35 +01:00
|
|
|
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
|
2025-02-14 15:53:34 +01:00
|
|
|
index 0f138b1099b4833176e8a0ce681c745422efc24a..c7dd203e4bd5d611186300d9c0f2255afdf81684 100644
|
2023-11-30 15:51:35 +01:00
|
|
|
--- a/lib/internal/modules/esm/translators.js
|
|
|
|
+++ b/lib/internal/modules/esm/translators.js
|
2025-02-14 15:53:34 +01:00
|
|
|
@@ -287,6 +287,9 @@ function cjsPreparseModuleExports(filename, source) {
|
2024-08-26 15:09:33 -04:00
|
|
|
if (module && module[kModuleExportNames] !== undefined) {
|
|
|
|
return { module, exportNames: module[kModuleExportNames] };
|
2023-11-30 15:51:35 +01:00
|
|
|
}
|
2024-08-26 15:09:33 -04:00
|
|
|
+ if (filename === 'electron') {
|
|
|
|
+ return { module, exportNames: new SafeSet(['default', ...Object.keys(module.exports)]) };
|
|
|
|
+ }
|
2023-11-30 15:51:35 +01:00
|
|
|
const loaded = Boolean(module);
|
|
|
|
if (!loaded) {
|
2024-08-26 15:09:33 -04:00
|
|
|
module = new CJSModule(filename);
|
2023-07-26 22:10:58 -07:00
|
|
|
diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js
|
2025-02-14 15:53:34 +01:00
|
|
|
index ab4783a7982b9feb8fa85b62e3e3b181f93309bd..34f91026451d7347ae278712d083e4fe281e50f3 100644
|
2023-07-26 22:10:58 -07:00
|
|
|
--- a/lib/internal/modules/run_main.js
|
|
|
|
+++ b/lib/internal/modules/run_main.js
|
2023-12-11 21:09:50 +01:00
|
|
|
@@ -2,6 +2,7 @@
|
2023-11-30 15:51:35 +01:00
|
|
|
|
2023-08-09 00:32:00 -07:00
|
|
|
const {
|
|
|
|
StringPrototypeEndsWith,
|
|
|
|
+ StringPrototypeStartsWith,
|
2024-11-13 06:34:30 -08:00
|
|
|
globalThis,
|
2023-08-09 00:32:00 -07:00
|
|
|
} = primordials;
|
2023-11-30 15:51:35 +01:00
|
|
|
|
2024-11-13 06:34:30 -08:00
|
|
|
@@ -26,6 +27,13 @@ const {
|
2023-12-11 21:09:50 +01:00
|
|
|
* @param {string} main - Entry point path
|
|
|
|
*/
|
2023-07-26 22:10:58 -07:00
|
|
|
function resolveMainPath(main) {
|
|
|
|
+ // For built-in modules used as the main entry point we _never_
|
|
|
|
+ // want to waste cycles resolving them to file paths on disk
|
|
|
|
+ // that actually might exist
|
2023-08-09 00:32:00 -07:00
|
|
|
+ if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) {
|
2023-07-26 22:10:58 -07:00
|
|
|
+ return main;
|
|
|
|
+ }
|
2023-12-11 21:09:50 +01:00
|
|
|
+
|
|
|
|
const defaultType = getOptionValue('--experimental-default-type');
|
|
|
|
/** @type {string} */
|
|
|
|
let mainPath;
|
2025-02-14 15:53:34 +01:00
|
|
|
@@ -62,6 +70,13 @@ function resolveMainPath(main) {
|
2023-12-11 21:09:50 +01:00
|
|
|
* @param {string} mainPath - Absolute path to the main entry point
|
|
|
|
*/
|
2023-08-09 00:32:00 -07:00
|
|
|
function shouldUseESMLoader(mainPath) {
|
|
|
|
+ // For built-in modules used as the main entry point we _never_
|
|
|
|
+ // want to waste cycles resolving them to file paths on disk
|
|
|
|
+ // that actually might exist
|
|
|
|
+ if (typeof mainPath === 'string' && StringPrototypeStartsWith(mainPath, 'electron/js2c')) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2023-12-11 21:09:50 +01:00
|
|
|
+
|
|
|
|
if (getOptionValue('--experimental-default-type') === 'module') { return true; }
|
|
|
|
|
2023-08-09 00:32:00 -07:00
|
|
|
/**
|