Skip to content

module.registerHooks() tracking issue #56241

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

Open
3 of 13 tasks
joyeecheung opened this issue Dec 12, 2024 · 5 comments
Open
3 of 13 tasks

module.registerHooks() tracking issue #56241

joyeecheung opened this issue Dec 12, 2024 · 5 comments
Labels
loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem.

Comments

@joyeecheung
Copy link
Member

joyeecheung commented Dec 12, 2024

@joyeecheung joyeecheung added module Issues and PRs related to the module subsystem. loaders Issues and PRs related to ES module loaders labels Dec 12, 2024
@joyeecheung
Copy link
Member Author

cc @nodejs/loaders

@jsumners-nr

This comment has been minimized.

@legendecas

This comment has been minimized.

@joyeecheung
Copy link
Member Author

I have a WIP for the evaluate hook which already works for a mock of require-in-the-middle. Pending on resolution about whether/how ESM can play into it. Opened an issue in Chromium to discuss about ESM evaluation hook: https://issues.chromium.org/u/1/issues/384413088 (mutability of exports would probably be out of scope of V8 as that's mandated by the spec, but at least we can address the use case where the hook does not need to patch and simply wants to observe).

@timokoessler
Copy link
Contributor

timokoessler commented Mar 3, 2025

Thanks for your great work! Are there any plans to officially support modifying the exports of builtins (to instrument them)?
One workaround we are exploring is to return commonjs code for builtins. In this code we import, modify and re-export the original builtin module. This does not seem to be bulletproof as Node.js e.g. adds a module.exports property to the exports when importing in ESM. Also returning code with the module format does not work because Node.js tries to read the non-existing package.json of the builtin. We want to use the new hook system to add ESM support to AikidoSec/firewall-node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants