(hook, options)
| 6 | // check that a similar API can be built on top of the public |
| 7 | // hooks. |
| 8 | function 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 | |
| 30 | module.exports = { addHook }; |
no test coverage detected
searching dependent graphs…