hookable 5.0.0 → 5.1.2

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 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 hooks for Node.js and Browser
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
 
@@ -47,7 +44,7 @@ hooks.callHook('hello')
47
44
  ```js
48
45
  import { Hookable } from 'hookable'
49
46
 
50
- export default class Foo extends Hookable {
47
+ export default class FooLib extends Hookable {
51
48
  constructor() {
52
49
  // Call to parent to initialize
53
50
  super()
@@ -65,7 +62,7 @@ export default class Foo extends Hookable {
65
62
  **Inside plugins, register for any hook:**
66
63
 
67
64
  ```js
68
- const lib = newFooLib()
65
+ const lib = new FooLib()
69
66
 
70
67
  // Register a handler for `hook2`
71
68
  lib.hook('hook2', async () => { /* ... */ })
@@ -80,7 +77,7 @@ lib.addHooks({
80
77
  **Unregistering hooks:**
81
78
 
82
79
  ```js
83
- const lib = newFooLib()
80
+ const lib = new FooLib()
84
81
 
85
82
  const hook0 = async () => { /* ... */ }
86
83
  const hook1 = async () => { /* ... */ }
@@ -104,7 +101,7 @@ lib.removeHook('hook2', hook2)
104
101
  **Triggering a hook handler once:**
105
102
 
106
103
  ```js
107
- const lib = newFooLib()
104
+ const lib = new FooLib()
108
105
 
109
106
  const unregister = lib.hook('hook0', async () => {
110
107
  // Unregister as soon as the hook is executed
@@ -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.js](https://github.com/nuxt/nuxt.js) hooks system
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 💖 by Nuxt.js team!
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://github.com/unjs/hookable/workflows/ci/badge.svg
223
- [github-actions-ci-href]: https://github.com/unjs/hookable/actions?query=workflow%3Aci
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") {
@@ -65,7 +72,9 @@ class Hookable {
65
72
  }
66
73
  if (deprecatedHookObj) {
67
74
  if (!deprecatedHookObj.message) {
68
- console.warn(`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : ""));
75
+ console.warn(
76
+ `${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : "")
77
+ );
69
78
  } else {
70
79
  console.warn(deprecatedHookObj.message);
71
80
  }
@@ -103,9 +112,17 @@ class Hookable {
103
112
  }
104
113
  deprecateHook(name, deprecated) {
105
114
  this._deprecatedHooks[name] = deprecated;
115
+ const _hooks = this._hooks[name] || [];
116
+ this._hooks[name] = void 0;
117
+ for (const hook of _hooks) {
118
+ this.hook(name, hook);
119
+ }
106
120
  }
107
121
  deprecateHooks(deprecatedHooks) {
108
122
  Object.assign(this._deprecatedHooks, deprecatedHooks);
123
+ for (const name in deprecatedHooks) {
124
+ this.deprecateHook(name, deprecatedHooks[name]);
125
+ }
109
126
  }
110
127
  addHooks(configHooks) {
111
128
  const hooks = flatHooks(configHooks);
@@ -121,10 +138,13 @@ class Hookable {
121
138
  }
122
139
  }
123
140
  callHook(name, ...args) {
124
- if (!this._hooks[name]) {
125
- return;
126
- }
127
- return serial(this._hooks[name], (fn) => fn(...args));
141
+ return serialCaller(this._hooks[name] || [], args);
142
+ }
143
+ callHookParallel(name, ...args) {
144
+ return parallelCaller(this._hooks[name] || [], args);
145
+ }
146
+ callHookWith(caller, name, ...args) {
147
+ return caller(this._hooks[name] || [], args);
128
148
  }
129
149
  }
130
150
  function createHooks() {
@@ -135,4 +155,6 @@ exports.Hookable = Hookable;
135
155
  exports.createHooks = createHooks;
136
156
  exports.flatHooks = flatHooks;
137
157
  exports.mergeHooks = mergeHooks;
158
+ exports.parallelCaller = parallelCaller;
138
159
  exports.serial = serial;
160
+ exports.serialCaller = serialCaller;
@@ -48,11 +48,15 @@ declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends
48
48
  addHooks(configHooks: NestedHooks<HooksT>): () => void;
49
49
  removeHooks(configHooks: NestedHooks<HooksT>): void;
50
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>;
51
53
  }
52
54
  declare function createHooks<T>(): Hookable<T>;
53
55
 
54
56
  declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
55
57
  declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
56
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[]>;
57
61
 
58
- export { DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hookable, Hooks, NestedHooks, createHooks, flatHooks, mergeHooks, serial };
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") {
@@ -61,7 +68,9 @@ class Hookable {
61
68
  }
62
69
  if (deprecatedHookObj) {
63
70
  if (!deprecatedHookObj.message) {
64
- console.warn(`${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : ""));
71
+ console.warn(
72
+ `${originalName} hook has been deprecated` + (deprecatedHookObj.to ? `, please use ${deprecatedHookObj.to}` : "")
73
+ );
65
74
  } else {
66
75
  console.warn(deprecatedHookObj.message);
67
76
  }
@@ -99,9 +108,17 @@ class Hookable {
99
108
  }
100
109
  deprecateHook(name, deprecated) {
101
110
  this._deprecatedHooks[name] = deprecated;
111
+ const _hooks = this._hooks[name] || [];
112
+ this._hooks[name] = void 0;
113
+ for (const hook of _hooks) {
114
+ this.hook(name, hook);
115
+ }
102
116
  }
103
117
  deprecateHooks(deprecatedHooks) {
104
118
  Object.assign(this._deprecatedHooks, deprecatedHooks);
119
+ for (const name in deprecatedHooks) {
120
+ this.deprecateHook(name, deprecatedHooks[name]);
121
+ }
105
122
  }
106
123
  addHooks(configHooks) {
107
124
  const hooks = flatHooks(configHooks);
@@ -117,14 +134,17 @@ class Hookable {
117
134
  }
118
135
  }
119
136
  callHook(name, ...args) {
120
- if (!this._hooks[name]) {
121
- return;
122
- }
123
- return serial(this._hooks[name], (fn) => fn(...args));
137
+ return serialCaller(this._hooks[name] || [], args);
138
+ }
139
+ callHookParallel(name, ...args) {
140
+ return parallelCaller(this._hooks[name] || [], args);
141
+ }
142
+ callHookWith(caller, name, ...args) {
143
+ return caller(this._hooks[name] || [], args);
124
144
  }
125
145
  }
126
146
  function createHooks() {
127
147
  return new Hookable();
128
148
  }
129
149
 
130
- export { Hookable, createHooks, flatHooks, mergeHooks, serial };
150
+ 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.0.0",
4
- "description": "Awaitable hooks for Node.js",
3
+ "version": "5.1.2",
4
+ "description": "Awaitable hook system",
5
5
  "keywords": [
6
6
  "hook",
7
7
  "hookable",
@@ -17,30 +17,28 @@
17
17
  },
18
18
  "main": "./dist/index.cjs",
19
19
  "module": "./dist/index.mjs",
20
- "types": "./types/index.d.ts",
20
+ "types": "./dist/index.d.ts",
21
21
  "files": [
22
- "dist",
23
- "types"
22
+ "dist"
24
23
  ],
25
- "scripts": {
26
- "build": "siroc build",
27
- "lint": "eslint --ext .ts src",
28
- "prepublish": "yarn build",
29
- "release": "yarn test && yarn build && standard-version && git push --follow-tags && npm publish",
30
- "test": "yarn lint && yarn jest"
31
- },
32
24
  "devDependencies": {
33
25
  "@nuxtjs/eslint-config-typescript": "latest",
34
- "@types/jest": "latest",
35
- "babel-jest": "latest",
26
+ "c8": "latest",
36
27
  "codecov": "latest",
37
28
  "eslint": "latest",
38
- "expect-type": "^0.12.0",
39
- "jest": "latest",
40
- "rollup-plugin-typescript2": "latest",
41
- "siroc": "latest",
29
+ "expect-type": "^0.13.0",
30
+ "vitest": "latest",
42
31
  "standard-version": "latest",
43
- "ts-jest": "latest",
44
- "typescript": "latest"
32
+ "typescript": "latest",
33
+ "unbuild": "latest"
34
+ },
35
+ "packageManager": "pnpm@7.9.0",
36
+ "scripts": {
37
+ "build": "unbuild",
38
+ "lint": "eslint --ext .ts src",
39
+ "prepublish": "pnpm build",
40
+ "release": "pnpm test && pnpm build && standard-version && git push --follow-tags && pnpm publish",
41
+ "test": "pnpm lint && vitest run",
42
+ "test:types": "tsc --noEmit"
45
43
  }
46
- }
44
+ }
package/CHANGELOG.md DELETED
@@ -1,268 +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](https://github.com/unjs/hookable/compare/v5.0.0-2...v5.0.0) (2021-09-01)
6
-
7
-
8
- ### Bug Fixes
9
-
10
- * type nested/namespaced hooks ([#32](https://github.com/unjs/hookable/issues/32)) ([a0d9146](https://github.com/unjs/hookable/commit/a0d9146c40fb9767842564225444c6c5a7dce70f))
11
-
12
- ## [5.0.0-2](https://github.com/unjs/hookable/compare/v5.0.0-1...v5.0.0-2) (2021-08-27)
13
-
14
-
15
- ### Bug Fixes
16
-
17
- * allow type inference for `hook`, `hookOnce` and `removeHook` ([#29](https://github.com/unjs/hookable/issues/29)) ([22b74d3](https://github.com/unjs/hookable/commit/22b74d30805f35000709ba32220e6e4e059f4cc5))
18
-
19
- ## [5.0.0-1](https://github.com/unjs/hookable/compare/v5.0.0-0...v5.0.0-1) (2021-08-27)
20
-
21
-
22
- ### Bug Fixes
23
-
24
- * allow nested hooks type to omit some hooks ([#28](https://github.com/unjs/hookable/issues/28)) ([75f2a05](https://github.com/unjs/hookable/commit/75f2a057a526d018b9cf39f01ddfd2a3d2a6bbc1))
25
-
26
- ## [5.0.0-0](https://github.com/unjs/hookable/compare/v4.4.1...v5.0.0-0) (2021-08-26)
27
-
28
-
29
- ### ⚠ BREAKING CHANGES
30
-
31
- * You should directly handle errors with callHook
32
- * use named exports and expose createHooks
33
- * remove mergehooks from Hookable prototype
34
- * drop browser build and use exports field
35
- * improve type checking
36
-
37
- ### Features
38
-
39
- * drop browser build and use exports field ([b626770](https://github.com/unjs/hookable/commit/b626770192a62b23acc1be16b4e4eac2383e9136))
40
- * drop logger and global error handler ([ee6ea87](https://github.com/unjs/hookable/commit/ee6ea87ad0e15a52252389b9b3112060bd411330))
41
- * improve type checking ([c2e1e22](https://github.com/unjs/hookable/commit/c2e1e223d16e7bf87117cd8d72ad3ba211a333d8))
42
- * use named exports and expose createHooks ([fadfcbd](https://github.com/unjs/hookable/commit/fadfcbd07c3e2fa6905d0e31deabc37fc55d8317))
43
-
44
-
45
- * remove mergehooks from Hookable prototype ([d50af59](https://github.com/unjs/hookable/commit/d50af595d3cb05be8fb5060374f4e28b3d6259fa))
46
-
47
- ### [4.4.1](https://github.com/unjs/hookable/compare/v4.4.0...v4.4.1) (2021-02-26)
48
-
49
-
50
- ### Bug Fixes
51
-
52
- * avoid creating extra wrapper when merging hooks ([790c1c4](https://github.com/unjs/hookable/commit/790c1c4dbbd1f7b9cb1995b40baeecead5346ed0))
53
-
54
- ## [4.4.0](https://github.com/unjs/hookable/compare/v4.3.1...v4.4.0) (2021-01-21)
55
-
56
-
57
- ### Features
58
-
59
- * **pkg:** expose module format ([2987b09](https://github.com/unjs/hookable/commit/2987b0901e292eb4570f8141ca51cfd9d2d3f94f))
60
-
61
- ### [4.3.1](https://github.com/unjs/hookable/compare/v4.3.0...v4.3.1) (2020-11-06)
62
-
63
-
64
- ### Bug Fixes
65
-
66
- * expose types ([0ffbaff](https://github.com/unjs/hookable/commit/0ffbaffa91d38e333e0818cd73a084cf1e8657c8))
67
-
68
- ## [4.3.0](https://github.com/unjs/hookable/compare/v4.2.0...v4.3.0) (2020-11-06)
69
-
70
-
71
- ### Features
72
-
73
- * `mergeHooks` helper ([#26](https://github.com/unjs/hookable/issues/26)) ([8c52d03](https://github.com/unjs/hookable/commit/8c52d034aa1a40bafb13d0b847c72593c51fcba5))
74
-
75
- ## [4.2.0](https://github.com/unjs/hookable/compare/v4.1.2...v4.2.0) (2020-10-23)
76
-
77
-
78
- ### Features
79
-
80
- * hookOnce ([225fa8a](https://github.com/unjs/hookable/commit/225fa8af85e1a504916c357f57b047143b6bc5ab))
81
-
82
-
83
- ### Bug Fixes
84
-
85
- * typecheck for flatHooks ([7800190](https://github.com/unjs/hookable/commit/7800190feb82134be5dd089ca184a18a6644da19))
86
-
87
- ### [4.1.2](https://github.com/unjs/hookable/compare/v4.1.1...v4.1.2) (2020-08-24)
88
-
89
-
90
- ### Bug Fixes
91
-
92
- * **build:** exclude regenerator and update target to ie 11 ([48acfc5](https://github.com/unjs/hookable/commit/48acfc5c0a4b0fb8edc6e9790b37ad336c966215))
93
-
94
- ### [4.1.1](https://github.com/unjs/hookable/compare/v4.1.0...v4.1.1) (2020-04-28)
95
-
96
-
97
- ### Bug Fixes
98
-
99
- * **pkg:** typo in types entry name (fixes [#19](https://github.com/unjs/hookable/issues/19)) ([b9ba90f](https://github.com/unjs/hookable/commit/b9ba90fbc725097e41c430d7df4205985c2faaec))
100
-
101
- ## [4.1.0](https://github.com/unjs/hookable/compare/v4.0.0...v4.1.0) (2020-04-17)
102
-
103
-
104
- ### Features
105
-
106
- * **types:** implement strict types ([823cdca](https://github.com/unjs/hookable/commit/823cdcac728d189b802f75faa9a361ac5ea4883d))
107
-
108
- ## [4.0.0](https://github.com/unjs/hookable/compare/v3.0.0...v4.0.0) (2020-04-17)
109
-
110
-
111
- ### ⚠ BREAKING CHANGES
112
-
113
- * only dist and types getting published
114
-
115
- ### Features
116
-
117
- * allow disabling logger ([f8fb742](https://github.com/unjs/hookable/commit/f8fb74224f1277ec7f7d5a37bd312af7514fc962))
118
- * allow removing registered hooks ([#16](https://github.com/unjs/hookable/issues/16)) ([4134c31](https://github.com/unjs/hookable/commit/4134c31c44256cc82cac3a7a3610ece9252431dc))
119
- * migrate to typescript ([d63ea3e](https://github.com/unjs/hookable/commit/d63ea3e408ebea74ea3855af0c6e51880ebf9cac))
120
-
121
- ## [3.0.0](https://github.com/unjs/hookable/compare/v2.3.0...v3.0.0) (2020-02-25)
122
-
123
-
124
- ### Bug Fixes
125
-
126
- * revert back hooks ([07f52dc](https://github.com/unjs/hookable/commit/07f52dc))
127
-
128
-
129
- ### Features
130
-
131
- * advanced deprecation ([5b88628](https://github.com/unjs/hookable/commit/5b88628))
132
- * bundle package ([53a2a0e](https://github.com/unjs/hookable/commit/53a2a0e))
133
-
134
- # [2.3.0](https://github.com/unjs/hookable/compare/v2.2.1...v2.3.0) (2019-09-01)
135
-
136
-
137
- ### Features
138
-
139
- * hide deprecate warnings on production builds ([0861df3](https://github.com/unjs/hookable/commit/0861df3))
140
-
141
-
142
-
143
- ## [2.2.1](https://github.com/unjs/hookable/compare/v2.2.0...v2.2.1) (2019-08-21)
144
-
145
-
146
-
147
- # [2.2.0](https://github.com/unjs/hookable/compare/v2.1.0...v2.2.0) (2019-08-21)
148
-
149
-
150
- ### Features
151
-
152
- * deprecateHooks ([62f2d38](https://github.com/unjs/hookable/commit/62f2d38))
153
-
154
-
155
-
156
- # [2.1.0](https://github.com/unjs/hookable/compare/v2.0.1...v2.1.0) (2019-08-21)
157
-
158
-
159
- ### Features
160
-
161
- * optional fatal support for logger ([7c7355d](https://github.com/unjs/hookable/commit/7c7355d))
162
-
163
-
164
-
165
- ## [2.0.1](https://github.com/unjs/hookable/compare/v2.0.0...v2.0.1) (2019-08-21)
166
-
167
-
168
-
169
- # [2.0.0](https://github.com/unjs/hookable/compare/v1.0.1...v2.0.0) (2019-08-21)
170
-
171
-
172
- ### Features
173
-
174
- * custom logger ([ada6e37](https://github.com/unjs/hookable/commit/ada6e37))
175
-
176
-
177
- ### BREAKING CHANGES
178
-
179
- * console is replaced by consola by default
180
-
181
-
182
-
183
- ## [1.0.1](https://github.com/unjs/hookable/compare/v1.0.0...v1.0.1) (2019-03-16)
184
-
185
-
186
- ### Bug Fixes
187
-
188
- * fix package.json (2) ([7ff4ce9](https://github.com/unjs/hookable/commit/7ff4ce9))
189
-
190
-
191
-
192
- <a name="1.0.0"></a>
193
- # [1.0.0](https://github.com/unjs/hookable/compare/v0.0.7...v1.0.0) (2019-02-11)
194
-
195
-
196
- ### Features
197
-
198
- * rewrite for 1.0.0 ([88decae](https://github.com/unjs/hookable/commit/88decae))
199
-
200
-
201
- ### BREAKING CHANGES
202
-
203
- * api change
204
-
205
-
206
-
207
- <a name="0.0.7"></a>
208
- ## [0.0.7](https://github.com/pi0/hookable/compare/v0.0.6...v0.0.7) (2018-01-28)
209
-
210
-
211
- ### Bug Fixes
212
-
213
- * hook with array or falsy key ([7e90de1](https://github.com/pi0/hookable/commit/7e90de1))
214
-
215
-
216
- ### Performance Improvements
217
-
218
- * use for in for hookObj ([3c8e2e7](https://github.com/pi0/hookable/commit/3c8e2e7))
219
-
220
-
221
-
222
- <a name="0.0.6"></a>
223
- ## [0.0.6](https://github.com/pi0/hookable/compare/v0.0.5...v0.0.6) (2018-01-26)
224
-
225
-
226
- ### Performance Improvements
227
-
228
- * reduce transpiled dist size ([df607cf](https://github.com/pi0/hookable/commit/df607cf))
229
-
230
-
231
-
232
- <a name="0.0.5"></a>
233
- ## [0.0.5](https://github.com/pi0/hookable/compare/v0.0.4...v0.0.5) (2018-01-26)
234
-
235
-
236
- ### Bug Fixes
237
-
238
- * **package:** lib ~> dist ([34a8d5c](https://github.com/pi0/hookable/commit/34a8d5c))
239
-
240
-
241
-
242
- <a name="0.0.4"></a>
243
- ## [0.0.4](https://github.com/pi0/hookable/compare/v0.0.3...v0.0.4) (2018-01-26)
244
-
245
-
246
- ### Performance Improvements
247
-
248
- * handle fn as array faster ([ec35edc](https://github.com/pi0/hookable/commit/ec35edc))
249
-
250
-
251
-
252
- <a name="0.0.3"></a>
253
- ## [0.0.3](https://github.com/pi0/hookable/compare/v0.0.2...v0.0.3) (2018-01-26)
254
-
255
-
256
- ### Bug Fixes
257
-
258
- * bind hookObj to this context ([6f6f7bc](https://github.com/pi0/hookable/commit/6f6f7bc))
259
-
260
-
261
- ### Performance Improvements
262
-
263
- * minor refactor ([e4083aa](https://github.com/pi0/hookable/commit/e4083aa))
264
-
265
-
266
-
267
- <a name="0.0.2"></a>
268
- ## 0.0.2 (2018-01-26)
@@ -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 };