MCPcopy Index your code
hub / github.com/nodejs/node / addHook

Function addHook

test/fixtures/module-hooks/add-hook.js:8–28  ·  view source on GitHub ↗
(hook, options)

Source from the content-addressed store, hash-verified

6// check that a similar API can be built on top of the public
7// hooks.
8function addHook(hook, options) {
9 function load(url, context, nextLoad) {
10 const result = nextLoad(url, context);
11 const index = url.lastIndexOf('.');
12 const ext = url.slice(index);
13 if (!options.exts.includes(ext)) {
14 return result;
15 }
16 const filename = fileURLToPath(url);
17 if (!options.matcher(filename)) {
18 return result;
19 }
20 return { ...result, source: hook(result.source.toString(), filename) }
21 }
22
23 const registered = registerHooks({ load });
24
25 return function revert() {
26 registered.deregister();
27 };
28}
29
30module.exports = { addHook };

Calls 2

registerHooksFunction · 0.85
deregisterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…