fix_do_not_resolve_electron_entrypoints.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Samuel Attard <[email protected]>
  3. Date: Wed, 26 Jul 2023 17:03:15 -0700
  4. Subject: fix: do not resolve electron entrypoints
  5. This wastes fs cycles and can result in strange behavior if this path actually exists on disk
  6. diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
  7. index 4c3a0d8c484a402fe419a0bd45c7e2b1d717cb4a..b8be4cde3bbe4b14e607a2bef0a2405df3cae533 100644
  8. --- a/lib/internal/modules/esm/translators.js
  9. +++ b/lib/internal/modules/esm/translators.js
  10. @@ -309,6 +309,8 @@ function cjsPreparseModuleExports(filename, source) {
  11. const cached = cjsParseCache.get(module);
  12. if (cached)
  13. return { module, exportNames: cached.exportNames };
  14. + if (filename === 'electron')
  15. + return { module };
  16. }
  17. const loaded = Boolean(module);
  18. if (!loaded) {
  19. diff --git a/lib/internal/modules/run_main.js b/lib/internal/modules/run_main.js
  20. index 0bfe7b11241416bfca0d470047b14777ad99307f..c86add4395ed59cee0d880961e7572b0cc3d6698 100644
  21. --- a/lib/internal/modules/run_main.js
  22. +++ b/lib/internal/modules/run_main.js
  23. @@ -2,12 +2,19 @@
  24. const {
  25. StringPrototypeEndsWith,
  26. + StringPrototypeStartsWith,
  27. } = primordials;
  28. const { getOptionValue } = require('internal/options');
  29. const path = require('path');
  30. function resolveMainPath(main) {
  31. + // For built-in modules used as the main entry point we _never_
  32. + // want to waste cycles resolving them to file paths on disk
  33. + // that actually might exist
  34. + if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) {
  35. + return main;
  36. + }
  37. // Note extension resolution for the main entry point can be deprecated in a
  38. // future major.
  39. // Module._findPath is monkey-patchable here.
  40. @@ -24,6 +31,12 @@ function resolveMainPath(main) {
  41. }
  42. function shouldUseESMLoader(mainPath) {
  43. + // For built-in modules used as the main entry point we _never_
  44. + // want to waste cycles resolving them to file paths on disk
  45. + // that actually might exist
  46. + if (typeof mainPath === 'string' && StringPrototypeStartsWith(mainPath, 'electron/js2c')) {
  47. + return false;
  48. + }
  49. /**
  50. * @type {string[]} userLoaders A list of custom loaders registered by the user
  51. * (or an empty list when none have been registered).