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-11-30 15:51:35 +01:00
|
|
|
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
|
2025-05-13 21:56:52 +09:00
|
|
|
index 49aacb6262502ced54e817f99dd596db85b9659c..f9f065bb743275e9b2ce71375e6a9f06e00c0f36 100644
|
2023-11-30 15:51:35 +01:00
|
|
|
--- a/lib/internal/modules/esm/translators.js
|
|
|
|
+++ b/lib/internal/modules/esm/translators.js
|
2025-05-13 21:56:52 +09:00
|
|
|
@@ -291,6 +291,9 @@ function cjsPreparseModuleExports(filename, source, isMain, format) {
|
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-06-30 10:30:51 +02:00
|
|
|
index 02ba43adc2c8e92a78942bbb04023a16f5870ee9..bbf1ab69b884a9325bebdd07b2c4fd354eee946b 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
|
|
|
/**
|