hookable 6.0.0 → 6.1.0

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
@@ -163,10 +163,11 @@ Used by class itself to **sequentially** call handlers of a specific hook.
163
163
 
164
164
  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.
165
165
 
166
- `callerFn` if a callback function that accepts two arguments, `hooks` and `args`:
166
+ `callerFn` if a callback function that accepts 3 arguments, `hooks`, `args` and `name`:
167
167
 
168
168
  - `hooks`: Array of user hooks to be called
169
169
  - `args`: Array of arguments that should be passed each time calling a hook
170
+ - `name`: Name of the hook
170
171
 
171
172
  ### `deprecateHook (old, name)`
172
173
 
package/dist/index.d.mts CHANGED
@@ -39,6 +39,7 @@ declare class Hookable<HooksT extends Record<string, any> = Record<string, HookC
39
39
  }): () => void;
40
40
  hookOnce<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): () => void;
41
41
  removeHook<NameT extends HookNameT>(name: NameT, function_: InferCallback<HooksT, NameT>): void;
42
+ clearHook<NameT extends HookNameT>(name: NameT): void;
42
43
  deprecateHook<NameT extends HookNameT>(name: NameT, deprecated: HookKeys<HooksT> | DeprecatedHook<HooksT>): void;
43
44
  deprecateHooks(deprecatedHooks: Partial<Record<HookNameT, DeprecatedHook<HooksT>>>): void;
44
45
  addHooks(configHooks: NestedHooks<HooksT>): () => void;
@@ -46,7 +47,7 @@ declare class Hookable<HooksT extends Record<string, any> = Record<string, HookC
46
47
  removeAllHooks(): void;
47
48
  callHook<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any> | void;
48
49
  callHookParallel<NameT extends HookNameT>(name: NameT, ...args: Parameters<InferCallback<HooksT, NameT>>): Promise<any[]> | void;
49
- callHookWith<NameT extends HookNameT, CallFunction extends (hooks: HookCallback[], args: Parameters<InferCallback<HooksT, NameT>>) => any>(caller: CallFunction, name: NameT, args: Parameters<InferCallback<HooksT, NameT>>): ReturnType<CallFunction>;
50
+ callHookWith<NameT extends HookNameT, CallFunction extends (hooks: HookCallback[], args: Parameters<InferCallback<HooksT, NameT>>, name: NameT) => any>(caller: CallFunction, name: NameT, args: Parameters<InferCallback<HooksT, NameT>>): ReturnType<CallFunction>;
50
51
  beforeEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
51
52
  afterEach(function_: (event: InferSpyEvent<HooksT>) => void): () => void;
52
53
  }
@@ -99,8 +100,7 @@ interface CreateDebuggerOptions {
99
100
  }
100
101
  /** Start debugging hook names and timing in console */
101
102
  declare function createDebugger(hooks: Hookable<any>, _options?: CreateDebuggerOptions): {
102
- /** Stop debugging and remove listeners */
103
- close: () => void;
103
+ /** Stop debugging and remove listeners */close: () => void;
104
104
  };
105
105
  //#endregion
106
106
  export { CreateDebuggerOptions, DeprecatedHook, DeprecatedHooks, HookCallback, HookKeys, Hookable, HookableCore, Hooks, NestedHooks, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
package/dist/index.mjs CHANGED
@@ -37,12 +37,12 @@ function callHooks(hooks, args, startIndex, task) {
37
37
  return Promise.reject(error);
38
38
  }
39
39
  }
40
- function serialTaskCaller(hooks, args) {
41
- if (hooks.length > 0) return callHooks(hooks, args, 0, createTask(args.shift()));
40
+ function serialTaskCaller(hooks, args, name) {
41
+ if (hooks.length > 0) return callHooks(hooks, args, 0, createTask(name));
42
42
  }
43
- function parallelTaskCaller(hooks, args) {
43
+ function parallelTaskCaller(hooks, args, name) {
44
44
  if (hooks.length > 0) {
45
- const task = createTask(args.shift());
45
+ const task = createTask(name);
46
46
  return Promise.all(hooks.map((hook) => task.run(() => hook(...args))));
47
47
  }
48
48
  }
@@ -57,7 +57,6 @@ function parallelCaller(hooks, args) {
57
57
  function callEachWith(callbacks, arg0) {
58
58
  for (const callback of [...callbacks]) callback(arg0);
59
59
  }
60
-
61
60
  //#endregion
62
61
  //#region src/hookable.ts
63
62
  var Hookable = class {
@@ -127,6 +126,9 @@ var Hookable = class {
127
126
  if (hooks.length === 0) this._hooks[name] = void 0;
128
127
  }
129
128
  }
129
+ clearHook(name) {
130
+ this._hooks[name] = void 0;
131
+ }
130
132
  deprecateHook(name, deprecated) {
131
133
  this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
132
134
  const _hooks = this._hooks[name] || [];
@@ -164,8 +166,7 @@ var Hookable = class {
164
166
  context: {}
165
167
  } : void 0;
166
168
  if (this._before) callEachWith(this._before, event);
167
- const _args = args?.length ? [name, ...args] : [name];
168
- const result = caller(this._hooks[name] ? [...this._hooks[name]] : [], _args);
169
+ const result = caller(this._hooks[name] ? [...this._hooks[name]] : [], args, name);
169
170
  if (result instanceof Promise) return result.finally(() => {
170
171
  if (this._after && event) callEachWith(this._after, event);
171
172
  });
@@ -226,7 +227,6 @@ var HookableCore = class {
226
227
  return callHooks(hooks, args, 0);
227
228
  }
228
229
  };
229
-
230
230
  //#endregion
231
231
  //#region src/debugger.ts
232
232
  const isBrowser = typeof window !== "undefined";
@@ -262,6 +262,5 @@ function createDebugger(hooks, _options = {}) {
262
262
  unsubscribeAfter();
263
263
  } };
264
264
  }
265
-
266
265
  //#endregion
267
- export { Hookable, HookableCore, createDebugger, createHooks, flatHooks, mergeHooks, parallelCaller, serial, serialCaller };
266
+ 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.0.0",
3
+ "version": "6.1.0",
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
- "sideEffects": false,
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": "eslint --cache . && prettier -c src test",
29
- "lint:fix": "eslint --cache . --fix && prettier -c src test -w",
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": "tsc --noEmit"
33
+ "test:types": "tsgo --noEmit"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "^25.0.3",
37
- "@vitest/coverage-v8": "^4.0.16",
36
+ "@types/node": "^25.5.0",
37
+ "@typescript/native-preview": "7.0.0-dev.20260314.1",
38
+ "@vitest/coverage-v8": "^4.1.0",
38
39
  "changelogen": "^0.6.2",
39
- "esbuild": "^0.27.2",
40
- "eslint": "^9.39.2",
41
- "eslint-config-unjs": "^0.5.0",
40
+ "esbuild": "^0.27.4",
41
+ "eslint-config-unjs": "^0.6.2",
42
42
  "expect-type": "^1.3.0",
43
- "hookable-prev": "npm:hookable@^5.5.3",
43
+ "hookable-prev": "npm:hookable@^6.0.1",
44
44
  "mitata": "^1.0.34",
45
- "obuild": "^0.4.9",
46
- "prettier": "^3.7.4",
45
+ "obuild": "^0.4.32",
46
+ "oxfmt": "^0.40.0",
47
+ "oxlint": "^1.55.0",
47
48
  "typescript": "^5.9.3",
48
- "vite": "^7.3.0",
49
- "vitest": "^4.0.16"
49
+ "vite": "^8.0.0",
50
+ "vitest": "^4.1.0"
50
51
  },
51
- "packageManager": "pnpm@10.26.0"
52
+ "packageManager": "pnpm@10.32.1"
52
53
  }