-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
module: fix sync resolve hooks for require with node: prefixes #61088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Previously, when require()-ing builtins with the node: prefix, the sync resolve hooks were not properly invoked, and load hooks could not override the builtin's format. This fixes the handling and enables redirecting prefixed built-ins to on-disk files and overriding them with other module types via hooks.
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61088 +/- ##
==========================================
- Coverage 88.53% 88.52% -0.01%
==========================================
Files 703 703
Lines 208546 208589 +43
Branches 40217 40236 +19
==========================================
+ Hits 184634 184658 +24
- Misses 15926 15948 +22
+ Partials 7986 7983 -3
🚀 New features to boost your workflow:
|
| getCjsConditionsArray(), getDefaultLoad(url, id), validateLoadStrict); | ||
| if (resultFromHook.format && resultFromHook.format !== 'builtin') { | ||
| debug('loadBuiltinWithHooks overriding module', id, url, resultFromHook); | ||
| return { resultFromHook }; // Format has been overridden, return result for the caller to continue loading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return { resultFromHook }; // Format has been overridden, return result for the caller to continue loading. | |
| return { __proto__: null, resultFromHook }; // Format has been overridden, return result for the caller to continue loading. |
or
| return { resultFromHook }; // Format has been overridden, return result for the caller to continue loading. | |
| return { resultFromHook, builtinExports: undefined }; // Format has been overridden, return result for the caller to continue loading. |
otherwise we'll be hitting potential user-defined getters
| // exports. | ||
| const mod = loadBuiltinModule(id); | ||
| return mod.exports; | ||
| return { builtinExports: mod.exports }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
i'm confused; i thought the prefix was meant to prevent any kind of user intervention in accessing the core module, with require.extensions OR loaders - does this PR change that? |
|
|
wow, ok, that's unfortunate - that was one of the primary justifications for adding the prefix in the first place, the performance and reliability benefit of not being able to intercept it. |
Previously, when require()-ing builtins with the node: prefix, the sync resolve hooks were not properly invoked, and load hooks could not override the builtin's format. This fixes the handling and enables redirecting prefixed built-ins to on-disk files and overriding them with other module types via hooks.
Fixes: #60005