hookable 6.0.1 → 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 +2 -10
- package/dist/index.mjs +5 -14
- package/package.json +24 -23
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;
|
|
@@ -39,6 +36,7 @@ declare class Hookable<HooksT extends Record<string, any> = Record<string, HookC
|
|
|
39
36
|
}): () => void;
|
|
40
37
|
hookOnce<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): () => void;
|
|
41
38
|
removeHook<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): void;
|
|
39
|
+
clearHook<NameT extends HookNameT>(name: NameT): void;
|
|
42
40
|
deprecateHook<NameT extends HookNameT>(name: NameT, deprecated: HookKeys<HooksT> | DeprecatedHook<HooksT>): void;
|
|
43
41
|
deprecateHooks(deprecatedHooks: Partial<Record<HookNameT, DeprecatedHook<HooksT>>>): void;
|
|
44
42
|
addHooks(configHooks: NestedHooks<HooksT>): () => void;
|
|
@@ -60,8 +58,6 @@ declare class HookableCore<HooksT extends Record<string, any> = Record<string, H
|
|
|
60
58
|
removeHook<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): void;
|
|
61
59
|
callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any> | void;
|
|
62
60
|
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/utils.d.ts
|
|
65
61
|
declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
|
|
66
62
|
declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
|
|
67
63
|
declare function serial<T>(tasks: T[], function_: (task: T) => Promise<any> | any): Promise<any>;
|
|
@@ -77,8 +73,6 @@ declare global {
|
|
|
77
73
|
declare function serialCaller(hooks: HookCallback[], arguments_?: any[]): Promise<any>;
|
|
78
74
|
/** @deprecated */
|
|
79
75
|
declare function parallelCaller(hooks: HookCallback[], args?: any[]): Promise<any>;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/debugger.d.ts
|
|
82
76
|
interface CreateDebuggerOptions {
|
|
83
77
|
/** An optional tag to prefix console logs with */
|
|
84
78
|
tag?: string;
|
|
@@ -99,8 +93,6 @@ interface CreateDebuggerOptions {
|
|
|
99
93
|
}
|
|
100
94
|
/** Start debugging hook names and timing in console */
|
|
101
95
|
declare function createDebugger(hooks: Hookable<any>, _options?: CreateDebuggerOptions): {
|
|
102
|
-
/** Stop debugging and remove listeners */
|
|
103
|
-
close: () => void;
|
|
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,20 +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
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/hookable.ts
|
|
63
57
|
var Hookable = class {
|
|
64
58
|
_hooks;
|
|
65
59
|
_before;
|
|
@@ -127,6 +121,9 @@ var Hookable = class {
|
|
|
127
121
|
if (hooks.length === 0) this._hooks[name] = void 0;
|
|
128
122
|
}
|
|
129
123
|
}
|
|
124
|
+
clearHook(name) {
|
|
125
|
+
this._hooks[name] = void 0;
|
|
126
|
+
}
|
|
130
127
|
deprecateHook(name, deprecated) {
|
|
131
128
|
this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
|
|
132
129
|
const _hooks = this._hooks[name] || [];
|
|
@@ -225,11 +222,7 @@ var HookableCore = class {
|
|
|
225
222
|
return callHooks(hooks, args, 0);
|
|
226
223
|
}
|
|
227
224
|
};
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/debugger.ts
|
|
231
225
|
const isBrowser = typeof window !== "undefined";
|
|
232
|
-
/** Start debugging hook names and timing in console */
|
|
233
226
|
function createDebugger(hooks, _options = {}) {
|
|
234
227
|
const options = {
|
|
235
228
|
inspect: isBrowser,
|
|
@@ -261,6 +254,4 @@ function createDebugger(hooks, _options = {}) {
|
|
|
261
254
|
unsubscribeAfter();
|
|
262
255
|
} };
|
|
263
256
|
}
|
|
264
|
-
|
|
265
|
-
//#endregion
|
|
266
|
-
export { Hookable, HookableCore, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
|
|
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.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Awaitable hook system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hook",
|
|
@@ -9,44 +9,45 @@
|
|
|
9
9
|
"tapable",
|
|
10
10
|
"tappable"
|
|
11
11
|
],
|
|
12
|
-
"repository": "unjs/hookable",
|
|
13
12
|
"license": "MIT",
|
|
14
|
-
"
|
|
13
|
+
"repository": "unjs/hookable",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
15
17
|
"type": "module",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"main": "./dist/index.mjs",
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
16
21
|
"exports": {
|
|
17
22
|
".": "./dist/index.mjs"
|
|
18
23
|
},
|
|
19
|
-
"main": "./dist/index.mjs",
|
|
20
|
-
"types": "./dist/index.d.mts",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
24
|
"scripts": {
|
|
25
25
|
"bench": "node --expose-gc --allow-natives-syntax test/bench.ts",
|
|
26
26
|
"build": "obuild src/index.ts",
|
|
27
27
|
"dev": "vitest",
|
|
28
|
-
"lint": "
|
|
29
|
-
"lint:fix": "
|
|
28
|
+
"lint": "oxlint . && oxfmt --check src test",
|
|
29
|
+
"lint:fix": "oxlint . --fix && oxfmt src test",
|
|
30
30
|
"prepublish": "pnpm build",
|
|
31
31
|
"release": "pnpm test && pnpm build && changelogen --release --publish --push",
|
|
32
32
|
"test": "pnpm lint && vitest run --coverage",
|
|
33
|
-
"test:types": "
|
|
33
|
+
"test:types": "tsgo --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^25.0
|
|
37
|
-
"@
|
|
36
|
+
"@types/node": "^25.6.0",
|
|
37
|
+
"@typescript/native-preview": "^7.0.0-dev.20260414.1",
|
|
38
|
+
"@vitest/coverage-v8": "^4.1.4",
|
|
38
39
|
"changelogen": "^0.6.2",
|
|
39
|
-
"esbuild": "^0.
|
|
40
|
-
"eslint": "^
|
|
41
|
-
"eslint-config-unjs": "^0.5.0",
|
|
40
|
+
"esbuild": "^0.28.0",
|
|
41
|
+
"eslint-config-unjs": "^0.6.2",
|
|
42
42
|
"expect-type": "^1.3.0",
|
|
43
|
-
"hookable-prev": "npm:hookable@^
|
|
43
|
+
"hookable-prev": "npm:hookable@^6.1.0",
|
|
44
44
|
"mitata": "^1.0.34",
|
|
45
|
-
"obuild": "^0.4.
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
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"
|
|
50
51
|
},
|
|
51
|
-
"packageManager": "pnpm@10.
|
|
52
|
+
"packageManager": "pnpm@10.33.0"
|
|
52
53
|
}
|