@contrast/dep-hooks
Advanced tools
Comparing version 1.9.0 to 1.10.0
export = ExportHookDescriptor; | ||
/** @typedef {import('./package-finder').Metadata} Metadata */ | ||
/** | ||
* @typedef {Object} HookControls | ||
* @property {() => void} rerun | ||
*/ | ||
/** | ||
* @template {Object} T | ||
* @callback Handler | ||
* @param {T} mod | ||
* @param {Metadata} metadata | ||
* @param {Metadata & HookControls} metadata | ||
* @returns {T} | ||
@@ -58,7 +62,10 @@ */ | ||
declare namespace ExportHookDescriptor { | ||
export { DEFAULT_VERSION, Metadata, Handler, HookDescriptorOptions }; | ||
export { DEFAULT_VERSION, Metadata, HookControls, Handler, HookDescriptorOptions }; | ||
} | ||
type Handler<T extends Object> = (mod: T, metadata: Metadata) => T; | ||
type Handler<T extends Object> = (mod: T, metadata: Metadata & HookControls) => T; | ||
declare const DEFAULT_VERSION: "*"; | ||
type Metadata = import('./package-finder').Metadata; | ||
type HookControls = { | ||
rerun: () => void; | ||
}; | ||
type HookDescriptorOptions<T extends Object> = { | ||
@@ -65,0 +72,0 @@ name: string; |
@@ -25,6 +25,10 @@ /* | ||
/** | ||
* @typedef {Object} HookControls | ||
* @property {() => void} rerun | ||
*/ | ||
/** | ||
* @template {Object} T | ||
* @callback Handler | ||
* @param {T} mod | ||
* @param {Metadata} metadata | ||
* @param {Metadata & HookControls} metadata | ||
* @returns {T} | ||
@@ -31,0 +35,0 @@ */ |
@@ -71,7 +71,12 @@ /* | ||
invoke(xport, handlers, metadata) { | ||
/** @type {Handler<T>[]} */ | ||
const handlersToRerun = []; | ||
const newHandlers = this.filter(xport, handlers); | ||
const rv = newHandlers.reduce((acc, handler) => { | ||
try { | ||
const rerun = () => { | ||
handlersToRerun.push(handler); | ||
}; | ||
this.logger?.trace({ metadata }, 'invoking handler: %s', metadata.name); | ||
return handler(acc, metadata) ?? acc; | ||
return handler(acc, { rerun, ...metadata }) ?? acc; | ||
} | ||
@@ -87,2 +92,6 @@ catch (err) { | ||
} | ||
for (const handler of handlersToRerun) { | ||
this.seen.get(rv)?.delete?.(handler); | ||
this.seen.delete(handler); | ||
} | ||
return rv; | ||
@@ -89,0 +98,0 @@ } |
{ | ||
"name": "@contrast/dep-hooks", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Post hooks for Module.prototype.require", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112404
1016