You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch adds an `evaluate` hook that can be used as a supported
alternative to monkey-patching the CJS module loader, when the
primary use case is to modify the exports of modules, with the
goal of reducing dependency on CJS loader monkey-patching in
the wild.
The `evaluate` hook is run after the `resolve` and `load` hook,
abstracting the final execution of the code in the module. It is only
available to `module.registerHooks`. It is currently only run for the
execution of the following modules:
1. CommonJS modules, either being `require`d or `import`ed. In this
case, `context.module` equals to the `module` object in the CommonJS
module being evaluated, and `context.module.exports` is mutable.
2. ECMAScript modules that are `require`d. This hook would only be run
for the evaluation of the module being directly `require`d, but
could not be run for each of its inner modules being `import`ed. In
this case, `context.module` is a `Module` wrapper around the
ECMAScript modules. Reassigning `context.module.exports` to
something else only affects the result of `require()` call, but
would not affect access within the ECMAScript module. Properties of
`context.module.exports` (exports of the ECMAScript module) are not
mutable.
In future versions it may cover more module types, but the following
are unlikely to be supported due to restrictions in the ECMAScript
specifications:
1. The ability to skip evaluation of an inner ECMAScript module being
`import`ed by ECMAScript modules.
2. The ability to mutate the exports of a ECMAScript module.
For the ability to customize execution and exports of all the
ECMAScript modules in the graph, consider patching the source code of
the ECMAScript modules using the `load` hook as an imperfect
workaround.
0 commit comments