fix_do_not_resolve_electron_entrypoints.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/run_main.js b/lib/internal/modules/run_main.js
  7. index 5a50d5d6afab6e6648f72a1c0efa1df4cd80bcd9..ebc9999358ccf16689dc02322eb1aeb86355f39b 100644
  8. --- a/lib/internal/modules/run_main.js
  9. +++ b/lib/internal/modules/run_main.js
  10. @@ -3,6 +3,7 @@
  11. const {
  12. ObjectCreate,
  13. StringPrototypeEndsWith,
  14. + StringPrototypeStartsWith,
  15. } = primordials;
  16. const CJSLoader = require('internal/modules/cjs/loader');
  17. const { Module, toRealPath, readPackageScope } = CJSLoader;
  18. @@ -13,6 +14,13 @@ const {
  19. } = require('internal/modules/esm/handle_process_exit');
  20. function resolveMainPath(main) {
  21. + // For built-in modules used as the main entry point we _never_
  22. + // want to waste cycles resolving them to file paths on disk
  23. + // that actually might exist
  24. + if (typeof main === 'string' && StringPrototypeStartsWith(main, 'electron/js2c')) {
  25. + return main;
  26. + }
  27. +
  28. // Note extension resolution for the main entry point can be deprecated in a
  29. // future major.
  30. // Module._findPath is monkey-patchable here.
  31. @@ -28,6 +36,13 @@ function resolveMainPath(main) {
  32. }
  33. function shouldUseESMLoader(mainPath) {
  34. + // For built-in modules used as the main entry point we _never_
  35. + // want to waste cycles resolving them to file paths on disk
  36. + // that actually might exist
  37. + if (typeof mainPath === 'string' && StringPrototypeStartsWith(mainPath, 'electron/js2c')) {
  38. + return false;
  39. + }
  40. +
  41. /**
  42. * @type {string[]} userLoaders A list of custom loaders registered by the user
  43. * (or an empty list when none have been registered).