@kubb/core 5.9.2 → 5.9.4

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.
@@ -2,12 +2,11 @@ import "./rolldown-runtime-CRm0XQPb.js";
2
2
  import { satisfies } from "verkit";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { styleText } from "node:util";
5
- import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
6
6
  import path, { dirname, isAbsolute, relative, resolve } from "node:path";
7
- import { ast, collectImportedRefNames, collectUsedSchemaNames, composeMacros, extractStringsFromNodes, transform } from "@kubb/ast";
8
- import { EventEmitter } from "node:events";
7
+ import { ast, collectImportedRefNames, collectUsedSchemaNames, extractStringsFromNodes } from "@kubb/ast";
9
8
  //#region package.json
10
- var version = "5.9.2";
9
+ var version = "5.9.4";
11
10
  //#endregion
12
11
  //#region ../../internals/utils/src/casing.ts
13
12
  /**
@@ -96,21 +95,6 @@ function detect() {
96
95
  //#endregion
97
96
  //#region ../../internals/utils/src/fs.ts
98
97
  /**
99
- * Resolves to `true` when the file or directory at `path` exists.
100
- * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
101
- *
102
- * @example
103
- * ```ts
104
- * if (await exists('./kubb.config.ts')) {
105
- * const content = await read('./kubb.config.ts')
106
- * }
107
- * ```
108
- */
109
- async function exists(path) {
110
- if (runtime.isBun) return Bun.file(path).exists();
111
- return access(path).then(() => true, () => false);
112
- }
113
- /**
114
98
  * Reads the file at `path` as a UTF-8 string.
115
99
  * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
116
100
  *
@@ -189,20 +173,6 @@ async function write(path, data, options = {}) {
189
173
  return content;
190
174
  }
191
175
  /**
192
- * Recursively removes `path`. Silently succeeds when `path` does not exist.
193
- *
194
- * @example
195
- * ```ts
196
- * await clean('./dist')
197
- * ```
198
- */
199
- async function clean(path) {
200
- return rm(path, {
201
- recursive: true,
202
- force: true
203
- });
204
- }
205
- /**
206
176
  * Converts a filesystem path to use POSIX (`/`) separators.
207
177
  *
208
178
  * Most of the codebase compares and composes paths as strings (prefix matching, joining for
@@ -999,12 +969,17 @@ function checkDependencies({ name, dependencies, plugins }) {
999
969
  });
1000
970
  }
1001
971
  }
972
+ /**
973
+ * Builds the factory behind `defineExtension`. It passes `{}` when called without options, and carries `kind` and
974
+ * `meta` so tools can read them without calling it.
975
+ *
976
+ * @internal
977
+ */
1002
978
  function createExtensionFactory({ kind, meta, build }) {
1003
- const factory = (options) => build(options ?? {});
1004
- return Object.assign(factory, meta ? {
979
+ return Object.assign((options = {}) => build(options), {
1005
980
  kind,
1006
981
  meta
1007
- } : { kind });
982
+ });
1008
983
  }
1009
984
  function defineExtension(definition) {
1010
985
  switch (definition.kind) {
@@ -1185,20 +1160,15 @@ function assertPluginOption({ plugin, option, value, allowed }) {
1185
1160
  plugin
1186
1161
  });
1187
1162
  }
1188
- function definePlugin(input) {
1189
- if (typeof input === "function") return createExtensionFactory({
1190
- kind: "plugin",
1191
- build: (options) => {
1192
- const plugin = input(options);
1193
- return {
1194
- ...plugin,
1195
- meta: resolveMeta(plugin)
1196
- };
1197
- }
1198
- });
1163
+ /**
1164
+ * Defines a plugin from one object and returns a factory that takes the user's options.
1165
+ *
1166
+ * @deprecated Use `defineExtension` with `kind: 'plugin'` instead.
1167
+ */
1168
+ function definePlugin(definition) {
1199
1169
  return defineExtension({
1200
1170
  kind: "plugin",
1201
- ...input
1171
+ ...definition
1202
1172
  });
1203
1173
  }
1204
1174
  //#endregion
@@ -1693,125 +1663,6 @@ function createResolver(options) {
1693
1663
  return new Resolver(options);
1694
1664
  }
1695
1665
  //#endregion
1696
- //#region src/Hookable.ts
1697
- /**
1698
- * Typed hook emitter that awaits all async listeners before resolving.
1699
- * Wraps Node's `EventEmitter` with full TypeScript hook-map inference.
1700
- *
1701
- * @example
1702
- * ```ts
1703
- * const hooks = new Hookable<{ build: [name: string] }>()
1704
- * hooks.hook('build', async (name) => { console.log(name) })
1705
- * await hooks.callHook('build', 'petstore') // all listeners awaited
1706
- * ```
1707
- */
1708
- var Hookable = class {
1709
- /**
1710
- * Maximum number of listeners per hook before Node emits a memory-leak warning.
1711
- * @default 10
1712
- */
1713
- constructor(maxListener = 10) {
1714
- this.#emitter.setMaxListeners(maxListener);
1715
- }
1716
- #emitter = new EventEmitter();
1717
- /**
1718
- * Calls `hookName` and awaits all registered listeners sequentially.
1719
- * Throws if any listener rejects, wrapping the cause in an error that names the hook.
1720
- *
1721
- * @example
1722
- * ```ts
1723
- * await hooks.callHook('build', 'petstore')
1724
- * ```
1725
- */
1726
- callHook(hookName, ...hookArgs) {
1727
- const listeners = this.#emitter.listeners(hookName);
1728
- if (listeners.length === 0) return;
1729
- return this.#emitAll(hookName, listeners, hookArgs);
1730
- }
1731
- async #emitAll(hookName, listeners, hookArgs) {
1732
- for (const listener of listeners) try {
1733
- await listener(...hookArgs);
1734
- } catch (err) {
1735
- throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
1736
- }
1737
- }
1738
- /**
1739
- * Registers a persistent listener for `hookName` and returns a function that removes it.
1740
- *
1741
- * @example
1742
- * ```ts
1743
- * const unhook = hooks.hook('build', async (name) => { console.log(name) })
1744
- * unhook() // removes it
1745
- * ```
1746
- */
1747
- hook(hookName, handler) {
1748
- this.#emitter.on(hookName, handler);
1749
- return () => this.removeHook(hookName, handler);
1750
- }
1751
- /**
1752
- * Registers every handler in `configHooks` at once and returns a function that removes them
1753
- * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
1754
- *
1755
- * @example
1756
- * ```ts
1757
- * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
1758
- * unhook() // removes both
1759
- * ```
1760
- */
1761
- addHooks(configHooks) {
1762
- const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
1763
- return () => {
1764
- for (const unhook of unhooks) unhook();
1765
- };
1766
- }
1767
- /**
1768
- * Removes a previously registered listener.
1769
- *
1770
- * @example
1771
- * ```ts
1772
- * hooks.removeHook('build', handler)
1773
- * ```
1774
- */
1775
- removeHook(hookName, handler) {
1776
- this.#emitter.off(hookName, handler);
1777
- }
1778
- /**
1779
- * Returns the number of listeners registered for `hookName`.
1780
- *
1781
- * @example
1782
- * ```ts
1783
- * hooks.hook('build', handler)
1784
- * hooks.listenerCount('build') // 1
1785
- * ```
1786
- */
1787
- listenerCount(hookName) {
1788
- return this.#emitter.listenerCount(hookName);
1789
- }
1790
- /**
1791
- * Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.
1792
- * Set this above the expected listener count when many listeners attach by design.
1793
- *
1794
- * @example
1795
- * ```ts
1796
- * hooks.setMaxListeners(40)
1797
- * ```
1798
- */
1799
- setMaxListeners(max) {
1800
- this.#emitter.setMaxListeners(max);
1801
- }
1802
- /**
1803
- * Removes all listeners from every hook channel.
1804
- *
1805
- * @example
1806
- * ```ts
1807
- * hooks.removeAllHooks()
1808
- * ```
1809
- */
1810
- removeAllHooks() {
1811
- this.#emitter.removeAllListeners();
1812
- }
1813
- };
1814
- //#endregion
1815
1666
  //#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
1816
1667
  function _usingCtx() {
1817
1668
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
@@ -1891,7 +1742,7 @@ function runParser(parser, print) {
1891
1742
  async function parseCopy(file, parser) {
1892
1743
  let content;
1893
1744
  try {
1894
- content = await read(file.copy);
1745
+ content = await readFile(file.copy, "utf8");
1895
1746
  } catch (err) {
1896
1747
  throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err });
1897
1748
  }
@@ -1946,7 +1797,6 @@ function isUnchanged({ stored, source, key, manifest }) {
1946
1797
  * ```
1947
1798
  */
1948
1799
  var FileManager = class {
1949
- hooks = new Hookable();
1950
1800
  #cache = /* @__PURE__ */ new Map();
1951
1801
  #sorted = null;
1952
1802
  add(...files) {
@@ -1995,13 +1845,11 @@ var FileManager = class {
1995
1845
  return [...seen.values()];
1996
1846
  }
1997
1847
  /**
1998
- * Releases all stored files and clears every `hooks` listener. Called by the core after
1999
- * `kubb:build:end`.
1848
+ * Releases all stored files. Called by the core after `kubb:build:end`.
2000
1849
  */
2001
1850
  dispose() {
2002
1851
  this.#cache.clear();
2003
1852
  this.#sorted = null;
2004
- this.hooks.removeAllHooks();
2005
1853
  }
2006
1854
  /**
2007
1855
  * All stored files in stable sort order (shortest path first, barrel files
@@ -2023,28 +1871,29 @@ var FileManager = class {
2023
1871
  * Parses and writes every file through a bounded pool of workers. A small spec runs all its files
2024
1872
  * at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in
2025
1873
  * memory rather than holding every source, while still overlapping each file's write with the
2026
- * next file's parse. Each `update` carries the file's input position, so a consumer can present
2027
- * the files in generation order even though they finish in whatever order they parse.
1874
+ * next file's parse. Files finish in whatever order they parse, so the update rows are sorted back
1875
+ * into input order before `kubb:files:processing:update` fires once with the whole batch.
2028
1876
  *
2029
1877
  * A file the storage already holds is skipped, so a rebuild that generates identical output
2030
1878
  * writes nothing and leaves every mtime where it was.
2031
1879
  */
2032
- async write(files, { storage, parsers, manifest, signal }) {
1880
+ async write(files, { storage, parsers, manifest, signal, hooks, config }) {
2033
1881
  if (files.length === 0) return;
2034
- await this.hooks.callHook("start", files);
1882
+ await hooks?.callHook("kubb:files:processing:start", { files });
2035
1883
  const total = files.length;
1884
+ const updates = [];
2036
1885
  await inParallel({
2037
1886
  items: files,
2038
1887
  limit: 50,
2039
1888
  run: async (file, index) => {
2040
1889
  signal?.throwIfAborted();
2041
1890
  const source = await this.parse(file, { parsers });
2042
- await this.hooks.callHook("update", {
1891
+ if (config) updates.push({
2043
1892
  file,
2044
- source,
2045
1893
  processed: index + 1,
2046
1894
  total,
2047
- percentage: (index + 1) / total * 100
1895
+ percentage: (index + 1) / total * 100,
1896
+ config
2048
1897
  });
2049
1898
  if (!source) return;
2050
1899
  signal?.throwIfAborted();
@@ -2063,83 +1912,9 @@ var FileManager = class {
2063
1912
  });
2064
1913
  }
2065
1914
  });
2066
- await this.hooks.callHook("end", files);
2067
- }
2068
- };
2069
- //#endregion
2070
- //#region src/Transform.ts
2071
- /**
2072
- * Holds an ordered list of macros per plugin, keyed by plugin name. Each plugin's macros run in
2073
- * isolation on the original adapter node and are composed into a single `Visitor` that the
2074
- * `@kubb/ast` `transform` primitive applies. `applyTo` is a per-plugin lookup, not a cross-plugin
2075
- * chain, so plugin A's macros never see plugin B's output. When a plugin has no macros, `applyTo`
2076
- * returns the original node reference, and `transform` does the same when the composed visitor
2077
- * leaves the tree untouched, so callers can detect a no-op by identity.
2078
- *
2079
- * Registration order matches the order setup hooks fire, which the driver has already sorted by
2080
- * `enforce` and dependency edges. The registry preserves that order. Macro `enforce` only reorders
2081
- * within a single plugin's list.
2082
- */
2083
- var Transform = class {
2084
- #macros = /* @__PURE__ */ new Map();
2085
- #composed = /* @__PURE__ */ new Map();
2086
- #memo = /* @__PURE__ */ new Map();
2087
- /**
2088
- * Appends `macro` to the plugin's list, after any macros already registered.
2089
- */
2090
- add(pluginName, macro) {
2091
- const list = this.#macros.get(pluginName);
2092
- if (list) list.push(macro);
2093
- else this.#macros.set(pluginName, [macro]);
2094
- this.#invalidate(pluginName);
2095
- }
2096
- /**
2097
- * Replaces the plugin's macro list with `macros`.
2098
- */
2099
- set(pluginName, macros) {
2100
- this.#macros.set(pluginName, [...macros]);
2101
- this.#invalidate(pluginName);
2102
- }
2103
- /**
2104
- * Runs the plugin's macros on `node`. Returns the original node reference when the plugin has no
2105
- * macros, so callers can compare by identity to detect a no-op.
2106
- */
2107
- applyTo(pluginName, node) {
2108
- const visitor = this.#visitorFor(pluginName);
2109
- if (!visitor) return node;
2110
- let memo = this.#memo.get(pluginName);
2111
- if (!memo) {
2112
- memo = /* @__PURE__ */ new WeakMap();
2113
- this.#memo.set(pluginName, memo);
2114
- }
2115
- const cached = memo.get(node);
2116
- if (cached) return cached;
2117
- const result = transform(node, visitor);
2118
- memo.set(node, result);
2119
- return result;
2120
- }
2121
- /**
2122
- * Clears every registration. Called from the driver's `dispose()` so macros do not leak across
2123
- * builds.
2124
- */
2125
- dispose() {
2126
- this.#macros.clear();
2127
- this.#composed.clear();
2128
- this.#memo.clear();
2129
- }
2130
- #invalidate(pluginName) {
2131
- this.#composed.delete(pluginName);
2132
- this.#memo.delete(pluginName);
2133
- }
2134
- #visitorFor(pluginName) {
2135
- const macros = this.#macros.get(pluginName);
2136
- if (!macros || macros.length === 0) return void 0;
2137
- let composed = this.#composed.get(pluginName);
2138
- if (!composed) {
2139
- composed = composeMacros(macros);
2140
- this.#composed.set(pluginName, composed);
2141
- }
2142
- return composed;
1915
+ updates.sort((a, b) => a.processed - b.processed);
1916
+ await hooks?.callHook("kubb:files:processing:update", { files: updates });
1917
+ await hooks?.callHook("kubb:files:processing:end", { files });
2143
1918
  }
2144
1919
  };
2145
1920
  //#endregion
@@ -2236,11 +2011,6 @@ var KubbDriver = class {
2236
2011
  * them in one pass. External `hooks.hook(...)` listeners are not tracked.
2237
2012
  */
2238
2013
  #unhooks = [];
2239
- /**
2240
- * Transform registry. Plugins populate it during `kubb:plugin:setup` via `addMacro`/`setMacros`,
2241
- * and `#runGenerators` reads it once per `(plugin, node)` pair through `applyTo`.
2242
- */
2243
- #transforms = new Transform();
2244
2014
  constructor(config, options) {
2245
2015
  this.config = config;
2246
2016
  this.options = options;
@@ -2366,10 +2136,10 @@ var KubbDriver = class {
2366
2136
  plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
2367
2137
  },
2368
2138
  addMacro: (macro) => {
2369
- this.#transforms.add(plugin.name, macro);
2139
+ plugin.macros = [...plugin.macros ?? [], macro];
2370
2140
  },
2371
2141
  setMacros: (macros) => {
2372
- this.#transforms.set(plugin.name, macros);
2142
+ plugin.macros = [...macros];
2373
2143
  },
2374
2144
  setOptions: (opts) => {
2375
2145
  plugin.options = normalizePluginOptions({
@@ -2406,27 +2176,6 @@ var KubbDriver = class {
2406
2176
  const diagnostics = [];
2407
2177
  const parsersMap = /* @__PURE__ */ new Map();
2408
2178
  for (const parser of config.parsers) if (parser.extNames) for (const ext of parser.extNames) parsersMap.set(ext, parser);
2409
- const updateBuffer = [];
2410
- const unhookWrites = fileManager.hooks.addHooks({
2411
- start: async (files) => {
2412
- await hooks.callHook("kubb:files:processing:start", { files });
2413
- },
2414
- update: ({ file, processed, total, percentage }) => {
2415
- updateBuffer.push({
2416
- file,
2417
- processed,
2418
- total,
2419
- percentage,
2420
- config
2421
- });
2422
- },
2423
- end: async (files) => {
2424
- updateBuffer.sort((a, b) => a.processed - b.processed);
2425
- await hooks.callHook("kubb:files:processing:update", { files: updateBuffer });
2426
- updateBuffer.length = 0;
2427
- await hooks.callHook("kubb:files:processing:end", { files });
2428
- }
2429
- });
2430
2179
  return Diagnostics.scope((diagnostic) => diagnostics.push(diagnostic), async () => {
2431
2180
  try {
2432
2181
  this.options.signal?.throwIfAborted();
@@ -2496,7 +2245,9 @@ var KubbDriver = class {
2496
2245
  storage: config.storage,
2497
2246
  parsers: parsersMap,
2498
2247
  manifest: this.options.manifest,
2499
- signal: this.options.signal
2248
+ signal: this.options.signal,
2249
+ hooks,
2250
+ config
2500
2251
  });
2501
2252
  await hooks.callHook("kubb:build:end", {
2502
2253
  files: this.fileManager.files,
@@ -2507,8 +2258,6 @@ var KubbDriver = class {
2507
2258
  } catch (caughtError) {
2508
2259
  diagnostics.push(Diagnostics.from(caughtError));
2509
2260
  return { diagnostics: Diagnostics.dedupe(diagnostics) };
2510
- } finally {
2511
- unhookWrites();
2512
2261
  }
2513
2262
  });
2514
2263
  }
@@ -2539,7 +2288,7 @@ var KubbDriver = class {
2539
2288
  * generators of every plugin in dependency order. A per-node cache (`createNodeCache`) is created
2540
2289
  * once per node and shared by all of that node's plugins, so node-derived work is computed once
2541
2290
  * and reused instead of recomputed per plugin. Each node still runs through the plugin's macros
2542
- * (from `this.#transforms`) and its exclude/include/override filters before that plugin's
2291
+ * and its exclude/include/override filters before that plugin's
2543
2292
  * generator sees it, so plugins stay isolated. Schemas run before operations so file output
2544
2293
  * stays deterministic across runs. A generator with a `match` predicate that resolves `false`
2545
2294
  * for a node is skipped for that node, without calling `schema`/`operation`.
@@ -2570,7 +2319,6 @@ var KubbDriver = class {
2570
2319
  }
2571
2320
  return diagnostics;
2572
2321
  }
2573
- const transforms = this.#transforms;
2574
2322
  const { schemas, operations } = this.inputNode;
2575
2323
  const allowedSchemaNamesByPlugin = /* @__PURE__ */ new Map();
2576
2324
  for (const { plugin } of entries) {
@@ -2609,7 +2357,7 @@ var KubbDriver = class {
2609
2357
  };
2610
2358
  });
2611
2359
  const resolveForPlugin = (state, node) => {
2612
- const transformedNode = transforms.applyTo(state.plugin.name, node);
2360
+ const transformedNode = ast.applyMacros(node, state.plugin.macros ?? []);
2613
2361
  if (state.optionsAreStatic) return {
2614
2362
  transformedNode,
2615
2363
  options: state.plugin.options
@@ -2735,7 +2483,6 @@ var KubbDriver = class {
2735
2483
  dispose() {
2736
2484
  for (const unhook of this.#unhooks) unhook();
2737
2485
  this.#unhooks.length = 0;
2738
- this.#transforms.dispose();
2739
2486
  this.fileManager.dispose();
2740
2487
  this.inputNode = null;
2741
2488
  this.#adapterSource = null;
@@ -2835,6 +2582,113 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
2835
2582
  });
2836
2583
  }
2837
2584
  //#endregion
2838
- export { getElapsedMs as A, useOptions as C, resolveMeta as D, defineExtension as E, read as F, toPosixPath as I, write as L, clean as M, exists as N, Diagnostics as O, isPathInside as P, toError as R, useKubb as S, createExtensionFactory as T, setMacros as _, _usingCtx as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, FileManager as i, inParallel as j, formatMs as k, getInputKind as l, injectFile as m, pluginNotFoundError as n, Hookable as o, addMacro as p, createNodeCache as r, createResolver as s, KubbDriver as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y, camelCase as z };
2585
+ //#region src/Hookable.ts
2586
+ /**
2587
+ * Typed hook emitter that awaits all async listeners before resolving.
2588
+ *
2589
+ * @example
2590
+ * ```ts
2591
+ * const hooks = new Hookable<{ build: [name: string] }>()
2592
+ * hooks.hook('build', async (name) => { console.log(name) })
2593
+ * await hooks.callHook('build', 'petstore') // all listeners awaited
2594
+ * ```
2595
+ */
2596
+ var Hookable = class {
2597
+ #listeners = /* @__PURE__ */ new Map();
2598
+ /**
2599
+ * Calls `hookName` and awaits all registered listeners sequentially.
2600
+ * Throws if any listener rejects, wrapping the cause in an error that names the hook.
2601
+ *
2602
+ * @example
2603
+ * ```ts
2604
+ * await hooks.callHook('build', 'petstore')
2605
+ * ```
2606
+ */
2607
+ callHook(hookName, ...hookArgs) {
2608
+ const listeners = this.#listeners.get(hookName);
2609
+ if (!listeners?.size) return;
2610
+ return this.#emitAll(hookName, [...listeners], hookArgs);
2611
+ }
2612
+ async #emitAll(hookName, listeners, hookArgs) {
2613
+ for (const listener of listeners) try {
2614
+ await listener(...hookArgs);
2615
+ } catch (err) {
2616
+ throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
2617
+ }
2618
+ }
2619
+ /**
2620
+ * Registers a persistent listener for `hookName` and returns a function that removes it.
2621
+ *
2622
+ * @example
2623
+ * ```ts
2624
+ * const unhook = hooks.hook('build', async (name) => { console.log(name) })
2625
+ * unhook() // removes it
2626
+ * ```
2627
+ */
2628
+ hook(hookName, handler) {
2629
+ let listeners = this.#listeners.get(hookName);
2630
+ if (!listeners) this.#listeners.set(hookName, listeners = /* @__PURE__ */ new Set());
2631
+ listeners.add(handler);
2632
+ return () => this.removeHook(hookName, handler);
2633
+ }
2634
+ /**
2635
+ * Registers every handler in `configHooks` at once and returns a function that removes them
2636
+ * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
2637
+ *
2638
+ * @example
2639
+ * ```ts
2640
+ * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
2641
+ * unhook() // removes both
2642
+ * ```
2643
+ */
2644
+ addHooks(configHooks) {
2645
+ const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
2646
+ return () => {
2647
+ for (const unhook of unhooks) unhook();
2648
+ };
2649
+ }
2650
+ /**
2651
+ * Removes a previously registered listener.
2652
+ *
2653
+ * @example
2654
+ * ```ts
2655
+ * hooks.removeHook('build', handler)
2656
+ * ```
2657
+ */
2658
+ removeHook(hookName, handler) {
2659
+ this.#listeners.get(hookName)?.delete(handler);
2660
+ }
2661
+ /**
2662
+ * Returns the number of listeners registered for `hookName`.
2663
+ *
2664
+ * @example
2665
+ * ```ts
2666
+ * hooks.hook('build', handler)
2667
+ * hooks.listenerCount('build') // 1
2668
+ * ```
2669
+ */
2670
+ listenerCount(hookName) {
2671
+ return this.#listeners.get(hookName)?.size ?? 0;
2672
+ }
2673
+ /**
2674
+ * No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
2675
+ *
2676
+ * @deprecated There is no listener ceiling anymore.
2677
+ */
2678
+ setMaxListeners(_max) {}
2679
+ /**
2680
+ * Removes all listeners from every hook channel.
2681
+ *
2682
+ * @example
2683
+ * ```ts
2684
+ * hooks.removeAllHooks()
2685
+ * ```
2686
+ */
2687
+ removeAllHooks() {
2688
+ this.#listeners.clear();
2689
+ }
2690
+ };
2691
+ //#endregion
2692
+ export { inParallel as A, useOptions as C, Diagnostics as D, resolveMeta as E, toError as F, camelCase as I, read as M, toPosixPath as N, formatMs as O, write as P, useKubb as S, defineExtension as T, setMacros as _, FileManager as a, tryUseKubb as b, Resolver as c, definePlugin as d, addGenerator as f, requirePlugin as g, kubbContext as h, createNodeCache as i, isPathInside as j, getElapsedMs as k, getInputKind as l, injectFile as m, KubbDriver as n, _usingCtx as o, addMacro as p, pluginNotFoundError as r, createResolver as s, Hookable as t, assertPluginOption as u, setOptions as v, checkCompatibility as w, useConfig as x, setResolver as y };
2839
2693
 
2840
- //# sourceMappingURL=KubbDriver-DiYRWgxN.js.map
2694
+ //# sourceMappingURL=Hookable-C4PGA4hT.js.map