@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.
- package/dist/{KubbDriver-D2Jn4i3J.cjs → Hookable-BEzKPyQH.cjs} +144 -308
- package/dist/Hookable-BEzKPyQH.cjs.map +1 -0
- package/dist/{KubbDriver-DiYRWgxN.js → Hookable-C4PGA4hT.js} +147 -293
- package/dist/Hookable-C4PGA4hT.js.map +1 -0
- package/dist/{createAdapter-DfbfcqcJ.d.ts → createAdapter-D55JE9lX.d.ts} +16 -76
- package/dist/index.cjs +91 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -28
- package/dist/index.js +33 -81
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +9 -9
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/package.json +2 -2
- package/dist/KubbDriver-D2Jn4i3J.cjs.map +0 -1
- package/dist/KubbDriver-DiYRWgxN.js.map +0 -1
|
@@ -31,9 +31,8 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
31
31
|
let node_path = require("node:path");
|
|
32
32
|
node_path = __toESM(node_path, 1);
|
|
33
33
|
let _kubb_ast = require("@kubb/ast");
|
|
34
|
-
let node_events = require("node:events");
|
|
35
34
|
//#region package.json
|
|
36
|
-
var version = "5.9.
|
|
35
|
+
var version = "5.9.4";
|
|
37
36
|
//#endregion
|
|
38
37
|
//#region ../../internals/utils/src/casing.ts
|
|
39
38
|
/**
|
|
@@ -122,21 +121,6 @@ function detect() {
|
|
|
122
121
|
//#endregion
|
|
123
122
|
//#region ../../internals/utils/src/fs.ts
|
|
124
123
|
/**
|
|
125
|
-
* Resolves to `true` when the file or directory at `path` exists.
|
|
126
|
-
* Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* if (await exists('./kubb.config.ts')) {
|
|
131
|
-
* const content = await read('./kubb.config.ts')
|
|
132
|
-
* }
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
async function exists(path) {
|
|
136
|
-
if (runtime.isBun) return Bun.file(path).exists();
|
|
137
|
-
return (0, node_fs_promises.access)(path).then(() => true, () => false);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
124
|
* Reads the file at `path` as a UTF-8 string.
|
|
141
125
|
* Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
|
|
142
126
|
*
|
|
@@ -215,20 +199,6 @@ async function write(path, data, options = {}) {
|
|
|
215
199
|
return content;
|
|
216
200
|
}
|
|
217
201
|
/**
|
|
218
|
-
* Recursively removes `path`. Silently succeeds when `path` does not exist.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* await clean('./dist')
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
async function clean(path) {
|
|
226
|
-
return (0, node_fs_promises.rm)(path, {
|
|
227
|
-
recursive: true,
|
|
228
|
-
force: true
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
202
|
* Converts a filesystem path to use POSIX (`/`) separators.
|
|
233
203
|
*
|
|
234
204
|
* Most of the codebase compares and composes paths as strings (prefix matching, joining for
|
|
@@ -1025,12 +995,17 @@ function checkDependencies({ name, dependencies, plugins }) {
|
|
|
1025
995
|
});
|
|
1026
996
|
}
|
|
1027
997
|
}
|
|
998
|
+
/**
|
|
999
|
+
* Builds the factory behind `defineExtension`. It passes `{}` when called without options, and carries `kind` and
|
|
1000
|
+
* `meta` so tools can read them without calling it.
|
|
1001
|
+
*
|
|
1002
|
+
* @internal
|
|
1003
|
+
*/
|
|
1028
1004
|
function createExtensionFactory({ kind, meta, build }) {
|
|
1029
|
-
|
|
1030
|
-
return Object.assign(factory, meta ? {
|
|
1005
|
+
return Object.assign((options = {}) => build(options), {
|
|
1031
1006
|
kind,
|
|
1032
1007
|
meta
|
|
1033
|
-
}
|
|
1008
|
+
});
|
|
1034
1009
|
}
|
|
1035
1010
|
function defineExtension(definition) {
|
|
1036
1011
|
switch (definition.kind) {
|
|
@@ -1211,20 +1186,15 @@ function assertPluginOption({ plugin, option, value, allowed }) {
|
|
|
1211
1186
|
plugin
|
|
1212
1187
|
});
|
|
1213
1188
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
...plugin,
|
|
1221
|
-
meta: resolveMeta(plugin)
|
|
1222
|
-
};
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1189
|
+
/**
|
|
1190
|
+
* Defines a plugin from one object and returns a factory that takes the user's options.
|
|
1191
|
+
*
|
|
1192
|
+
* @deprecated Use `defineExtension` with `kind: 'plugin'` instead.
|
|
1193
|
+
*/
|
|
1194
|
+
function definePlugin(definition) {
|
|
1225
1195
|
return defineExtension({
|
|
1226
1196
|
kind: "plugin",
|
|
1227
|
-
...
|
|
1197
|
+
...definition
|
|
1228
1198
|
});
|
|
1229
1199
|
}
|
|
1230
1200
|
//#endregion
|
|
@@ -1719,125 +1689,6 @@ function createResolver(options) {
|
|
|
1719
1689
|
return new Resolver(options);
|
|
1720
1690
|
}
|
|
1721
1691
|
//#endregion
|
|
1722
|
-
//#region src/Hookable.ts
|
|
1723
|
-
/**
|
|
1724
|
-
* Typed hook emitter that awaits all async listeners before resolving.
|
|
1725
|
-
* Wraps Node's `EventEmitter` with full TypeScript hook-map inference.
|
|
1726
|
-
*
|
|
1727
|
-
* @example
|
|
1728
|
-
* ```ts
|
|
1729
|
-
* const hooks = new Hookable<{ build: [name: string] }>()
|
|
1730
|
-
* hooks.hook('build', async (name) => { console.log(name) })
|
|
1731
|
-
* await hooks.callHook('build', 'petstore') // all listeners awaited
|
|
1732
|
-
* ```
|
|
1733
|
-
*/
|
|
1734
|
-
var Hookable = class {
|
|
1735
|
-
/**
|
|
1736
|
-
* Maximum number of listeners per hook before Node emits a memory-leak warning.
|
|
1737
|
-
* @default 10
|
|
1738
|
-
*/
|
|
1739
|
-
constructor(maxListener = 10) {
|
|
1740
|
-
this.#emitter.setMaxListeners(maxListener);
|
|
1741
|
-
}
|
|
1742
|
-
#emitter = new node_events.EventEmitter();
|
|
1743
|
-
/**
|
|
1744
|
-
* Calls `hookName` and awaits all registered listeners sequentially.
|
|
1745
|
-
* Throws if any listener rejects, wrapping the cause in an error that names the hook.
|
|
1746
|
-
*
|
|
1747
|
-
* @example
|
|
1748
|
-
* ```ts
|
|
1749
|
-
* await hooks.callHook('build', 'petstore')
|
|
1750
|
-
* ```
|
|
1751
|
-
*/
|
|
1752
|
-
callHook(hookName, ...hookArgs) {
|
|
1753
|
-
const listeners = this.#emitter.listeners(hookName);
|
|
1754
|
-
if (listeners.length === 0) return;
|
|
1755
|
-
return this.#emitAll(hookName, listeners, hookArgs);
|
|
1756
|
-
}
|
|
1757
|
-
async #emitAll(hookName, listeners, hookArgs) {
|
|
1758
|
-
for (const listener of listeners) try {
|
|
1759
|
-
await listener(...hookArgs);
|
|
1760
|
-
} catch (err) {
|
|
1761
|
-
throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
/**
|
|
1765
|
-
* Registers a persistent listener for `hookName` and returns a function that removes it.
|
|
1766
|
-
*
|
|
1767
|
-
* @example
|
|
1768
|
-
* ```ts
|
|
1769
|
-
* const unhook = hooks.hook('build', async (name) => { console.log(name) })
|
|
1770
|
-
* unhook() // removes it
|
|
1771
|
-
* ```
|
|
1772
|
-
*/
|
|
1773
|
-
hook(hookName, handler) {
|
|
1774
|
-
this.#emitter.on(hookName, handler);
|
|
1775
|
-
return () => this.removeHook(hookName, handler);
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Registers every handler in `configHooks` at once and returns a function that removes them
|
|
1779
|
-
* all. Undefined entries are skipped, so a partial hook object registers only its present keys.
|
|
1780
|
-
*
|
|
1781
|
-
* @example
|
|
1782
|
-
* ```ts
|
|
1783
|
-
* const unhook = hooks.addHooks({ build: onBuild, done: onDone })
|
|
1784
|
-
* unhook() // removes both
|
|
1785
|
-
* ```
|
|
1786
|
-
*/
|
|
1787
|
-
addHooks(configHooks) {
|
|
1788
|
-
const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
|
|
1789
|
-
return () => {
|
|
1790
|
-
for (const unhook of unhooks) unhook();
|
|
1791
|
-
};
|
|
1792
|
-
}
|
|
1793
|
-
/**
|
|
1794
|
-
* Removes a previously registered listener.
|
|
1795
|
-
*
|
|
1796
|
-
* @example
|
|
1797
|
-
* ```ts
|
|
1798
|
-
* hooks.removeHook('build', handler)
|
|
1799
|
-
* ```
|
|
1800
|
-
*/
|
|
1801
|
-
removeHook(hookName, handler) {
|
|
1802
|
-
this.#emitter.off(hookName, handler);
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Returns the number of listeners registered for `hookName`.
|
|
1806
|
-
*
|
|
1807
|
-
* @example
|
|
1808
|
-
* ```ts
|
|
1809
|
-
* hooks.hook('build', handler)
|
|
1810
|
-
* hooks.listenerCount('build') // 1
|
|
1811
|
-
* ```
|
|
1812
|
-
*/
|
|
1813
|
-
listenerCount(hookName) {
|
|
1814
|
-
return this.#emitter.listenerCount(hookName);
|
|
1815
|
-
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.
|
|
1818
|
-
* Set this above the expected listener count when many listeners attach by design.
|
|
1819
|
-
*
|
|
1820
|
-
* @example
|
|
1821
|
-
* ```ts
|
|
1822
|
-
* hooks.setMaxListeners(40)
|
|
1823
|
-
* ```
|
|
1824
|
-
*/
|
|
1825
|
-
setMaxListeners(max) {
|
|
1826
|
-
this.#emitter.setMaxListeners(max);
|
|
1827
|
-
}
|
|
1828
|
-
/**
|
|
1829
|
-
* Removes all listeners from every hook channel.
|
|
1830
|
-
*
|
|
1831
|
-
* @example
|
|
1832
|
-
* ```ts
|
|
1833
|
-
* hooks.removeAllHooks()
|
|
1834
|
-
* ```
|
|
1835
|
-
*/
|
|
1836
|
-
removeAllHooks() {
|
|
1837
|
-
this.#emitter.removeAllListeners();
|
|
1838
|
-
}
|
|
1839
|
-
};
|
|
1840
|
-
//#endregion
|
|
1841
1692
|
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
|
|
1842
1693
|
function _usingCtx() {
|
|
1843
1694
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
@@ -1917,7 +1768,7 @@ function runParser(parser, print) {
|
|
|
1917
1768
|
async function parseCopy(file, parser) {
|
|
1918
1769
|
let content;
|
|
1919
1770
|
try {
|
|
1920
|
-
content = await
|
|
1771
|
+
content = await (0, node_fs_promises.readFile)(file.copy, "utf8");
|
|
1921
1772
|
} catch (err) {
|
|
1922
1773
|
throw new Error(`[kubb] Could not copy file into output: ${file.copy}`, { cause: err });
|
|
1923
1774
|
}
|
|
@@ -1972,7 +1823,6 @@ function isUnchanged({ stored, source, key, manifest }) {
|
|
|
1972
1823
|
* ```
|
|
1973
1824
|
*/
|
|
1974
1825
|
var FileManager = class {
|
|
1975
|
-
hooks = new Hookable();
|
|
1976
1826
|
#cache = /* @__PURE__ */ new Map();
|
|
1977
1827
|
#sorted = null;
|
|
1978
1828
|
add(...files) {
|
|
@@ -2021,13 +1871,11 @@ var FileManager = class {
|
|
|
2021
1871
|
return [...seen.values()];
|
|
2022
1872
|
}
|
|
2023
1873
|
/**
|
|
2024
|
-
* Releases all stored files
|
|
2025
|
-
* `kubb:build:end`.
|
|
1874
|
+
* Releases all stored files. Called by the core after `kubb:build:end`.
|
|
2026
1875
|
*/
|
|
2027
1876
|
dispose() {
|
|
2028
1877
|
this.#cache.clear();
|
|
2029
1878
|
this.#sorted = null;
|
|
2030
|
-
this.hooks.removeAllHooks();
|
|
2031
1879
|
}
|
|
2032
1880
|
/**
|
|
2033
1881
|
* All stored files in stable sort order (shortest path first, barrel files
|
|
@@ -2049,28 +1897,29 @@ var FileManager = class {
|
|
|
2049
1897
|
* Parses and writes every file through a bounded pool of workers. A small spec runs all its files
|
|
2050
1898
|
* at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in
|
|
2051
1899
|
* memory rather than holding every source, while still overlapping each file's write with the
|
|
2052
|
-
* next file's parse.
|
|
2053
|
-
*
|
|
1900
|
+
* next file's parse. Files finish in whatever order they parse, so the update rows are sorted back
|
|
1901
|
+
* into input order before `kubb:files:processing:update` fires once with the whole batch.
|
|
2054
1902
|
*
|
|
2055
1903
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
2056
1904
|
* writes nothing and leaves every mtime where it was.
|
|
2057
1905
|
*/
|
|
2058
|
-
async write(files, { storage, parsers, manifest, signal }) {
|
|
1906
|
+
async write(files, { storage, parsers, manifest, signal, hooks, config }) {
|
|
2059
1907
|
if (files.length === 0) return;
|
|
2060
|
-
await
|
|
1908
|
+
await hooks?.callHook("kubb:files:processing:start", { files });
|
|
2061
1909
|
const total = files.length;
|
|
1910
|
+
const updates = [];
|
|
2062
1911
|
await inParallel({
|
|
2063
1912
|
items: files,
|
|
2064
1913
|
limit: 50,
|
|
2065
1914
|
run: async (file, index) => {
|
|
2066
1915
|
signal?.throwIfAborted();
|
|
2067
1916
|
const source = await this.parse(file, { parsers });
|
|
2068
|
-
|
|
1917
|
+
if (config) updates.push({
|
|
2069
1918
|
file,
|
|
2070
|
-
source,
|
|
2071
1919
|
processed: index + 1,
|
|
2072
1920
|
total,
|
|
2073
|
-
percentage: (index + 1) / total * 100
|
|
1921
|
+
percentage: (index + 1) / total * 100,
|
|
1922
|
+
config
|
|
2074
1923
|
});
|
|
2075
1924
|
if (!source) return;
|
|
2076
1925
|
signal?.throwIfAborted();
|
|
@@ -2089,83 +1938,9 @@ var FileManager = class {
|
|
|
2089
1938
|
});
|
|
2090
1939
|
}
|
|
2091
1940
|
});
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
};
|
|
2095
|
-
//#endregion
|
|
2096
|
-
//#region src/Transform.ts
|
|
2097
|
-
/**
|
|
2098
|
-
* Holds an ordered list of macros per plugin, keyed by plugin name. Each plugin's macros run in
|
|
2099
|
-
* isolation on the original adapter node and are composed into a single `Visitor` that the
|
|
2100
|
-
* `@kubb/ast` `transform` primitive applies. `applyTo` is a per-plugin lookup, not a cross-plugin
|
|
2101
|
-
* chain, so plugin A's macros never see plugin B's output. When a plugin has no macros, `applyTo`
|
|
2102
|
-
* returns the original node reference, and `transform` does the same when the composed visitor
|
|
2103
|
-
* leaves the tree untouched, so callers can detect a no-op by identity.
|
|
2104
|
-
*
|
|
2105
|
-
* Registration order matches the order setup hooks fire, which the driver has already sorted by
|
|
2106
|
-
* `enforce` and dependency edges. The registry preserves that order. Macro `enforce` only reorders
|
|
2107
|
-
* within a single plugin's list.
|
|
2108
|
-
*/
|
|
2109
|
-
var Transform = class {
|
|
2110
|
-
#macros = /* @__PURE__ */ new Map();
|
|
2111
|
-
#composed = /* @__PURE__ */ new Map();
|
|
2112
|
-
#memo = /* @__PURE__ */ new Map();
|
|
2113
|
-
/**
|
|
2114
|
-
* Appends `macro` to the plugin's list, after any macros already registered.
|
|
2115
|
-
*/
|
|
2116
|
-
add(pluginName, macro) {
|
|
2117
|
-
const list = this.#macros.get(pluginName);
|
|
2118
|
-
if (list) list.push(macro);
|
|
2119
|
-
else this.#macros.set(pluginName, [macro]);
|
|
2120
|
-
this.#invalidate(pluginName);
|
|
2121
|
-
}
|
|
2122
|
-
/**
|
|
2123
|
-
* Replaces the plugin's macro list with `macros`.
|
|
2124
|
-
*/
|
|
2125
|
-
set(pluginName, macros) {
|
|
2126
|
-
this.#macros.set(pluginName, [...macros]);
|
|
2127
|
-
this.#invalidate(pluginName);
|
|
2128
|
-
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Runs the plugin's macros on `node`. Returns the original node reference when the plugin has no
|
|
2131
|
-
* macros, so callers can compare by identity to detect a no-op.
|
|
2132
|
-
*/
|
|
2133
|
-
applyTo(pluginName, node) {
|
|
2134
|
-
const visitor = this.#visitorFor(pluginName);
|
|
2135
|
-
if (!visitor) return node;
|
|
2136
|
-
let memo = this.#memo.get(pluginName);
|
|
2137
|
-
if (!memo) {
|
|
2138
|
-
memo = /* @__PURE__ */ new WeakMap();
|
|
2139
|
-
this.#memo.set(pluginName, memo);
|
|
2140
|
-
}
|
|
2141
|
-
const cached = memo.get(node);
|
|
2142
|
-
if (cached) return cached;
|
|
2143
|
-
const result = (0, _kubb_ast.transform)(node, visitor);
|
|
2144
|
-
memo.set(node, result);
|
|
2145
|
-
return result;
|
|
2146
|
-
}
|
|
2147
|
-
/**
|
|
2148
|
-
* Clears every registration. Called from the driver's `dispose()` so macros do not leak across
|
|
2149
|
-
* builds.
|
|
2150
|
-
*/
|
|
2151
|
-
dispose() {
|
|
2152
|
-
this.#macros.clear();
|
|
2153
|
-
this.#composed.clear();
|
|
2154
|
-
this.#memo.clear();
|
|
2155
|
-
}
|
|
2156
|
-
#invalidate(pluginName) {
|
|
2157
|
-
this.#composed.delete(pluginName);
|
|
2158
|
-
this.#memo.delete(pluginName);
|
|
2159
|
-
}
|
|
2160
|
-
#visitorFor(pluginName) {
|
|
2161
|
-
const macros = this.#macros.get(pluginName);
|
|
2162
|
-
if (!macros || macros.length === 0) return void 0;
|
|
2163
|
-
let composed = this.#composed.get(pluginName);
|
|
2164
|
-
if (!composed) {
|
|
2165
|
-
composed = (0, _kubb_ast.composeMacros)(macros);
|
|
2166
|
-
this.#composed.set(pluginName, composed);
|
|
2167
|
-
}
|
|
2168
|
-
return composed;
|
|
1941
|
+
updates.sort((a, b) => a.processed - b.processed);
|
|
1942
|
+
await hooks?.callHook("kubb:files:processing:update", { files: updates });
|
|
1943
|
+
await hooks?.callHook("kubb:files:processing:end", { files });
|
|
2169
1944
|
}
|
|
2170
1945
|
};
|
|
2171
1946
|
//#endregion
|
|
@@ -2262,11 +2037,6 @@ var KubbDriver = class {
|
|
|
2262
2037
|
* them in one pass. External `hooks.hook(...)` listeners are not tracked.
|
|
2263
2038
|
*/
|
|
2264
2039
|
#unhooks = [];
|
|
2265
|
-
/**
|
|
2266
|
-
* Transform registry. Plugins populate it during `kubb:plugin:setup` via `addMacro`/`setMacros`,
|
|
2267
|
-
* and `#runGenerators` reads it once per `(plugin, node)` pair through `applyTo`.
|
|
2268
|
-
*/
|
|
2269
|
-
#transforms = new Transform();
|
|
2270
2040
|
constructor(config, options) {
|
|
2271
2041
|
this.config = config;
|
|
2272
2042
|
this.options = options;
|
|
@@ -2392,10 +2162,10 @@ var KubbDriver = class {
|
|
|
2392
2162
|
plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
|
|
2393
2163
|
},
|
|
2394
2164
|
addMacro: (macro) => {
|
|
2395
|
-
|
|
2165
|
+
plugin.macros = [...plugin.macros ?? [], macro];
|
|
2396
2166
|
},
|
|
2397
2167
|
setMacros: (macros) => {
|
|
2398
|
-
|
|
2168
|
+
plugin.macros = [...macros];
|
|
2399
2169
|
},
|
|
2400
2170
|
setOptions: (opts) => {
|
|
2401
2171
|
plugin.options = normalizePluginOptions({
|
|
@@ -2432,27 +2202,6 @@ var KubbDriver = class {
|
|
|
2432
2202
|
const diagnostics = [];
|
|
2433
2203
|
const parsersMap = /* @__PURE__ */ new Map();
|
|
2434
2204
|
for (const parser of config.parsers) if (parser.extNames) for (const ext of parser.extNames) parsersMap.set(ext, parser);
|
|
2435
|
-
const updateBuffer = [];
|
|
2436
|
-
const unhookWrites = fileManager.hooks.addHooks({
|
|
2437
|
-
start: async (files) => {
|
|
2438
|
-
await hooks.callHook("kubb:files:processing:start", { files });
|
|
2439
|
-
},
|
|
2440
|
-
update: ({ file, processed, total, percentage }) => {
|
|
2441
|
-
updateBuffer.push({
|
|
2442
|
-
file,
|
|
2443
|
-
processed,
|
|
2444
|
-
total,
|
|
2445
|
-
percentage,
|
|
2446
|
-
config
|
|
2447
|
-
});
|
|
2448
|
-
},
|
|
2449
|
-
end: async (files) => {
|
|
2450
|
-
updateBuffer.sort((a, b) => a.processed - b.processed);
|
|
2451
|
-
await hooks.callHook("kubb:files:processing:update", { files: updateBuffer });
|
|
2452
|
-
updateBuffer.length = 0;
|
|
2453
|
-
await hooks.callHook("kubb:files:processing:end", { files });
|
|
2454
|
-
}
|
|
2455
|
-
});
|
|
2456
2205
|
return Diagnostics.scope((diagnostic) => diagnostics.push(diagnostic), async () => {
|
|
2457
2206
|
try {
|
|
2458
2207
|
this.options.signal?.throwIfAborted();
|
|
@@ -2522,7 +2271,9 @@ var KubbDriver = class {
|
|
|
2522
2271
|
storage: config.storage,
|
|
2523
2272
|
parsers: parsersMap,
|
|
2524
2273
|
manifest: this.options.manifest,
|
|
2525
|
-
signal: this.options.signal
|
|
2274
|
+
signal: this.options.signal,
|
|
2275
|
+
hooks,
|
|
2276
|
+
config
|
|
2526
2277
|
});
|
|
2527
2278
|
await hooks.callHook("kubb:build:end", {
|
|
2528
2279
|
files: this.fileManager.files,
|
|
@@ -2533,8 +2284,6 @@ var KubbDriver = class {
|
|
|
2533
2284
|
} catch (caughtError) {
|
|
2534
2285
|
diagnostics.push(Diagnostics.from(caughtError));
|
|
2535
2286
|
return { diagnostics: Diagnostics.dedupe(diagnostics) };
|
|
2536
|
-
} finally {
|
|
2537
|
-
unhookWrites();
|
|
2538
2287
|
}
|
|
2539
2288
|
});
|
|
2540
2289
|
}
|
|
@@ -2565,7 +2314,7 @@ var KubbDriver = class {
|
|
|
2565
2314
|
* generators of every plugin in dependency order. A per-node cache (`createNodeCache`) is created
|
|
2566
2315
|
* once per node and shared by all of that node's plugins, so node-derived work is computed once
|
|
2567
2316
|
* and reused instead of recomputed per plugin. Each node still runs through the plugin's macros
|
|
2568
|
-
*
|
|
2317
|
+
* and its exclude/include/override filters before that plugin's
|
|
2569
2318
|
* generator sees it, so plugins stay isolated. Schemas run before operations so file output
|
|
2570
2319
|
* stays deterministic across runs. A generator with a `match` predicate that resolves `false`
|
|
2571
2320
|
* for a node is skipped for that node, without calling `schema`/`operation`.
|
|
@@ -2596,7 +2345,6 @@ var KubbDriver = class {
|
|
|
2596
2345
|
}
|
|
2597
2346
|
return diagnostics;
|
|
2598
2347
|
}
|
|
2599
|
-
const transforms = this.#transforms;
|
|
2600
2348
|
const { schemas, operations } = this.inputNode;
|
|
2601
2349
|
const allowedSchemaNamesByPlugin = /* @__PURE__ */ new Map();
|
|
2602
2350
|
for (const { plugin } of entries) {
|
|
@@ -2635,7 +2383,7 @@ var KubbDriver = class {
|
|
|
2635
2383
|
};
|
|
2636
2384
|
});
|
|
2637
2385
|
const resolveForPlugin = (state, node) => {
|
|
2638
|
-
const transformedNode =
|
|
2386
|
+
const transformedNode = _kubb_ast.ast.applyMacros(node, state.plugin.macros ?? []);
|
|
2639
2387
|
if (state.optionsAreStatic) return {
|
|
2640
2388
|
transformedNode,
|
|
2641
2389
|
options: state.plugin.options
|
|
@@ -2761,7 +2509,6 @@ var KubbDriver = class {
|
|
|
2761
2509
|
dispose() {
|
|
2762
2510
|
for (const unhook of this.#unhooks) unhook();
|
|
2763
2511
|
this.#unhooks.length = 0;
|
|
2764
|
-
this.#transforms.dispose();
|
|
2765
2512
|
this.fileManager.dispose();
|
|
2766
2513
|
this.inputNode = null;
|
|
2767
2514
|
this.#adapterSource = null;
|
|
@@ -2861,6 +2608,113 @@ function pluginNotFoundError({ pluginName, requiredBy }) {
|
|
|
2861
2608
|
});
|
|
2862
2609
|
}
|
|
2863
2610
|
//#endregion
|
|
2611
|
+
//#region src/Hookable.ts
|
|
2612
|
+
/**
|
|
2613
|
+
* Typed hook emitter that awaits all async listeners before resolving.
|
|
2614
|
+
*
|
|
2615
|
+
* @example
|
|
2616
|
+
* ```ts
|
|
2617
|
+
* const hooks = new Hookable<{ build: [name: string] }>()
|
|
2618
|
+
* hooks.hook('build', async (name) => { console.log(name) })
|
|
2619
|
+
* await hooks.callHook('build', 'petstore') // all listeners awaited
|
|
2620
|
+
* ```
|
|
2621
|
+
*/
|
|
2622
|
+
var Hookable = class {
|
|
2623
|
+
#listeners = /* @__PURE__ */ new Map();
|
|
2624
|
+
/**
|
|
2625
|
+
* Calls `hookName` and awaits all registered listeners sequentially.
|
|
2626
|
+
* Throws if any listener rejects, wrapping the cause in an error that names the hook.
|
|
2627
|
+
*
|
|
2628
|
+
* @example
|
|
2629
|
+
* ```ts
|
|
2630
|
+
* await hooks.callHook('build', 'petstore')
|
|
2631
|
+
* ```
|
|
2632
|
+
*/
|
|
2633
|
+
callHook(hookName, ...hookArgs) {
|
|
2634
|
+
const listeners = this.#listeners.get(hookName);
|
|
2635
|
+
if (!listeners?.size) return;
|
|
2636
|
+
return this.#emitAll(hookName, [...listeners], hookArgs);
|
|
2637
|
+
}
|
|
2638
|
+
async #emitAll(hookName, listeners, hookArgs) {
|
|
2639
|
+
for (const listener of listeners) try {
|
|
2640
|
+
await listener(...hookArgs);
|
|
2641
|
+
} catch (err) {
|
|
2642
|
+
throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* Registers a persistent listener for `hookName` and returns a function that removes it.
|
|
2647
|
+
*
|
|
2648
|
+
* @example
|
|
2649
|
+
* ```ts
|
|
2650
|
+
* const unhook = hooks.hook('build', async (name) => { console.log(name) })
|
|
2651
|
+
* unhook() // removes it
|
|
2652
|
+
* ```
|
|
2653
|
+
*/
|
|
2654
|
+
hook(hookName, handler) {
|
|
2655
|
+
let listeners = this.#listeners.get(hookName);
|
|
2656
|
+
if (!listeners) this.#listeners.set(hookName, listeners = /* @__PURE__ */ new Set());
|
|
2657
|
+
listeners.add(handler);
|
|
2658
|
+
return () => this.removeHook(hookName, handler);
|
|
2659
|
+
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Registers every handler in `configHooks` at once and returns a function that removes them
|
|
2662
|
+
* all. Undefined entries are skipped, so a partial hook object registers only its present keys.
|
|
2663
|
+
*
|
|
2664
|
+
* @example
|
|
2665
|
+
* ```ts
|
|
2666
|
+
* const unhook = hooks.addHooks({ build: onBuild, done: onDone })
|
|
2667
|
+
* unhook() // removes both
|
|
2668
|
+
* ```
|
|
2669
|
+
*/
|
|
2670
|
+
addHooks(configHooks) {
|
|
2671
|
+
const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
|
|
2672
|
+
return () => {
|
|
2673
|
+
for (const unhook of unhooks) unhook();
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Removes a previously registered listener.
|
|
2678
|
+
*
|
|
2679
|
+
* @example
|
|
2680
|
+
* ```ts
|
|
2681
|
+
* hooks.removeHook('build', handler)
|
|
2682
|
+
* ```
|
|
2683
|
+
*/
|
|
2684
|
+
removeHook(hookName, handler) {
|
|
2685
|
+
this.#listeners.get(hookName)?.delete(handler);
|
|
2686
|
+
}
|
|
2687
|
+
/**
|
|
2688
|
+
* Returns the number of listeners registered for `hookName`.
|
|
2689
|
+
*
|
|
2690
|
+
* @example
|
|
2691
|
+
* ```ts
|
|
2692
|
+
* hooks.hook('build', handler)
|
|
2693
|
+
* hooks.listenerCount('build') // 1
|
|
2694
|
+
* ```
|
|
2695
|
+
*/
|
|
2696
|
+
listenerCount(hookName) {
|
|
2697
|
+
return this.#listeners.get(hookName)?.size ?? 0;
|
|
2698
|
+
}
|
|
2699
|
+
/**
|
|
2700
|
+
* No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
|
|
2701
|
+
*
|
|
2702
|
+
* @deprecated There is no listener ceiling anymore.
|
|
2703
|
+
*/
|
|
2704
|
+
setMaxListeners(_max) {}
|
|
2705
|
+
/**
|
|
2706
|
+
* Removes all listeners from every hook channel.
|
|
2707
|
+
*
|
|
2708
|
+
* @example
|
|
2709
|
+
* ```ts
|
|
2710
|
+
* hooks.removeAllHooks()
|
|
2711
|
+
* ```
|
|
2712
|
+
*/
|
|
2713
|
+
removeAllHooks() {
|
|
2714
|
+
this.#listeners.clear();
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2717
|
+
//#endregion
|
|
2864
2718
|
Object.defineProperty(exports, "Diagnostics", {
|
|
2865
2719
|
enumerable: true,
|
|
2866
2720
|
get: function() {
|
|
@@ -2939,18 +2793,6 @@ Object.defineProperty(exports, "checkCompatibility", {
|
|
|
2939
2793
|
return checkCompatibility;
|
|
2940
2794
|
}
|
|
2941
2795
|
});
|
|
2942
|
-
Object.defineProperty(exports, "clean", {
|
|
2943
|
-
enumerable: true,
|
|
2944
|
-
get: function() {
|
|
2945
|
-
return clean;
|
|
2946
|
-
}
|
|
2947
|
-
});
|
|
2948
|
-
Object.defineProperty(exports, "createExtensionFactory", {
|
|
2949
|
-
enumerable: true,
|
|
2950
|
-
get: function() {
|
|
2951
|
-
return createExtensionFactory;
|
|
2952
|
-
}
|
|
2953
|
-
});
|
|
2954
2796
|
Object.defineProperty(exports, "createNodeCache", {
|
|
2955
2797
|
enumerable: true,
|
|
2956
2798
|
get: function() {
|
|
@@ -2975,12 +2817,6 @@ Object.defineProperty(exports, "definePlugin", {
|
|
|
2975
2817
|
return definePlugin;
|
|
2976
2818
|
}
|
|
2977
2819
|
});
|
|
2978
|
-
Object.defineProperty(exports, "exists", {
|
|
2979
|
-
enumerable: true,
|
|
2980
|
-
get: function() {
|
|
2981
|
-
return exists;
|
|
2982
|
-
}
|
|
2983
|
-
});
|
|
2984
2820
|
Object.defineProperty(exports, "formatMs", {
|
|
2985
2821
|
enumerable: true,
|
|
2986
2822
|
get: function() {
|
|
@@ -3108,4 +2944,4 @@ Object.defineProperty(exports, "write", {
|
|
|
3108
2944
|
}
|
|
3109
2945
|
});
|
|
3110
2946
|
|
|
3111
|
-
//# sourceMappingURL=
|
|
2947
|
+
//# sourceMappingURL=Hookable-BEzKPyQH.cjs.map
|