From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samuel Attard 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 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) { diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js index 0bfe7b11241416bfca0d470047b14777ad99307f..c86add4395ed59cee0d880961e7572b0cc3d6698 100644 --- a/lib/internal/modules/run_main.js +++ b/lib/internal/modules/run_main.js @@ -2,12 +2,19 @@ const { StringPrototypeEndsWith, + StringPrototypeStartsWith, } = primordials; const { getOptionValue } = require('internal/options'); const path = require('path'); 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 + if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) { + return main; + } // Note extension resolution for the main entry point can be deprecated in a // future major. // Module._findPath is monkey-patchable here. @@ -24,6 +31,12 @@ function resolveMainPath(main) { } 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).