hookable 5.0.0-1 → 5.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/README.md +15 -15
- package/dist/index.cjs +26 -12
- package/dist/index.d.ts +62 -0
- package/dist/index.mjs +25 -13
- package/package.json +8 -9
- package/CHANGELOG.md +0 -254
- package/types/hookable.d.ts +0 -43
- package/types/index.d.ts +0 -36
package/README.md
CHANGED
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
[![packagephobia][packagephobia-src]][packagephobia-href]
|
|
6
6
|
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
|
|
7
7
|
[![Codecov][codecov-src]][codecov-href]
|
|
8
|
-
[![Dependencies][david-dm-src]][david-dm-href]
|
|
9
8
|
|
|
10
|
-
> Awaitable
|
|
11
|
-
|
|
12
|
-
**Please see [Migration Guide](#migration) for migrating from < 4.0.0 to >= 5.0.0**
|
|
9
|
+
> Awaitable hook system
|
|
13
10
|
|
|
14
11
|
## Install
|
|
15
12
|
|
|
@@ -88,7 +85,7 @@ const hook2 = async () => { /* ... */ }
|
|
|
88
85
|
|
|
89
86
|
// The hook() method returns an "unregister" function
|
|
90
87
|
const unregisterHook0 = lib.hook('hook0', hook0)
|
|
91
|
-
const unregisterHooks1and2 lib.addHooks({ hook1, hook2 })
|
|
88
|
+
const unregisterHooks1and2 = lib.addHooks({ hook1, hook2 })
|
|
92
89
|
|
|
93
90
|
/* ... */
|
|
94
91
|
|
|
@@ -155,6 +152,14 @@ Returns an `unregister` function that, when called, will remove all the register
|
|
|
155
152
|
|
|
156
153
|
Used by class itself to **sequentially** call handlers of a specific hook.
|
|
157
154
|
|
|
155
|
+
### `callHookWith (name, callerFn)`
|
|
156
|
+
|
|
157
|
+
If you need custom control over how hooks are called, you can provide a custom function that will receive an array of handlers of a specific hook.
|
|
158
|
+
|
|
159
|
+
`callerFn` if a callback function that accepts two arguments, `hooks` and `args`:
|
|
160
|
+
- `hooks`: Array of user hooks to be called
|
|
161
|
+
- `args`: Array of arguments that should be passed each time calling a hook
|
|
162
|
+
|
|
158
163
|
### `deprecateHook (old, name)`
|
|
159
164
|
|
|
160
165
|
Deprecate hook called `old` in favor of `name` hook.
|
|
@@ -202,15 +207,13 @@ hookable.removeHooks({
|
|
|
202
207
|
|
|
203
208
|
## Credits
|
|
204
209
|
|
|
205
|
-
Extracted from [Nuxt
|
|
206
|
-
|
|
207
|
-
Original author [Sébastien Chopin](https://github.com/Atinux)
|
|
210
|
+
Extracted from [Nuxt](https://github.com/nuxt/nuxt.js) hooks system originally introduced by [Sébastien Chopin](https://github.com/Atinux)
|
|
208
211
|
|
|
209
|
-
Thanks to [Joe Paice](https://github.com/RGBboy) for donating [hookable](https://www.npmjs.com/package/hookable) package name
|
|
212
|
+
Thanks to [Joe Paice](https://github.com/RGBboy) for donating [hookable](https://www.npmjs.com/package/hookable) package name.
|
|
210
213
|
|
|
211
214
|
## License
|
|
212
215
|
|
|
213
|
-
MIT - Made with 💖
|
|
216
|
+
MIT - Made with 💖
|
|
214
217
|
|
|
215
218
|
<!-- Badges -->
|
|
216
219
|
[npm-version-src]: https://flat.badgen.net/npm/dt/hookable
|
|
@@ -219,14 +222,11 @@ MIT - Made with 💖 by Nuxt.js team!
|
|
|
219
222
|
[npm-downloads-src]: https://flat.badgen.net/npm/v/hookable
|
|
220
223
|
[npm-downloads-href]: https://npmjs.com/package/hookable
|
|
221
224
|
|
|
222
|
-
[github-actions-ci-src]: https://
|
|
223
|
-
[github-actions-ci-href]: https://github.com/unjs/hookable/actions
|
|
225
|
+
[github-actions-ci-src]: https://flat.badgen.net/github/checks/unjs/hookable/main
|
|
226
|
+
[github-actions-ci-href]: https://github.com/unjs/hookable/actions
|
|
224
227
|
|
|
225
228
|
[codecov-src]: https://flat.badgen.net/codecov/c/github/unjs/hookable
|
|
226
229
|
[codecov-href]: https://codecov.io/gh/unjs/hookable
|
|
227
230
|
|
|
228
|
-
[david-dm-src]: https://flat.badgen.net/david/dep/unjs/hookable
|
|
229
|
-
[david-dm-href]: https://david-dm.org/unjs/hookable
|
|
230
|
-
|
|
231
231
|
[packagephobia-src]: https://flat.badgen.net/packagephobia/install/hookable
|
|
232
232
|
[packagephobia-href]: https://packagephobia.now.sh/result?p=hookable
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,12 @@ function mergeHooks(...hooks) {
|
|
|
39
39
|
function serial(tasks, fn) {
|
|
40
40
|
return tasks.reduce((promise, task) => promise.then(() => fn(task)), Promise.resolve(null));
|
|
41
41
|
}
|
|
42
|
+
function serialCaller(hooks, args) {
|
|
43
|
+
return hooks.reduce((promise, hookFn) => promise.then(() => hookFn.apply(void 0, args)), Promise.resolve(null));
|
|
44
|
+
}
|
|
45
|
+
function parallelCaller(hooks, args) {
|
|
46
|
+
return Promise.all(hooks.map((hook) => hook.apply(void 0, args)));
|
|
47
|
+
}
|
|
42
48
|
|
|
43
49
|
class Hookable {
|
|
44
50
|
constructor() {
|
|
@@ -46,6 +52,7 @@ class Hookable {
|
|
|
46
52
|
this._deprecatedHooks = {};
|
|
47
53
|
this.hook = this.hook.bind(this);
|
|
48
54
|
this.callHook = this.callHook.bind(this);
|
|
55
|
+
this.callHookWith = this.callHookWith.bind(this);
|
|
49
56
|
}
|
|
50
57
|
hook(name, fn) {
|
|
51
58
|
if (!name || typeof fn !== "function") {
|
|
@@ -53,19 +60,21 @@ class Hookable {
|
|
|
53
60
|
};
|
|
54
61
|
}
|
|
55
62
|
const originalName = name;
|
|
56
|
-
let
|
|
63
|
+
let deprecatedHookObj;
|
|
57
64
|
while (this._deprecatedHooks[name]) {
|
|
58
|
-
deprecatedHook = this._deprecatedHooks[name];
|
|
65
|
+
const deprecatedHook = this._deprecatedHooks[name];
|
|
59
66
|
if (typeof deprecatedHook === "string") {
|
|
60
|
-
|
|
67
|
+
deprecatedHookObj = { to: deprecatedHook };
|
|
68
|
+
} else {
|
|
69
|
+
deprecatedHookObj = deprecatedHook;
|
|
61
70
|
}
|
|
62
|
-
name =
|
|
71
|
+
name = deprecatedHookObj.to;
|
|
63
72
|
}
|
|
64
|
-
if (
|
|
65
|
-
if (!
|
|
66
|
-
console.warn(`${originalName} hook has been deprecated` + (
|
|
73
|
+
if (deprecatedHookObj) {
|
|
74
|
+
if (!deprecatedHookObj.message) {
|
|
75
|
+
console.warn(`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : ""));
|
|
67
76
|
} else {
|
|
68
|
-
console.warn(
|
|
77
|
+
console.warn(deprecatedHookObj.message);
|
|
69
78
|
}
|
|
70
79
|
}
|
|
71
80
|
this._hooks[name] = this._hooks[name] || [];
|
|
@@ -119,10 +128,13 @@ class Hookable {
|
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
130
|
callHook(name, ...args) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
131
|
+
return serialCaller(this._hooks[name] || [], args);
|
|
132
|
+
}
|
|
133
|
+
callHookParallel(name, ...args) {
|
|
134
|
+
return parallelCaller(this._hooks[name] || [], args);
|
|
135
|
+
}
|
|
136
|
+
callHookWith(caller, name, ...args) {
|
|
137
|
+
return caller(this._hooks[name] || [], args);
|
|
126
138
|
}
|
|
127
139
|
}
|
|
128
140
|
function createHooks() {
|
|
@@ -133,4 +145,6 @@ exports.Hookable = Hookable;
|
|
|
133
145
|
exports.createHooks = createHooks;
|
|
134
146
|
exports.flatHooks = flatHooks;
|
|
135
147
|
exports.mergeHooks = mergeHooks;
|
|
148
|
+
exports.parallelCaller = parallelCaller;
|
|
136
149
|
exports.serial = serial;
|
|
150
|
+
exports.serialCaller = serialCaller;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare type HookCallback = (...args: any) => Promise<void> | void;
|
|
2
|
+
interface Hooks {
|
|
3
|
+
[key: string]: HookCallback;
|
|
4
|
+
}
|
|
5
|
+
declare type HookKeys<T> = keyof T & string;
|
|
6
|
+
declare type DeprecatedHook<T> = string | {
|
|
7
|
+
message?: string;
|
|
8
|
+
to: HookKeys<T>;
|
|
9
|
+
};
|
|
10
|
+
declare type DeprecatedHooks<T> = {
|
|
11
|
+
[name in HookKeys<T>]: DeprecatedHook<T>;
|
|
12
|
+
};
|
|
13
|
+
declare type ValueOf<C> = C extends Record<any, any> ? C[keyof C] : never;
|
|
14
|
+
declare type Strings<T> = Exclude<keyof T, number | symbol>;
|
|
15
|
+
declare type KnownKeys<T> = keyof {
|
|
16
|
+
[K in keyof T as string extends K ? never : number extends K ? never : K]: never;
|
|
17
|
+
};
|
|
18
|
+
declare type StripGeneric<T> = Pick<T, KnownKeys<T> extends keyof T ? KnownKeys<T> : never>;
|
|
19
|
+
declare type OnlyGeneric<T> = Omit<T, KnownKeys<T> extends keyof T ? KnownKeys<T> : never>;
|
|
20
|
+
declare type Namespaces<T> = ValueOf<{
|
|
21
|
+
[key in Strings<T>]: key extends `${infer Namespace}:${string}` ? Namespace : never;
|
|
22
|
+
}>;
|
|
23
|
+
declare type BareHooks<T> = ValueOf<{
|
|
24
|
+
[key in Strings<T>]: key extends `${string}:${string}` ? never : key;
|
|
25
|
+
}>;
|
|
26
|
+
declare type HooksInNamespace<T, Namespace extends string> = ValueOf<{
|
|
27
|
+
[key in Strings<T>]: key extends `${Namespace}:${infer HookName}` ? HookName : never;
|
|
28
|
+
}>;
|
|
29
|
+
declare type WithoutNamespace<T, Namespace extends string> = {
|
|
30
|
+
[key in HooksInNamespace<T, Namespace>]: `${Namespace}:${key}` extends keyof T ? T[`${Namespace}:${key}`] : never;
|
|
31
|
+
};
|
|
32
|
+
declare type NestedHooks<T> = (Partial<StripGeneric<T>> | Partial<OnlyGeneric<T>>) & Partial<{
|
|
33
|
+
[key in Namespaces<StripGeneric<T>>]: NestedHooks<WithoutNamespace<T, key>>;
|
|
34
|
+
}> & Partial<{
|
|
35
|
+
[key in BareHooks<StripGeneric<T>>]: T[key];
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
declare type InferCallback<HT, HN extends keyof HT> = HT[HN] extends HookCallback ? HT[HN] : never;
|
|
39
|
+
declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
|
|
40
|
+
private _hooks;
|
|
41
|
+
private _deprecatedHooks;
|
|
42
|
+
constructor();
|
|
43
|
+
hook<NameT extends HookNameT>(name: NameT, fn: InferCallback<HooksT, NameT>): () => void;
|
|
44
|
+
hookOnce<NameT extends HookNameT>(name: NameT, fn: InferCallback<HooksT, NameT>): () => void;
|
|
45
|
+
removeHook<NameT extends HookNameT>(name: NameT, fn: InferCallback<HooksT, NameT>): void;
|
|
46
|
+
deprecateHook<NameT extends HookNameT>(name: NameT, deprecated: DeprecatedHook<HooksT>): void;
|
|
47
|
+
deprecateHooks(deprecatedHooks: Record<HookNameT, DeprecatedHook<HooksT>>): void;
|
|
48
|
+
addHooks(configHooks: NestedHooks<HooksT>): () => void;
|
|
49
|
+
removeHooks(configHooks: NestedHooks<HooksT>): void;
|
|
50
|
+
callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any>;
|
|
51
|
+
callHookParallel<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any[]>;
|
|
52
|
+
callHookWith<NameT extends HookNameT, CallFunction extends (hooks: HookCallback[], args: Parameters<InferCallback<HooksT, NameT>>) => any>(caller: CallFunction, name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): void | ReturnType<CallFunction>;
|
|
53
|
+
}
|
|
54
|
+
declare function createHooks<T>(): Hookable<T>;
|
|
55
|
+
|
|
56
|
+
declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
|
|
57
|
+
declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
|
|
58
|
+
declare function serial<T>(tasks: T[], fn: (task: T) => Promise<any> | any): Promise<any>;
|
|
59
|
+
declare function serialCaller(hooks: HookCallback[], args?: any[]): Promise<any>;
|
|
60
|
+
declare function parallelCaller(hooks: HookCallback[], args?: any[]): Promise<any[]>;
|
|
61
|
+
|
|
62
|
+
export { DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hookable, Hooks, NestedHooks, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
|
package/dist/index.mjs
CHANGED
|
@@ -35,6 +35,12 @@ function mergeHooks(...hooks) {
|
|
|
35
35
|
function serial(tasks, fn) {
|
|
36
36
|
return tasks.reduce((promise, task) => promise.then(() => fn(task)), Promise.resolve(null));
|
|
37
37
|
}
|
|
38
|
+
function serialCaller(hooks, args) {
|
|
39
|
+
return hooks.reduce((promise, hookFn) => promise.then(() => hookFn.apply(void 0, args)), Promise.resolve(null));
|
|
40
|
+
}
|
|
41
|
+
function parallelCaller(hooks, args) {
|
|
42
|
+
return Promise.all(hooks.map((hook) => hook.apply(void 0, args)));
|
|
43
|
+
}
|
|
38
44
|
|
|
39
45
|
class Hookable {
|
|
40
46
|
constructor() {
|
|
@@ -42,6 +48,7 @@ class Hookable {
|
|
|
42
48
|
this._deprecatedHooks = {};
|
|
43
49
|
this.hook = this.hook.bind(this);
|
|
44
50
|
this.callHook = this.callHook.bind(this);
|
|
51
|
+
this.callHookWith = this.callHookWith.bind(this);
|
|
45
52
|
}
|
|
46
53
|
hook(name, fn) {
|
|
47
54
|
if (!name || typeof fn !== "function") {
|
|
@@ -49,19 +56,21 @@ class Hookable {
|
|
|
49
56
|
};
|
|
50
57
|
}
|
|
51
58
|
const originalName = name;
|
|
52
|
-
let
|
|
59
|
+
let deprecatedHookObj;
|
|
53
60
|
while (this._deprecatedHooks[name]) {
|
|
54
|
-
deprecatedHook = this._deprecatedHooks[name];
|
|
61
|
+
const deprecatedHook = this._deprecatedHooks[name];
|
|
55
62
|
if (typeof deprecatedHook === "string") {
|
|
56
|
-
|
|
63
|
+
deprecatedHookObj = { to: deprecatedHook };
|
|
64
|
+
} else {
|
|
65
|
+
deprecatedHookObj = deprecatedHook;
|
|
57
66
|
}
|
|
58
|
-
name =
|
|
67
|
+
name = deprecatedHookObj.to;
|
|
59
68
|
}
|
|
60
|
-
if (
|
|
61
|
-
if (!
|
|
62
|
-
console.warn(`${originalName} hook has been deprecated` + (
|
|
69
|
+
if (deprecatedHookObj) {
|
|
70
|
+
if (!deprecatedHookObj.message) {
|
|
71
|
+
console.warn(`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : ""));
|
|
63
72
|
} else {
|
|
64
|
-
console.warn(
|
|
73
|
+
console.warn(deprecatedHookObj.message);
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
this._hooks[name] = this._hooks[name] || [];
|
|
@@ -115,14 +124,17 @@ class Hookable {
|
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
126
|
callHook(name, ...args) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
127
|
+
return serialCaller(this._hooks[name] || [], args);
|
|
128
|
+
}
|
|
129
|
+
callHookParallel(name, ...args) {
|
|
130
|
+
return parallelCaller(this._hooks[name] || [], args);
|
|
131
|
+
}
|
|
132
|
+
callHookWith(caller, name, ...args) {
|
|
133
|
+
return caller(this._hooks[name] || [], args);
|
|
122
134
|
}
|
|
123
135
|
}
|
|
124
136
|
function createHooks() {
|
|
125
137
|
return new Hookable();
|
|
126
138
|
}
|
|
127
139
|
|
|
128
|
-
export { Hookable, createHooks, flatHooks, mergeHooks, serial };
|
|
140
|
+
export { Hookable, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hookable",
|
|
3
|
-
"version": "5.
|
|
4
|
-
"description": "Awaitable
|
|
3
|
+
"version": "5.1.1",
|
|
4
|
+
"description": "Awaitable hook system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hook",
|
|
7
7
|
"hookable",
|
|
@@ -17,13 +17,12 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.cjs",
|
|
19
19
|
"module": "./dist/index.mjs",
|
|
20
|
-
"types": "./
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
"types"
|
|
22
|
+
"dist"
|
|
24
23
|
],
|
|
25
24
|
"scripts": {
|
|
26
|
-
"build": "
|
|
25
|
+
"build": "unbuild",
|
|
27
26
|
"lint": "eslint --ext .ts src",
|
|
28
27
|
"prepublish": "yarn build",
|
|
29
28
|
"release": "yarn test && yarn build && standard-version && git push --follow-tags && npm publish",
|
|
@@ -35,11 +34,11 @@
|
|
|
35
34
|
"babel-jest": "latest",
|
|
36
35
|
"codecov": "latest",
|
|
37
36
|
"eslint": "latest",
|
|
37
|
+
"expect-type": "^0.12.0",
|
|
38
38
|
"jest": "latest",
|
|
39
|
-
"rollup-plugin-typescript2": "latest",
|
|
40
|
-
"siroc": "latest",
|
|
41
39
|
"standard-version": "latest",
|
|
42
40
|
"ts-jest": "latest",
|
|
43
|
-
"typescript": "latest"
|
|
41
|
+
"typescript": "latest",
|
|
42
|
+
"unbuild": "latest"
|
|
44
43
|
}
|
|
45
44
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
## [5.0.0-1](https://github.com/unjs/hookable/compare/v5.0.0-0...v5.0.0-1) (2021-08-27)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* allow nested hooks type to omit some hooks ([#28](https://github.com/unjs/hookable/issues/28)) ([75f2a05](https://github.com/unjs/hookable/commit/75f2a057a526d018b9cf39f01ddfd2a3d2a6bbc1))
|
|
11
|
-
|
|
12
|
-
## [5.0.0-0](https://github.com/unjs/hookable/compare/v4.4.1...v5.0.0-0) (2021-08-26)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### ⚠ BREAKING CHANGES
|
|
16
|
-
|
|
17
|
-
* You should directly handle errors with callHook
|
|
18
|
-
* use named exports and expose createHooks
|
|
19
|
-
* remove mergehooks from Hookable prototype
|
|
20
|
-
* drop browser build and use exports field
|
|
21
|
-
* improve type checking
|
|
22
|
-
|
|
23
|
-
### Features
|
|
24
|
-
|
|
25
|
-
* drop browser build and use exports field ([b626770](https://github.com/unjs/hookable/commit/b626770192a62b23acc1be16b4e4eac2383e9136))
|
|
26
|
-
* drop logger and global error handler ([ee6ea87](https://github.com/unjs/hookable/commit/ee6ea87ad0e15a52252389b9b3112060bd411330))
|
|
27
|
-
* improve type checking ([c2e1e22](https://github.com/unjs/hookable/commit/c2e1e223d16e7bf87117cd8d72ad3ba211a333d8))
|
|
28
|
-
* use named exports and expose createHooks ([fadfcbd](https://github.com/unjs/hookable/commit/fadfcbd07c3e2fa6905d0e31deabc37fc55d8317))
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* remove mergehooks from Hookable prototype ([d50af59](https://github.com/unjs/hookable/commit/d50af595d3cb05be8fb5060374f4e28b3d6259fa))
|
|
32
|
-
|
|
33
|
-
### [4.4.1](https://github.com/unjs/hookable/compare/v4.4.0...v4.4.1) (2021-02-26)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* avoid creating extra wrapper when merging hooks ([790c1c4](https://github.com/unjs/hookable/commit/790c1c4dbbd1f7b9cb1995b40baeecead5346ed0))
|
|
39
|
-
|
|
40
|
-
## [4.4.0](https://github.com/unjs/hookable/compare/v4.3.1...v4.4.0) (2021-01-21)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Features
|
|
44
|
-
|
|
45
|
-
* **pkg:** expose module format ([2987b09](https://github.com/unjs/hookable/commit/2987b0901e292eb4570f8141ca51cfd9d2d3f94f))
|
|
46
|
-
|
|
47
|
-
### [4.3.1](https://github.com/unjs/hookable/compare/v4.3.0...v4.3.1) (2020-11-06)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Bug Fixes
|
|
51
|
-
|
|
52
|
-
* expose types ([0ffbaff](https://github.com/unjs/hookable/commit/0ffbaffa91d38e333e0818cd73a084cf1e8657c8))
|
|
53
|
-
|
|
54
|
-
## [4.3.0](https://github.com/unjs/hookable/compare/v4.2.0...v4.3.0) (2020-11-06)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Features
|
|
58
|
-
|
|
59
|
-
* `mergeHooks` helper ([#26](https://github.com/unjs/hookable/issues/26)) ([8c52d03](https://github.com/unjs/hookable/commit/8c52d034aa1a40bafb13d0b847c72593c51fcba5))
|
|
60
|
-
|
|
61
|
-
## [4.2.0](https://github.com/unjs/hookable/compare/v4.1.2...v4.2.0) (2020-10-23)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
* hookOnce ([225fa8a](https://github.com/unjs/hookable/commit/225fa8af85e1a504916c357f57b047143b6bc5ab))
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
### Bug Fixes
|
|
70
|
-
|
|
71
|
-
* typecheck for flatHooks ([7800190](https://github.com/unjs/hookable/commit/7800190feb82134be5dd089ca184a18a6644da19))
|
|
72
|
-
|
|
73
|
-
### [4.1.2](https://github.com/unjs/hookable/compare/v4.1.1...v4.1.2) (2020-08-24)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Bug Fixes
|
|
77
|
-
|
|
78
|
-
* **build:** exclude regenerator and update target to ie 11 ([48acfc5](https://github.com/unjs/hookable/commit/48acfc5c0a4b0fb8edc6e9790b37ad336c966215))
|
|
79
|
-
|
|
80
|
-
### [4.1.1](https://github.com/unjs/hookable/compare/v4.1.0...v4.1.1) (2020-04-28)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Bug Fixes
|
|
84
|
-
|
|
85
|
-
* **pkg:** typo in types entry name (fixes [#19](https://github.com/unjs/hookable/issues/19)) ([b9ba90f](https://github.com/unjs/hookable/commit/b9ba90fbc725097e41c430d7df4205985c2faaec))
|
|
86
|
-
|
|
87
|
-
## [4.1.0](https://github.com/unjs/hookable/compare/v4.0.0...v4.1.0) (2020-04-17)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
### Features
|
|
91
|
-
|
|
92
|
-
* **types:** implement strict types ([823cdca](https://github.com/unjs/hookable/commit/823cdcac728d189b802f75faa9a361ac5ea4883d))
|
|
93
|
-
|
|
94
|
-
## [4.0.0](https://github.com/unjs/hookable/compare/v3.0.0...v4.0.0) (2020-04-17)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
### ⚠ BREAKING CHANGES
|
|
98
|
-
|
|
99
|
-
* only dist and types getting published
|
|
100
|
-
|
|
101
|
-
### Features
|
|
102
|
-
|
|
103
|
-
* allow disabling logger ([f8fb742](https://github.com/unjs/hookable/commit/f8fb74224f1277ec7f7d5a37bd312af7514fc962))
|
|
104
|
-
* allow removing registered hooks ([#16](https://github.com/unjs/hookable/issues/16)) ([4134c31](https://github.com/unjs/hookable/commit/4134c31c44256cc82cac3a7a3610ece9252431dc))
|
|
105
|
-
* migrate to typescript ([d63ea3e](https://github.com/unjs/hookable/commit/d63ea3e408ebea74ea3855af0c6e51880ebf9cac))
|
|
106
|
-
|
|
107
|
-
## [3.0.0](https://github.com/unjs/hookable/compare/v2.3.0...v3.0.0) (2020-02-25)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
### Bug Fixes
|
|
111
|
-
|
|
112
|
-
* revert back hooks ([07f52dc](https://github.com/unjs/hookable/commit/07f52dc))
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
### Features
|
|
116
|
-
|
|
117
|
-
* advanced deprecation ([5b88628](https://github.com/unjs/hookable/commit/5b88628))
|
|
118
|
-
* bundle package ([53a2a0e](https://github.com/unjs/hookable/commit/53a2a0e))
|
|
119
|
-
|
|
120
|
-
# [2.3.0](https://github.com/unjs/hookable/compare/v2.2.1...v2.3.0) (2019-09-01)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Features
|
|
124
|
-
|
|
125
|
-
* hide deprecate warnings on production builds ([0861df3](https://github.com/unjs/hookable/commit/0861df3))
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
## [2.2.1](https://github.com/unjs/hookable/compare/v2.2.0...v2.2.1) (2019-08-21)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
# [2.2.0](https://github.com/unjs/hookable/compare/v2.1.0...v2.2.0) (2019-08-21)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
### Features
|
|
137
|
-
|
|
138
|
-
* deprecateHooks ([62f2d38](https://github.com/unjs/hookable/commit/62f2d38))
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# [2.1.0](https://github.com/unjs/hookable/compare/v2.0.1...v2.1.0) (2019-08-21)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Features
|
|
146
|
-
|
|
147
|
-
* optional fatal support for logger ([7c7355d](https://github.com/unjs/hookable/commit/7c7355d))
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
## [2.0.1](https://github.com/unjs/hookable/compare/v2.0.0...v2.0.1) (2019-08-21)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
# [2.0.0](https://github.com/unjs/hookable/compare/v1.0.1...v2.0.0) (2019-08-21)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### Features
|
|
159
|
-
|
|
160
|
-
* custom logger ([ada6e37](https://github.com/unjs/hookable/commit/ada6e37))
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### BREAKING CHANGES
|
|
164
|
-
|
|
165
|
-
* console is replaced by consola by default
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
## [1.0.1](https://github.com/unjs/hookable/compare/v1.0.0...v1.0.1) (2019-03-16)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
### Bug Fixes
|
|
173
|
-
|
|
174
|
-
* fix package.json (2) ([7ff4ce9](https://github.com/unjs/hookable/commit/7ff4ce9))
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
<a name="1.0.0"></a>
|
|
179
|
-
# [1.0.0](https://github.com/unjs/hookable/compare/v0.0.7...v1.0.0) (2019-02-11)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
### Features
|
|
183
|
-
|
|
184
|
-
* rewrite for 1.0.0 ([88decae](https://github.com/unjs/hookable/commit/88decae))
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
### BREAKING CHANGES
|
|
188
|
-
|
|
189
|
-
* api change
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<a name="0.0.7"></a>
|
|
194
|
-
## [0.0.7](https://github.com/pi0/hookable/compare/v0.0.6...v0.0.7) (2018-01-28)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
### Bug Fixes
|
|
198
|
-
|
|
199
|
-
* hook with array or falsy key ([7e90de1](https://github.com/pi0/hookable/commit/7e90de1))
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
### Performance Improvements
|
|
203
|
-
|
|
204
|
-
* use for in for hookObj ([3c8e2e7](https://github.com/pi0/hookable/commit/3c8e2e7))
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
<a name="0.0.6"></a>
|
|
209
|
-
## [0.0.6](https://github.com/pi0/hookable/compare/v0.0.5...v0.0.6) (2018-01-26)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
### Performance Improvements
|
|
213
|
-
|
|
214
|
-
* reduce transpiled dist size ([df607cf](https://github.com/pi0/hookable/commit/df607cf))
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
<a name="0.0.5"></a>
|
|
219
|
-
## [0.0.5](https://github.com/pi0/hookable/compare/v0.0.4...v0.0.5) (2018-01-26)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### Bug Fixes
|
|
223
|
-
|
|
224
|
-
* **package:** lib ~> dist ([34a8d5c](https://github.com/pi0/hookable/commit/34a8d5c))
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
<a name="0.0.4"></a>
|
|
229
|
-
## [0.0.4](https://github.com/pi0/hookable/compare/v0.0.3...v0.0.4) (2018-01-26)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
### Performance Improvements
|
|
233
|
-
|
|
234
|
-
* handle fn as array faster ([ec35edc](https://github.com/pi0/hookable/commit/ec35edc))
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
<a name="0.0.3"></a>
|
|
239
|
-
## [0.0.3](https://github.com/pi0/hookable/compare/v0.0.2...v0.0.3) (2018-01-26)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
### Bug Fixes
|
|
243
|
-
|
|
244
|
-
* bind hookObj to this context ([6f6f7bc](https://github.com/pi0/hookable/commit/6f6f7bc))
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
### Performance Improvements
|
|
248
|
-
|
|
249
|
-
* minor refactor ([e4083aa](https://github.com/pi0/hookable/commit/e4083aa))
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
<a name="0.0.2"></a>
|
|
254
|
-
## 0.0.2 (2018-01-26)
|
package/types/hookable.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
declare type HookCallback = (...args: any) => Promise<void> | void;
|
|
2
|
-
interface Hooks {
|
|
3
|
-
[key: string]: HookCallback;
|
|
4
|
-
}
|
|
5
|
-
declare type HookKeys<T> = keyof T & string;
|
|
6
|
-
declare type NestedHooks<T> = {
|
|
7
|
-
[name in HookKeys<T>]: NestedHooks<T> | HookCallback;
|
|
8
|
-
};
|
|
9
|
-
declare type DeprecatedHook<T> = string | {
|
|
10
|
-
message: string;
|
|
11
|
-
to: HookKeys<T>;
|
|
12
|
-
};
|
|
13
|
-
declare type DeprecatedHooks<T> = {
|
|
14
|
-
[name in HookKeys<T>]: DeprecatedHook<T>;
|
|
15
|
-
};
|
|
16
|
-
interface LoggerT {
|
|
17
|
-
error(...args: any): void;
|
|
18
|
-
fatal?(...args: any): void;
|
|
19
|
-
warn(...args: any): void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
|
|
23
|
-
|
|
24
|
-
declare class Hookable<_HooksT = Record<string, HookCallback>, HooksT = _HooksT & {
|
|
25
|
-
error: (error: Error | any) => void;
|
|
26
|
-
}, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
|
|
27
|
-
private _hooks;
|
|
28
|
-
private _deprecatedHooks;
|
|
29
|
-
private _logger;
|
|
30
|
-
static mergeHooks: typeof mergeHooks;
|
|
31
|
-
mergeHooks: typeof mergeHooks;
|
|
32
|
-
constructor(logger?: LoggerT | false);
|
|
33
|
-
hook<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): () => void;
|
|
34
|
-
hookOnce<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): any;
|
|
35
|
-
removeHook<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): void;
|
|
36
|
-
deprecateHook<NameT extends HookNameT>(name: NameT, deprecated: DeprecatedHook<HooksT>): void;
|
|
37
|
-
deprecateHooks(deprecatedHooks: Record<HookNameT, DeprecatedHook<HooksT>>): void;
|
|
38
|
-
addHooks(configHooks: NestedHooks<HooksT>): () => void;
|
|
39
|
-
removeHooks(configHooks: NestedHooks<HooksT>): void;
|
|
40
|
-
callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<HooksT[NameT]>): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hooks, LoggerT, NestedHooks, Hookable as default };
|
package/types/index.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
declare type HookCallback = (...args: any) => Promise<void> | void;
|
|
2
|
-
interface Hooks {
|
|
3
|
-
[key: string]: HookCallback;
|
|
4
|
-
}
|
|
5
|
-
declare type HookKeys<T> = keyof T & string;
|
|
6
|
-
declare type NestedHooks<T> = Partial<{
|
|
7
|
-
[name in HookKeys<T>]: NestedHooks<T> | HookCallback;
|
|
8
|
-
}>;
|
|
9
|
-
declare type DeprecatedHook<T> = string | {
|
|
10
|
-
message: string;
|
|
11
|
-
to: HookKeys<T>;
|
|
12
|
-
};
|
|
13
|
-
declare type DeprecatedHooks<T> = {
|
|
14
|
-
[name in HookKeys<T>]: DeprecatedHook<T>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
|
|
18
|
-
private _hooks;
|
|
19
|
-
private _deprecatedHooks;
|
|
20
|
-
constructor();
|
|
21
|
-
hook<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): () => void;
|
|
22
|
-
hookOnce<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): any;
|
|
23
|
-
removeHook<NameT extends HookNameT>(name: NameT, fn: HooksT[NameT] & HookCallback): void;
|
|
24
|
-
deprecateHook<NameT extends HookNameT>(name: NameT, deprecated: DeprecatedHook<HooksT>): void;
|
|
25
|
-
deprecateHooks(deprecatedHooks: Record<HookNameT, DeprecatedHook<HooksT>>): void;
|
|
26
|
-
addHooks(configHooks: NestedHooks<HooksT>): () => void;
|
|
27
|
-
removeHooks(configHooks: NestedHooks<HooksT>): void;
|
|
28
|
-
callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<HooksT[NameT]>): Promise<any>;
|
|
29
|
-
}
|
|
30
|
-
declare function createHooks<T>(): Hookable<T>;
|
|
31
|
-
|
|
32
|
-
declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
|
|
33
|
-
declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
|
|
34
|
-
declare function serial<T>(tasks: T[], fn: (task: T) => Promise<any> | any): Promise<any>;
|
|
35
|
-
|
|
36
|
-
export { DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hookable, Hooks, NestedHooks, createHooks, flatHooks, mergeHooks, serial };
|