hookable 5.5.1 → 5.5.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
@@ -194,12 +194,16 @@ hookable.removeHooks({
194
194
  })
195
195
  ```
196
196
 
197
+ ### `removeAllHooks`
198
+
199
+ Remove all hook handlers.
200
+
197
201
  ### `beforeEach (syncCallback)`
198
202
 
199
203
  Registers a (sync) callback to be called before each hook is being called.
200
204
 
201
205
  ```js
202
- hookable.beforeEach((event) => { console.log(`${event.name} hook is being called with ${event.args}`)})
206
+ hookable.beforeEach((event) => { console.log(`${event.name} hook is being called with ${event.args}`)}`)
203
207
  hookable.hook('test', () => { console.log('running test hook') })
204
208
 
205
209
  // test hook is being called with []
@@ -212,7 +216,7 @@ await hookable.callHook('test')
212
216
  Registers a (sync) callback to be called after each hook is being called.
213
217
 
214
218
  ```js
215
- hookable.afterEach((event) => { console.log(`${event.name} hook called with ${event.args}`)})
219
+ hookable.afterEach((event) => { console.log(`${event.name} hook called with ${event.args}`)}`)
216
220
  hookable.hook('test', () => { console.log('running test hook') })
217
221
 
218
222
  // running test hook
package/dist/index.cjs CHANGED
@@ -58,12 +58,12 @@ function parallelTaskCaller(hooks, args) {
58
58
  }
59
59
  function serialCaller(hooks, arguments_) {
60
60
  return hooks.reduce(
61
- (promise, hookFunction) => promise.then(() => hookFunction(...arguments_)),
61
+ (promise, hookFunction) => promise.then(() => hookFunction(...arguments_ || [])),
62
62
  Promise.resolve()
63
63
  );
64
64
  }
65
65
  function parallelCaller(hooks, args) {
66
- return Promise.all(hooks.map((hook) => hook(...args)));
66
+ return Promise.all(hooks.map((hook) => hook(...args || [])));
67
67
  }
68
68
  function callEachWith(callbacks, arg0) {
69
69
  for (const callback of callbacks) {
@@ -151,7 +151,7 @@ class Hookable {
151
151
  deprecateHook(name, deprecated) {
152
152
  this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
153
153
  const _hooks = this._hooks[name] || [];
154
- this._hooks[name] = void 0;
154
+ delete this._hooks[name];
155
155
  for (const hook of _hooks) {
156
156
  this.hook(name, hook);
157
157
  }
@@ -214,9 +214,11 @@ class Hookable {
214
214
  this._before = this._before || [];
215
215
  this._before.push(function_);
216
216
  return () => {
217
- const index = this._before.indexOf(function_);
218
- if (index !== -1) {
219
- this._before.splice(index, 1);
217
+ if (this._before !== void 0) {
218
+ const index = this._before.indexOf(function_);
219
+ if (index !== -1) {
220
+ this._before.splice(index, 1);
221
+ }
220
222
  }
221
223
  };
222
224
  }
@@ -224,9 +226,11 @@ class Hookable {
224
226
  this._after = this._after || [];
225
227
  this._after.push(function_);
226
228
  return () => {
227
- const index = this._after.indexOf(function_);
228
- if (index !== -1) {
229
- this._after.splice(index, 1);
229
+ if (this._after !== void 0) {
230
+ const index = this._after.indexOf(function_);
231
+ if (index !== -1) {
232
+ this._after.splice(index, 1);
233
+ }
230
234
  }
231
235
  };
232
236
  }
@@ -249,7 +253,7 @@ function createDebugger(hooks, _options = {}) {
249
253
  const logPrefix = (event) => _tag + event.name + "".padEnd(event._id, "\0");
250
254
  const _idCtr = {};
251
255
  const unsubscribeBefore = hooks.beforeEach((event) => {
252
- if (!filter(event.name)) {
256
+ if (filter !== void 0 && !filter(event.name)) {
253
257
  return;
254
258
  }
255
259
  _idCtr[event.name] = _idCtr[event.name] || 0;
@@ -257,7 +261,7 @@ function createDebugger(hooks, _options = {}) {
257
261
  console.time(logPrefix(event));
258
262
  });
259
263
  const unsubscribeAfter = hooks.afterEach((event) => {
260
- if (!filter(event.name)) {
264
+ if (filter !== void 0 && !filter(event.name)) {
261
265
  return;
262
266
  }
263
267
  if (options.group) {
package/dist/index.d.ts CHANGED
@@ -43,12 +43,12 @@ type InferSpyEvent<HT extends Record<string, any>> = {
43
43
  context: Record<string, any>;
44
44
  };
45
45
  }[keyof HT];
46
- declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
46
+ declare class Hookable<HooksT extends Record<string, any> = Record<string, HookCallback>, HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>> {
47
47
  private _hooks;
48
- private _before;
49
- private _after;
48
+ private _before?;
49
+ private _after?;
50
50
  private _deprecatedHooks;
51
- private _deprecatedMessages;
51
+ private _deprecatedMessages?;
52
52
  constructor();
53
53
  hook<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>, options?: {
54
54
  allowDeprecated?: boolean;
@@ -66,7 +66,7 @@ declare class Hookable<HooksT = Record<string, HookCallback>, HookNameT extends
66
66
  beforeEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
67
67
  afterEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
68
68
  }
69
- declare function createHooks<T>(): Hookable<T>;
69
+ declare function createHooks<T extends Record<string, any>>(): Hookable<T>;
70
70
 
71
71
  declare function flatHooks<T>(configHooks: NestedHooks<T>, hooks?: T, parentName?: string): T;
72
72
  declare function mergeHooks<T>(...hooks: NestedHooks<T>[]): T;
package/dist/index.mjs CHANGED
@@ -56,12 +56,12 @@ function parallelTaskCaller(hooks, args) {
56
56
  }
57
57
  function serialCaller(hooks, arguments_) {
58
58
  return hooks.reduce(
59
- (promise, hookFunction) => promise.then(() => hookFunction(...arguments_)),
59
+ (promise, hookFunction) => promise.then(() => hookFunction(...arguments_ || [])),
60
60
  Promise.resolve()
61
61
  );
62
62
  }
63
63
  function parallelCaller(hooks, args) {
64
- return Promise.all(hooks.map((hook) => hook(...args)));
64
+ return Promise.all(hooks.map((hook) => hook(...args || [])));
65
65
  }
66
66
  function callEachWith(callbacks, arg0) {
67
67
  for (const callback of callbacks) {
@@ -149,7 +149,7 @@ class Hookable {
149
149
  deprecateHook(name, deprecated) {
150
150
  this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
151
151
  const _hooks = this._hooks[name] || [];
152
- this._hooks[name] = void 0;
152
+ delete this._hooks[name];
153
153
  for (const hook of _hooks) {
154
154
  this.hook(name, hook);
155
155
  }
@@ -212,9 +212,11 @@ class Hookable {
212
212
  this._before = this._before || [];
213
213
  this._before.push(function_);
214
214
  return () => {
215
- const index = this._before.indexOf(function_);
216
- if (index !== -1) {
217
- this._before.splice(index, 1);
215
+ if (this._before !== void 0) {
216
+ const index = this._before.indexOf(function_);
217
+ if (index !== -1) {
218
+ this._before.splice(index, 1);
219
+ }
218
220
  }
219
221
  };
220
222
  }
@@ -222,9 +224,11 @@ class Hookable {
222
224
  this._after = this._after || [];
223
225
  this._after.push(function_);
224
226
  return () => {
225
- const index = this._after.indexOf(function_);
226
- if (index !== -1) {
227
- this._after.splice(index, 1);
227
+ if (this._after !== void 0) {
228
+ const index = this._after.indexOf(function_);
229
+ if (index !== -1) {
230
+ this._after.splice(index, 1);
231
+ }
228
232
  }
229
233
  };
230
234
  }
@@ -247,7 +251,7 @@ function createDebugger(hooks, _options = {}) {
247
251
  const logPrefix = (event) => _tag + event.name + "".padEnd(event._id, "\0");
248
252
  const _idCtr = {};
249
253
  const unsubscribeBefore = hooks.beforeEach((event) => {
250
- if (!filter(event.name)) {
254
+ if (filter !== void 0 && !filter(event.name)) {
251
255
  return;
252
256
  }
253
257
  _idCtr[event.name] = _idCtr[event.name] || 0;
@@ -255,7 +259,7 @@ function createDebugger(hooks, _options = {}) {
255
259
  console.time(logPrefix(event));
256
260
  });
257
261
  const unsubscribeAfter = hooks.afterEach((event) => {
258
- if (!filter(event.name)) {
262
+ if (filter !== void 0 && !filter(event.name)) {
259
263
  return;
260
264
  }
261
265
  if (options.group) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookable",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "Awaitable hook system",
5
5
  "keywords": [
6
6
  "hook",
@@ -23,18 +23,19 @@
23
23
  "dist"
24
24
  ],
25
25
  "devDependencies": {
26
- "@types/node": "^18.15.0",
26
+ "@types/node": "^18.15.3",
27
27
  "@vitest/coverage-c8": "^0.29.2",
28
28
  "changelogen": "^0.5.1",
29
- "eslint": "^8.35.0",
29
+ "eslint": "^8.36.0",
30
30
  "eslint-config-unjs": "^0.1.0",
31
31
  "expect-type": "^0.15.0",
32
32
  "prettier": "^2.8.4",
33
33
  "typescript": "^4.9.5",
34
34
  "unbuild": "^1.1.2",
35
+ "vite": "^4.2.1",
35
36
  "vitest": "^0.29.2"
36
37
  },
37
- "packageManager": "pnpm@7.29.1",
38
+ "packageManager": "pnpm@7.29.2",
38
39
  "scripts": {
39
40
  "build": "unbuild",
40
41
  "dev": "vitest",