2023-07-27 05:10:58 +00: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 14:51:35 +00:00
|
|
|
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
|
|
|
|
index 4c3a0d8c484a402fe419a0bd45c7e2b1d717cb4a..b8be4cde3bbe4b14e607a2bef0a2405df3cae533 100644
|
|
|
|
--- a/lib/internal/modules/esm/translators.js
|
|
|
|
+++ b/lib/internal/modules/esm/translators.js
|
|
|
|
@@ -309,6 +309,8 @@ function cjsPreparseModuleExports(filename, source) {
|
|
|
|
const cached = cjsParseCache.get(module);
|
|
|
|
if (cached)
|
|
|
|
return { module, exportNames: cached.exportNames };
|
|
|
|
+ if (filename === 'electron')
|
|
|
|
+ return { module };
|
|
|
|
}
|
|
|
|
const loaded = Boolean(module);
|
|
|
|
if (!loaded) {
|
2023-07-27 05:10:58 +00:00
|
|
|
diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js
|
2023-11-30 14:51:35 +00:00
|
|
|
index 0bfe7b11241416bfca0d470047b14777ad99307f..c86add4395ed59cee0d880961e7572b0cc3d6698 100644
|
2023-07-27 05:10:58 +00:00
|
|
|
--- a/lib/internal/modules/run_main.js
|
|
|
|
+++ b/lib/internal/modules/run_main.js
|
2023-11-30 14:51:35 +00:00
|
|
|
@@ -2,12 +2,19 @@
|
|
|
|
|
2023-08-09 07:32:00 +00:00
|
|
|
const {
|
|
|
|
StringPrototypeEndsWith,
|
|
|
|
+ StringPrototypeStartsWith,
|
|
|
|
} = primordials;
|
2023-11-30 14:51:35 +00:00
|
|
|
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const path = require('path');
|
2023-07-27 05:10:58 +00: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 07:32:00 +00:00
|
|
|
+ if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) {
|
2023-07-27 05:10:58 +00:00
|
|
|
+ return main;
|
|
|
|
+ }
|
|
|
|
// Note extension resolution for the main entry point can be deprecated in a
|
|
|
|
// future major.
|
|
|
|
// Module._findPath is monkey-patchable here.
|
2023-11-30 14:51:35 +00:00
|
|
|
@@ -24,6 +31,12 @@ function resolveMainPath(main) {
|
2023-08-09 07:32:00 +00: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;
|
|
|
|
+ }
|
|
|
|
/**
|
|
|
|
* @type {string[]} userLoaders A list of custom loaders registered by the user
|
|
|
|
* (or an empty list when none have been registered).
|