hookable 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +1 -10
- package/package.json +13 -13
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
1
|
type HookCallback = (...arguments_: any) => Promise<void> | void;
|
|
3
2
|
interface Hooks {
|
|
4
3
|
[key: string]: HookCallback;
|
|
@@ -19,8 +18,6 @@ type BareHooks<T> = ValueOf<{ [key in Strings<T>]: key extends `${string}:${stri
|
|
|
19
18
|
type HooksInNamespace<T, Namespace extends string> = ValueOf<{ [key in Strings<T>]: key extends `${Namespace}:${infer HookName}` ? HookName : never }>;
|
|
20
19
|
type WithoutNamespace<T, Namespace extends string> = { [key in HooksInNamespace<T, Namespace>]: `${Namespace}:${key}` extends keyof T ? T[`${Namespace}:${key}`] : never };
|
|
21
20
|
type NestedHooks<T> = (Partial<StripGeneric<T>> | Partial<OnlyGeneric<T>>) & Partial<{ [key in Namespaces<StripGeneric<T>>]: NestedHooks<WithoutNamespace<T, key>> }> & Partial<{ [key in BareHooks<StripGeneric<T>>]: T[key] }>;
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/hookable.d.ts
|
|
24
21
|
type InferCallback<HT, HN extends keyof HT> = HT[HN] extends HookCallback ? HT[HN] : never;
|
|
25
22
|
type InferSpyEvent<HT extends Record<string, any>> = { [key in keyof HT]: {
|
|
26
23
|
name: key;
|
|
@@ -61,8 +58,6 @@ declare class HookableCore<HooksT extends Record<string, any> = Record<string, H
|
|
|
61
58
|
removeHook<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): void;
|
|
62
59
|
callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any> | void;
|
|
63
60
|
}
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/utils.d.ts
|
|
66
61
|
declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
|
|
67
62
|
declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
|
|
68
63
|
declare function serial<T>(tasks: T[], function_: (task: T) => Promise<any> | any): Promise<any>;
|
|
@@ -78,8 +73,6 @@ declare global {
|
|
|
78
73
|
declare function serialCaller(hooks: HookCallback[], arguments_?: any[]): Promise<any>;
|
|
79
74
|
/** @deprecated */
|
|
80
75
|
declare function parallelCaller(hooks: HookCallback[], args?: any[]): Promise<any>;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/debugger.d.ts
|
|
83
76
|
interface CreateDebuggerOptions {
|
|
84
77
|
/** An optional tag to prefix console logs with */
|
|
85
78
|
tag?: string;
|
|
@@ -102,5 +95,4 @@ interface CreateDebuggerOptions {
|
|
|
102
95
|
declare function createDebugger(hooks: Hookable<any>, _options?: CreateDebuggerOptions): {
|
|
103
96
|
/** Stop debugging and remove listeners */close: () => void;
|
|
104
97
|
};
|
|
105
|
-
//#endregion
|
|
106
98
|
export { CreateDebuggerOptions, DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hookable, HookableCore, Hooks, NestedHooks, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/utils.ts
|
|
2
1
|
function flatHooks(configHooks, hooks = {}, parentName) {
|
|
3
2
|
for (const key in configHooks) {
|
|
4
3
|
const subHook = configHooks[key];
|
|
@@ -32,7 +31,7 @@ const createTask = /* @__PURE__ */ (() => {
|
|
|
32
31
|
function callHooks(hooks, args, startIndex, task) {
|
|
33
32
|
for (let i = startIndex; i < hooks.length; i += 1) try {
|
|
34
33
|
const result = task ? task.run(() => hooks[i](...args)) : hooks[i](...args);
|
|
35
|
-
if (result
|
|
34
|
+
if (result && typeof result.then === "function") return Promise.resolve(result).then(() => callHooks(hooks, args, i + 1, task));
|
|
36
35
|
} catch (error) {
|
|
37
36
|
return Promise.reject(error);
|
|
38
37
|
}
|
|
@@ -46,19 +45,15 @@ function parallelTaskCaller(hooks, args, name) {
|
|
|
46
45
|
return Promise.all(hooks.map((hook) => task.run(() => hook(...args))));
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
/** @deprecated */
|
|
50
48
|
function serialCaller(hooks, arguments_) {
|
|
51
49
|
return hooks.reduce((promise, hookFunction) => promise.then(() => hookFunction(...arguments_ || [])), Promise.resolve());
|
|
52
50
|
}
|
|
53
|
-
/** @deprecated */
|
|
54
51
|
function parallelCaller(hooks, args) {
|
|
55
52
|
return Promise.all(hooks.map((hook) => hook(...args || [])));
|
|
56
53
|
}
|
|
57
54
|
function callEachWith(callbacks, arg0) {
|
|
58
55
|
for (const callback of [...callbacks]) callback(arg0);
|
|
59
56
|
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/hookable.ts
|
|
62
57
|
var Hookable = class {
|
|
63
58
|
_hooks;
|
|
64
59
|
_before;
|
|
@@ -227,10 +222,7 @@ var HookableCore = class {
|
|
|
227
222
|
return callHooks(hooks, args, 0);
|
|
228
223
|
}
|
|
229
224
|
};
|
|
230
|
-
//#endregion
|
|
231
|
-
//#region src/debugger.ts
|
|
232
225
|
const isBrowser = typeof window !== "undefined";
|
|
233
|
-
/** Start debugging hook names and timing in console */
|
|
234
226
|
function createDebugger(hooks, _options = {}) {
|
|
235
227
|
const options = {
|
|
236
228
|
inspect: isBrowser,
|
|
@@ -262,5 +254,4 @@ function createDebugger(hooks, _options = {}) {
|
|
|
262
254
|
unsubscribeAfter();
|
|
263
255
|
} };
|
|
264
256
|
}
|
|
265
|
-
//#endregion
|
|
266
257
|
export { Hookable, HookableCore, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookable",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Awaitable hook system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hook",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"test:types": "tsgo --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^25.
|
|
37
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
38
|
-
"@vitest/coverage-v8": "^4.1.
|
|
36
|
+
"@types/node": "^25.6.0",
|
|
37
|
+
"@typescript/native-preview": "^7.0.0-dev.20260414.1",
|
|
38
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
39
39
|
"changelogen": "^0.6.2",
|
|
40
|
-
"esbuild": "^0.
|
|
40
|
+
"esbuild": "^0.28.0",
|
|
41
41
|
"eslint-config-unjs": "^0.6.2",
|
|
42
42
|
"expect-type": "^1.3.0",
|
|
43
|
-
"hookable-prev": "npm:hookable@^6.0
|
|
43
|
+
"hookable-prev": "npm:hookable@^6.1.0",
|
|
44
44
|
"mitata": "^1.0.34",
|
|
45
|
-
"obuild": "^0.4.
|
|
46
|
-
"oxfmt": "^0.
|
|
47
|
-
"oxlint": "^1.
|
|
48
|
-
"typescript": "^
|
|
49
|
-
"vite": "^8.0.
|
|
50
|
-
"vitest": "^4.1.
|
|
45
|
+
"obuild": "^0.4.33",
|
|
46
|
+
"oxfmt": "^0.45.0",
|
|
47
|
+
"oxlint": "^1.60.0",
|
|
48
|
+
"typescript": "^6.0.2",
|
|
49
|
+
"vite": "^8.0.8",
|
|
50
|
+
"vitest": "^4.1.4"
|
|
51
51
|
},
|
|
52
|
-
"packageManager": "pnpm@10.
|
|
52
|
+
"packageManager": "pnpm@10.33.0"
|
|
53
53
|
}
|