(createHooks)
| 14 | * @returns {(compilation: import("../Compilation")) => T} getter that returns (or creates) hooks for the compilation |
| 15 | */ |
| 16 | const createHooksRegistry = (createHooks) => { |
| 17 | /** @type {WeakMap<import("../Compilation"), T>} */ |
| 18 | const map = new WeakMap(); |
| 19 | return (compilation) => { |
| 20 | const Compilation = getCompilation(); |
| 21 | if (!(compilation instanceof Compilation)) { |
| 22 | throw new TypeError( |
| 23 | "The 'compilation' argument must be an instance of Compilation" |
| 24 | ); |
| 25 | } |
| 26 | let hooks = map.get(compilation); |
| 27 | if (hooks === undefined) { |
| 28 | hooks = createHooks(); |
| 29 | map.set(compilation, hooks); |
| 30 | } |
| 31 | return hooks; |
| 32 | }; |
| 33 | }; |
| 34 | |
| 35 | module.exports = createHooksRegistry; |
no test coverage detected