@kubb/core 5.10.2 → 5.10.3
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/{Hookable-Bjfoua7Y.js → Hookable-BsWZ8pHO.js} +11 -4
- package/dist/{Hookable-Bjfoua7Y.js.map → Hookable-BsWZ8pHO.js.map} +1 -1
- package/dist/Hookable-C4S0gBso.cjs +3030 -0
- package/dist/Hookable-C4S0gBso.cjs.map +1 -0
- package/dist/{Hookable-RTuEiBd9.cjs → Hookable-pvEb-nN9.cjs} +2 -2
- package/dist/{Hookable-RTuEiBd9.cjs.map → Hookable-pvEb-nN9.cjs.map} +1 -1
- package/dist/{createAdapter-CMnLz31B.d.ts → createAdapter-B5kKMsWV.d.cts} +1 -2
- package/dist/createAdapter-B5kKMsWV.d.ts +3147 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +620 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.cts +107 -0
- package/dist/mocks.d.ts +1 -2
- package/dist/mocks.js +1 -2
- package/dist/mocks.js.map +1 -1
- package/package.json +26 -8
- package/dist/rolldown-runtime-CRm0XQPb.js +0 -9
|
@@ -0,0 +1,3030 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let verkit = require("verkit");
|
|
24
|
+
let node_async_hooks = require("node:async_hooks");
|
|
25
|
+
let node_fs_promises = require("node:fs/promises");
|
|
26
|
+
let node_path = require("node:path");
|
|
27
|
+
node_path = __toESM(node_path, 1);
|
|
28
|
+
let node_util = require("node:util");
|
|
29
|
+
let _kubb_ast = require("@kubb/ast");
|
|
30
|
+
//#region package.json
|
|
31
|
+
var version = "5.10.3";
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region ../../internals/utils/src/casing.ts
|
|
34
|
+
/**
|
|
35
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
36
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
37
|
+
* and capitalizes each word according to `pascal`.
|
|
38
|
+
*
|
|
39
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
40
|
+
*/
|
|
41
|
+
function toCamelOrPascal(text, pascal) {
|
|
42
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
43
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
44
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
45
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts `text` to camelCase.
|
|
49
|
+
*
|
|
50
|
+
* @example Word boundaries
|
|
51
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
52
|
+
*
|
|
53
|
+
* @example With a prefix
|
|
54
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
55
|
+
*/
|
|
56
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
57
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region ../../internals/utils/src/errors.ts
|
|
61
|
+
/**
|
|
62
|
+
* Coerces an unknown thrown value to an `Error` instance.
|
|
63
|
+
* Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* try { ... } catch(err) {
|
|
68
|
+
* throw new Error('Build failed', { cause: toError(err) })
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function toError(value) {
|
|
73
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Extracts a human-readable message from any thrown value.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* getErrorMessage(new Error('oops')) // 'oops'
|
|
81
|
+
* getErrorMessage('plain string') // 'plain string'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function getErrorMessage(value) {
|
|
85
|
+
return value instanceof Error ? value.message : String(value);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a
|
|
89
|
+
* non-`Error` cause or a cycle.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)
|
|
94
|
+
* // ['Config failed loading', 'boom']
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
function getErrorChain(error) {
|
|
98
|
+
const chain = [];
|
|
99
|
+
for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) chain.push(current);
|
|
100
|
+
return chain;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../../internals/utils/src/jsonPointer.ts
|
|
104
|
+
/**
|
|
105
|
+
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
106
|
+
* name holding those characters maps to a distinct pointer.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* escapePointerToken('/pets/{id}') // '~1pets~1{id}'
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function escapePointerToken(token) {
|
|
114
|
+
return token.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region ../../internals/utils/src/runtime.ts
|
|
118
|
+
const isBun = typeof Bun !== "undefined";
|
|
119
|
+
const isDeno = "Deno" in globalThis;
|
|
120
|
+
/**
|
|
121
|
+
* The JavaScript runtime executing the current process: its name, version and whether it is Bun.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
const runtime = {
|
|
129
|
+
isBun,
|
|
130
|
+
...detect()
|
|
131
|
+
};
|
|
132
|
+
function detect() {
|
|
133
|
+
if (isBun) return {
|
|
134
|
+
name: "bun",
|
|
135
|
+
version: process.versions.bun ?? ""
|
|
136
|
+
};
|
|
137
|
+
if (isDeno) return {
|
|
138
|
+
name: "deno",
|
|
139
|
+
version: globalThis.Deno?.version?.deno ?? ""
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
name: "node",
|
|
143
|
+
version: process.versions?.node ?? ""
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region ../../internals/utils/src/fs.ts
|
|
148
|
+
/**
|
|
149
|
+
* Reads the file at `path` as a UTF-8 string.
|
|
150
|
+
* Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const source = await read('./src/Pet.ts')
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
async function read(path) {
|
|
158
|
+
if (runtime.isBun) return Bun.file(path).text();
|
|
159
|
+
return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact
|
|
163
|
+
* bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a
|
|
164
|
+
* reason to rewrite the file.
|
|
165
|
+
*
|
|
166
|
+
* Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one
|
|
167
|
+
* that normalizes what it stores. Trimming only `stored` would leave a source with leading
|
|
168
|
+
* whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison
|
|
169
|
+
* has already dropped.
|
|
170
|
+
*/
|
|
171
|
+
function matchesStored({ stored, source }) {
|
|
172
|
+
return stored.trim() === source.trim();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline
|
|
176
|
+
* the way prettier, biome, and oxfmt all do.
|
|
177
|
+
* Skips the write when the trimmed content is empty, or when the file already holds that content.
|
|
178
|
+
* Creates any missing parent directories automatically.
|
|
179
|
+
* When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline
|
|
184
|
+
* await write('./src/Pet.ts', source) // null — file unchanged
|
|
185
|
+
* await write('./src/Pet.ts', ' ') // null — empty content skipped
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
async function write(path, data, options = {}) {
|
|
189
|
+
const trimmed = data.trim();
|
|
190
|
+
if (trimmed === "") return null;
|
|
191
|
+
const content = `${trimmed}\n`;
|
|
192
|
+
const resolved = (0, node_path.resolve)(path);
|
|
193
|
+
let stored = options.stored;
|
|
194
|
+
if (stored === void 0) {
|
|
195
|
+
if (runtime.isBun) {
|
|
196
|
+
const file = Bun.file(resolved);
|
|
197
|
+
stored = await file.exists() ? await file.text() : null;
|
|
198
|
+
} else try {
|
|
199
|
+
stored = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
|
|
200
|
+
} catch {
|
|
201
|
+
stored = null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (matchesStored({
|
|
205
|
+
stored: stored ?? "",
|
|
206
|
+
source: trimmed
|
|
207
|
+
})) return null;
|
|
208
|
+
if (runtime.isBun) {
|
|
209
|
+
await Bun.write(resolved, content);
|
|
210
|
+
return content;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error.code !== "ENOENT") throw error;
|
|
216
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
|
|
217
|
+
await (0, node_fs_promises.writeFile)(resolved, content, { encoding: "utf-8" });
|
|
218
|
+
}
|
|
219
|
+
if (options.sanity) {
|
|
220
|
+
const savedData = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
|
|
221
|
+
if (savedData !== content) throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`);
|
|
222
|
+
return savedData;
|
|
223
|
+
}
|
|
224
|
+
return content;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Converts a filesystem path to use POSIX (`/`) separators.
|
|
228
|
+
*
|
|
229
|
+
* Most of the codebase compares and composes paths as strings (prefix matching, joining for
|
|
230
|
+
* import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated
|
|
231
|
+
* paths, but on Windows it returns `\`-separated paths, which breaks every such comparison.
|
|
232
|
+
*
|
|
233
|
+
* Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the
|
|
234
|
+
* code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is
|
|
235
|
+
* exercisable from POSIX CI.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* toPosixPath('C:\\repo\\src\\pet.ts') // 'C:/repo/src/pet.ts'
|
|
239
|
+
*/
|
|
240
|
+
function toPosixPath(filePath) {
|
|
241
|
+
return filePath.replaceAll("\\", "/");
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved
|
|
245
|
+
* to absolute paths first, so relative and `..`-containing inputs compare correctly.
|
|
246
|
+
*
|
|
247
|
+
* Guards a destructive or an out-of-tree operation: before wiping an output directory, check that
|
|
248
|
+
* it does not contain the project root, and before loading a path a caller supplied, check that it
|
|
249
|
+
* did not escape the directory it is allowed to read from.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* isPathInside('./src/gen', '.') // true — nested inside the root
|
|
253
|
+
* isPathInside('.', '.') // true — the same directory counts as inside
|
|
254
|
+
* isPathInside('.', './src/gen') // false — the root is not inside its own output
|
|
255
|
+
* isPathInside('../other', '.') // false — escapes the root
|
|
256
|
+
*/
|
|
257
|
+
function isPathInside(path, parent) {
|
|
258
|
+
const resolvedPath = (0, node_path.resolve)(path);
|
|
259
|
+
const resolvedParent = (0, node_path.resolve)(parent);
|
|
260
|
+
if (resolvedPath === resolvedParent) return true;
|
|
261
|
+
const rel = (0, node_path.relative)(resolvedParent, resolvedPath);
|
|
262
|
+
return rel !== "" && !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel);
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region ../../internals/utils/src/promise.ts
|
|
266
|
+
/**
|
|
267
|
+
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
268
|
+
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
async function inParallel({ items, limit, run }) {
|
|
276
|
+
const queue = items.entries();
|
|
277
|
+
const worker = async () => {
|
|
278
|
+
for (const [index, item] of queue) await run(item, index);
|
|
279
|
+
};
|
|
280
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region ../../internals/utils/src/time.ts
|
|
284
|
+
/**
|
|
285
|
+
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
286
|
+
* Rounds to 2 decimal places for sub-millisecond precision without noise.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* const start = process.hrtime()
|
|
291
|
+
* doWork()
|
|
292
|
+
* getElapsedMs(start) // 42.35
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
function getElapsedMs(hrStart) {
|
|
296
|
+
const [seconds, nanoseconds] = process.hrtime(hrStart);
|
|
297
|
+
const ms = seconds * 1e3 + nanoseconds / 1e6;
|
|
298
|
+
return Math.round(ms * 100) / 100;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* formatMs(250) // '250ms'
|
|
306
|
+
* formatMs(1500) // '1.50s'
|
|
307
|
+
* formatMs(90000) // '1m 30.0s'
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
function formatMs(ms) {
|
|
311
|
+
if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
|
|
312
|
+
if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
|
|
313
|
+
return `${Math.round(ms)}ms`;
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/diagnosticCatalog.ts
|
|
317
|
+
/**
|
|
318
|
+
* Every diagnostic code with its docs entry: a short title, what triggers it, and how to resolve
|
|
319
|
+
* it. The source of truth for {@link diagnosticCode}, and the kubb.dev `/reference/diagnostics`
|
|
320
|
+
* sections mirror it.
|
|
321
|
+
*/
|
|
322
|
+
const diagnosticCatalog = {
|
|
323
|
+
unknown: {
|
|
324
|
+
code: "KUBB_UNKNOWN",
|
|
325
|
+
title: "Unknown error",
|
|
326
|
+
cause: "An error was thrown without a stable Kubb code, so it is reported as-is.",
|
|
327
|
+
fix: "Read the underlying message and stack. If it comes from a plugin or adapter, check its configuration; otherwise report it as a possible Kubb bug."
|
|
328
|
+
},
|
|
329
|
+
inputNotFound: {
|
|
330
|
+
code: "KUBB_INPUT_NOT_FOUND",
|
|
331
|
+
title: "Input not found",
|
|
332
|
+
cause: "The file set as `input` (or passed as `kubb generate PATH`) could not be read. A URL reports `KUBB_INPUT_REQUEST_FAILED` or `KUBB_INPUT_UNREACHABLE` instead.",
|
|
333
|
+
fix: "Check that the path exists and is readable, then set it as `input` or pass it on the CLI."
|
|
334
|
+
},
|
|
335
|
+
inputRequestFailed: {
|
|
336
|
+
code: "KUBB_INPUT_REQUEST_FAILED",
|
|
337
|
+
title: "Input request failed",
|
|
338
|
+
cause: "A URL set as `input` (or reached through a `$ref`) answered with a 4xx or 5xx status instead of the document.",
|
|
339
|
+
fix: "Open the URL to see what the server returns. A 401 or 403 needs credentials Kubb does not send, so download the document and point `input` at the local file. A 404 means the path is wrong, and a 5xx means the server itself failed."
|
|
340
|
+
},
|
|
341
|
+
inputUnreachable: {
|
|
342
|
+
code: "KUBB_INPUT_UNREACHABLE",
|
|
343
|
+
title: "Input unreachable",
|
|
344
|
+
cause: "A URL set as `input` (or reached through a `$ref`) never answered, so the request failed before a status came back. A refused connection, an unknown host, an expired certificate, and a timeout all land here.",
|
|
345
|
+
fix: "Check that the host is running and reachable from this machine. For a local server, start it and confirm the port matches the one in `input`."
|
|
346
|
+
},
|
|
347
|
+
inputRequired: {
|
|
348
|
+
code: "KUBB_INPUT_REQUIRED",
|
|
349
|
+
title: "Input required",
|
|
350
|
+
cause: "An adapter is configured but no `input` was provided.",
|
|
351
|
+
fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config."
|
|
352
|
+
},
|
|
353
|
+
legacyInput: {
|
|
354
|
+
code: "KUBB_LEGACY_INPUT",
|
|
355
|
+
title: "Legacy input shape",
|
|
356
|
+
cause: "`input` is a `{ path }` or `{ data }` wrapper, which v4 used to point at a document and v5 reads as the document itself.",
|
|
357
|
+
fix: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`."
|
|
358
|
+
},
|
|
359
|
+
invalidDocument: {
|
|
360
|
+
code: "KUBB_INVALID_DOCUMENT",
|
|
361
|
+
title: "Invalid document",
|
|
362
|
+
cause: "The `input` cannot be read as an OpenAPI or Swagger document: its JSON or YAML has a syntax error, it declares no `openapi` or `swagger` version field, or its version cannot be upgraded to OpenAPI 3.1.",
|
|
363
|
+
fix: "Fix the syntax at the reported line, and check that `input` points at the spec and not an HTML page. Point `input` at a Swagger 2.0, OpenAPI 3.0, or OpenAPI 3.1 document, and check that a passed object is the spec itself rather than a wrapper around it."
|
|
364
|
+
},
|
|
365
|
+
invalidSpec: {
|
|
366
|
+
code: "KUBB_INVALID_SPEC",
|
|
367
|
+
title: "Invalid spec",
|
|
368
|
+
cause: "The document does not pass OpenAPI schema validation. Kubb still generates from it, but the output can be incomplete or wrong.",
|
|
369
|
+
fix: "Fix the reported problem in the spec. Run `kubb validate` to list every error, or set `validate: false` on the adapter to skip the check."
|
|
370
|
+
},
|
|
371
|
+
refNotFound: {
|
|
372
|
+
code: "KUBB_REF_NOT_FOUND",
|
|
373
|
+
title: "Reference not found",
|
|
374
|
+
cause: "A `$ref` could not be resolved in the source document.",
|
|
375
|
+
fix: "Add the missing definition (for example under `components.schemas`) or fix the `$ref`. Run `kubb validate` to check the spec."
|
|
376
|
+
},
|
|
377
|
+
invalidServerVariable: {
|
|
378
|
+
code: "KUBB_INVALID_SERVER_VARIABLE",
|
|
379
|
+
title: "Invalid server variable",
|
|
380
|
+
cause: "A server variable value is not allowed by its `enum`.",
|
|
381
|
+
fix: "Use one of the values listed in the server variable `enum`, or update the spec."
|
|
382
|
+
},
|
|
383
|
+
pluginNotFound: {
|
|
384
|
+
code: "KUBB_PLUGIN_NOT_FOUND",
|
|
385
|
+
title: "Plugin not found",
|
|
386
|
+
cause: "A plugin that another plugin depends on is missing from the config.",
|
|
387
|
+
fix: "Add the required plugin to the `plugins` array in kubb.config.ts, or remove the dependency on it."
|
|
388
|
+
},
|
|
389
|
+
incompatibleExtension: {
|
|
390
|
+
code: "KUBB_INCOMPATIBLE_EXTENSION",
|
|
391
|
+
title: "Incompatible extension",
|
|
392
|
+
cause: "A plugin sets `meta.compatibility.kubb` or `meta.compatibility.node` to a range the running Kubb or Node.js version does not satisfy.",
|
|
393
|
+
fix: "Upgrade Kubb or Node.js to a version in the range, or install a version of the plugin that supports your current Kubb and Node.js."
|
|
394
|
+
},
|
|
395
|
+
missingDependency: {
|
|
396
|
+
code: "KUBB_MISSING_DEPENDENCY",
|
|
397
|
+
title: "Missing dependency",
|
|
398
|
+
cause: "A plugin lists another plugin in its `dependencies` record without `optional: true`, and the config does not include it.",
|
|
399
|
+
fix: "Add the missing plugin to the `plugins` array in kubb.config.ts."
|
|
400
|
+
},
|
|
401
|
+
incompatibleDependency: {
|
|
402
|
+
code: "KUBB_INCOMPATIBLE_DEPENDENCY",
|
|
403
|
+
title: "Incompatible dependency",
|
|
404
|
+
cause: "A plugin's `dependencies` record sets a `version` range, and the configured plugin's `meta.version` falls outside it.",
|
|
405
|
+
fix: "Install a version of the dependency inside the range, or a version of the dependent plugin that supports the installed dependency."
|
|
406
|
+
},
|
|
407
|
+
pluginFailed: {
|
|
408
|
+
code: "KUBB_PLUGIN_FAILED",
|
|
409
|
+
title: "Plugin failed",
|
|
410
|
+
cause: "A plugin threw while generating, or reported an error through `ctx.error`.",
|
|
411
|
+
fix: "Check the plugin options and the node at `at:`. If it is a bug, report it with the stack at `report:`."
|
|
412
|
+
},
|
|
413
|
+
adapterFailed: {
|
|
414
|
+
code: "KUBB_ADAPTER_FAILED",
|
|
415
|
+
title: "Adapter failed",
|
|
416
|
+
cause: "The adapter threw an unexpected error while parsing the input.",
|
|
417
|
+
fix: "Check the input and the adapter options. If it is a bug, report it with the stack at `report:`."
|
|
418
|
+
},
|
|
419
|
+
parserFailed: {
|
|
420
|
+
code: "KUBB_PARSER_FAILED",
|
|
421
|
+
title: "Parser failed",
|
|
422
|
+
cause: "A parser threw an unexpected error while printing a generated file.",
|
|
423
|
+
fix: "Check the parser options. If it is a bug, report it with the stack at `report:`."
|
|
424
|
+
},
|
|
425
|
+
pluginWarning: {
|
|
426
|
+
code: "KUBB_PLUGIN_WARNING",
|
|
427
|
+
title: "Plugin warning",
|
|
428
|
+
cause: "A plugin reported a non-fatal warning through `ctx.warn`.",
|
|
429
|
+
fix: "Review the message. It does not fail the build; adjust the plugin options or input if the warning is unwanted."
|
|
430
|
+
},
|
|
431
|
+
pluginInfo: {
|
|
432
|
+
code: "KUBB_PLUGIN_INFO",
|
|
433
|
+
title: "Plugin info",
|
|
434
|
+
cause: "A plugin reported an informational message through `ctx.info`.",
|
|
435
|
+
fix: "Informational only. No action is required."
|
|
436
|
+
},
|
|
437
|
+
noContext: {
|
|
438
|
+
code: "KUBB_NO_CONTEXT",
|
|
439
|
+
title: "No plugin context",
|
|
440
|
+
cause: "A `kubb/kit` composable such as `useKubb()` or `addGenerator()` ran outside the `setup` and `kubb:plugin:setup` of a plugin, so there is no plugin to apply it to.",
|
|
441
|
+
fix: "Call the composable inside `setup` or `kubb:plugin:setup`, including in code that setup awaits."
|
|
442
|
+
},
|
|
443
|
+
unsupportedFormat: {
|
|
444
|
+
code: "KUBB_UNSUPPORTED_FORMAT",
|
|
445
|
+
title: "Unsupported format",
|
|
446
|
+
cause: "A schema uses a `format` Kubb does not map to a specific type, so it falls back to the base type.",
|
|
447
|
+
fix: "Use a format Kubb supports, or handle the custom format with a parser or plugin."
|
|
448
|
+
},
|
|
449
|
+
deprecated: {
|
|
450
|
+
code: "KUBB_DEPRECATED",
|
|
451
|
+
title: "Deprecated",
|
|
452
|
+
cause: "A referenced schema or operation is marked `deprecated`.",
|
|
453
|
+
fix: "Migrate off the deprecated definition if the warning is unwanted."
|
|
454
|
+
},
|
|
455
|
+
adapterRequired: {
|
|
456
|
+
code: "KUBB_ADAPTER_REQUIRED",
|
|
457
|
+
title: "Adapter required",
|
|
458
|
+
cause: "An action needs an adapter but none is configured.",
|
|
459
|
+
fix: "Set `adapter` in kubb.config.ts, for example `adapterOas()`."
|
|
460
|
+
},
|
|
461
|
+
pathTraversal: {
|
|
462
|
+
code: "KUBB_PATH_TRAVERSAL",
|
|
463
|
+
title: "Path traversal",
|
|
464
|
+
cause: "A resolved output path escaped the output directory, which can stem from a path traversal in the spec or a misconfigured `group.name`.",
|
|
465
|
+
fix: "Keep generated paths within the output directory. Review the `group.name` function and the names coming from the spec."
|
|
466
|
+
},
|
|
467
|
+
cleanRoot: {
|
|
468
|
+
code: "KUBB_CLEAN_ROOT",
|
|
469
|
+
title: "Clean targets the project root",
|
|
470
|
+
cause: "`output.clean` is enabled and `output.path` resolves to the project root or a parent of it, so cleaning would delete `kubb.config` and every source file.",
|
|
471
|
+
fix: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code, or disable `output.clean`."
|
|
472
|
+
},
|
|
473
|
+
invalidPluginOptions: {
|
|
474
|
+
code: "KUBB_INVALID_PLUGIN_OPTIONS",
|
|
475
|
+
title: "Invalid plugin options",
|
|
476
|
+
cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
|
|
477
|
+
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or use `output.mode: 'directory'`."
|
|
478
|
+
},
|
|
479
|
+
postGenerateFailed: {
|
|
480
|
+
code: "KUBB_POST_GENERATE_FAILED",
|
|
481
|
+
title: "Post-generate command failed",
|
|
482
|
+
cause: "A post-generate command (`output.postGenerate`) exited with a non-zero status.",
|
|
483
|
+
fix: "Check the command is installed and correct, and run it manually to see the error."
|
|
484
|
+
},
|
|
485
|
+
formatFailed: {
|
|
486
|
+
code: "KUBB_FORMAT_FAILED",
|
|
487
|
+
title: "Format failed",
|
|
488
|
+
cause: "The formatter pass over the generated files failed.",
|
|
489
|
+
fix: "Check the formatter (oxfmt, biome, or prettier) is installed and its config is valid, then run it manually on the output."
|
|
490
|
+
},
|
|
491
|
+
lintFailed: {
|
|
492
|
+
code: "KUBB_LINT_FAILED",
|
|
493
|
+
title: "Lint failed",
|
|
494
|
+
cause: "The linter pass over the generated files failed.",
|
|
495
|
+
fix: "Check the linter (oxlint, biome, or eslint) is installed and its config is valid, then run it manually on the output."
|
|
496
|
+
},
|
|
497
|
+
barrelDuplicateExport: {
|
|
498
|
+
code: "KUBB_BARREL_DUPLICATE_EXPORT",
|
|
499
|
+
title: "Duplicate barrel export",
|
|
500
|
+
cause: "Two generated modules export the same name, so the barrel cannot re-export both.",
|
|
501
|
+
fix: "Rename one of the colliding declarations, or configure the plugin resolver to produce distinct names."
|
|
502
|
+
},
|
|
503
|
+
internalError: {
|
|
504
|
+
code: "KUBB_INTERNAL_ERROR",
|
|
505
|
+
title: "Internal error",
|
|
506
|
+
cause: "Kubb hit a state it does not expect. This is a bug in Kubb, not in your config.",
|
|
507
|
+
fix: "Rerun with `--reporter json` or `--verbose` to get the stack. Then report it at https://github.com/kubb-labs/kubb/issues with the spec and config that trigger it."
|
|
508
|
+
},
|
|
509
|
+
performance: {
|
|
510
|
+
code: "KUBB_PERFORMANCE",
|
|
511
|
+
title: "Performance",
|
|
512
|
+
cause: "Not a failure. Records a plugin’s elapsed time, summed into the run total.",
|
|
513
|
+
fix: "No action. This is an informational metric."
|
|
514
|
+
},
|
|
515
|
+
updateAvailable: {
|
|
516
|
+
code: "KUBB_UPDATE_AVAILABLE",
|
|
517
|
+
title: "Update available",
|
|
518
|
+
cause: "A newer Kubb version is published on npm than the one running.",
|
|
519
|
+
fix: "Update the `@kubb/*` packages, for example `npm install -g @kubb/cli`, to get the latest fixes."
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Stable codes Kubb attaches to a `Diagnostic`, derived from {@link diagnosticCatalog}. Reference
|
|
524
|
+
* these instead of inlining the string at a throw site.
|
|
525
|
+
*/
|
|
526
|
+
const diagnosticCode = Object.fromEntries(Object.entries(diagnosticCatalog).map(([key, { code }]) => [key, code]));
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/formatDiagnostic.ts
|
|
529
|
+
/** A problem's `help`, or the catalog fix. `info` gets none: its catalog fix says no action is needed. */
|
|
530
|
+
function getHelp(problem) {
|
|
531
|
+
if (problem.help || problem.severity === "info") return problem.help;
|
|
532
|
+
return Diagnostics.explain(problem.code).fix;
|
|
533
|
+
}
|
|
534
|
+
/** The `cause` chain's messages, outermost first, minus those `message` already contains. */
|
|
535
|
+
function getCauses(problem) {
|
|
536
|
+
return getErrorChain(problem.cause).filter((error) => !problem.message.includes(error.message)).map((error) => error.name === "Error" ? error.message : `${error.name}: ${error.message}`);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Accent color per severity, which paints the icon in the `human` layout (red error, yellow
|
|
540
|
+
* warning, blue info). The code itself stays dim.
|
|
541
|
+
*/
|
|
542
|
+
const severityStyle = {
|
|
543
|
+
error: "red",
|
|
544
|
+
warning: "yellow",
|
|
545
|
+
info: "blue"
|
|
546
|
+
};
|
|
547
|
+
const severityIcon = {
|
|
548
|
+
error: "✖",
|
|
549
|
+
warning: "⚠",
|
|
550
|
+
info: "ℹ"
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Codes for a crash, which carry the root cause's stack.
|
|
554
|
+
*/
|
|
555
|
+
const crashCodes = /* @__PURE__ */ new Set([
|
|
556
|
+
diagnosticCode.unknown,
|
|
557
|
+
diagnosticCode.internalError,
|
|
558
|
+
diagnosticCode.pluginFailed,
|
|
559
|
+
diagnosticCode.adapterFailed,
|
|
560
|
+
diagnosticCode.parserFailed
|
|
561
|
+
]);
|
|
562
|
+
/**
|
|
563
|
+
* Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
|
|
564
|
+
* consumers, with the catalog `title`, `cause`, and fix, and the `cause` error as `causes` and
|
|
565
|
+
* `stack`. Absent optional fields are omitted.
|
|
566
|
+
*/
|
|
567
|
+
function serialize(diagnostic) {
|
|
568
|
+
const problem = Diagnostics.isProblem(diagnostic) ? diagnostic : void 0;
|
|
569
|
+
const doc = problem ? Diagnostics.explain(problem.code) : void 0;
|
|
570
|
+
const help = problem ? getHelp(problem) : void 0;
|
|
571
|
+
const causes = problem ? getCauses(problem) : [];
|
|
572
|
+
const stack = problem && crashCodes.has(problem.code) ? getErrorChain(problem.cause).at(-1)?.stack : void 0;
|
|
573
|
+
return {
|
|
574
|
+
code: diagnostic.code,
|
|
575
|
+
severity: diagnostic.severity,
|
|
576
|
+
message: diagnostic.message,
|
|
577
|
+
...doc ? {
|
|
578
|
+
title: doc.title,
|
|
579
|
+
cause: doc.cause
|
|
580
|
+
} : {},
|
|
581
|
+
...problem?.location ? { location: problem.location } : {},
|
|
582
|
+
...help ? { help } : {},
|
|
583
|
+
...problem?.plugin ? { plugin: problem.plugin } : {},
|
|
584
|
+
...problem?.issues ? { issues: problem.issues } : {},
|
|
585
|
+
...causes.length ? { causes } : {},
|
|
586
|
+
...stack ? { stack } : {},
|
|
587
|
+
...diagnostic.code === diagnosticCode.unknown ? {} : { docsUrl: Diagnostics.docsUrl(diagnostic.code) }
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Renders a {@link Diagnostic} as lines: a headline, then indented detail rows. `agent` (the default)
|
|
592
|
+
* prints uncolored labeled rows (`at:`, `why:`, `fix:`, `caused by:`, `stack:` for a crash,
|
|
593
|
+
* `docs:`, `report:`). `human` prints an icon, the bold message, and the code aligned to `width`,
|
|
594
|
+
* with `at`, `fix`, the first cause, and `Learn more` for an error, and one row for a warning.
|
|
595
|
+
* `verbose` adds the full stack.
|
|
596
|
+
*/
|
|
597
|
+
function format(diagnostic, { audience = "agent", verbose = false, width = 0 } = {}) {
|
|
598
|
+
const { code, severity, message } = diagnostic;
|
|
599
|
+
const problem = Diagnostics.isProblem(diagnostic) ? diagnostic : void 0;
|
|
600
|
+
const human = audience === "human";
|
|
601
|
+
const paint = human ? node_util.styleText : (_format, text) => text;
|
|
602
|
+
const [firstLine = "", ...rest] = message.split("\n");
|
|
603
|
+
const pointer = problem?.location && "pointer" in problem.location ? problem.location.pointer : void 0;
|
|
604
|
+
const help = problem ? getHelp(problem) : void 0;
|
|
605
|
+
const causes = problem ? getCauses(problem) : [];
|
|
606
|
+
const crash = problem ? crashCodes.has(problem.code) : false;
|
|
607
|
+
const frames = (problem && (verbose || !human && crash) ? getErrorChain(problem.cause).at(-1)?.stack : void 0)?.split("\n").slice(1, verbose ? void 0 : 4).map((frame) => ` ${paint("dim", frame.trim())}`);
|
|
608
|
+
if (!human) {
|
|
609
|
+
const details = rest.filter((line) => line.trim()).map((line) => ` ${line}`);
|
|
610
|
+
const row = (label, value) => {
|
|
611
|
+
if (value) details.push(` ${label}: ${value}`);
|
|
612
|
+
};
|
|
613
|
+
row("at", pointer);
|
|
614
|
+
if (problem && severity !== "info") row("why", Diagnostics.explain(problem.code).cause);
|
|
615
|
+
row("fix", help);
|
|
616
|
+
for (const cause of causes) row("caused by", cause);
|
|
617
|
+
if (frames?.length) details.push(" stack:", ...frames);
|
|
618
|
+
if (code !== diagnosticCode.unknown) row("docs", Diagnostics.docsUrl(code));
|
|
619
|
+
row("report", problem?.issues);
|
|
620
|
+
return [`${severity} ${code}${problem?.plugin ? ` [${problem.plugin}]` : ""}: ${firstLine}`, ...details];
|
|
621
|
+
}
|
|
622
|
+
const left = `${paint(severityStyle[severity], severityIcon[severity])} ${paint("bold", firstLine)}`;
|
|
623
|
+
const gap = Math.max(2, width - (0, node_util.stripVTControlCharacters)(left).length - code.length);
|
|
624
|
+
const headline = `${left}${" ".repeat(gap)}${paint("dim", code)}`;
|
|
625
|
+
const frame = rest.filter((line) => line.trim()).map((line) => ` ${paint("dim", line)}`);
|
|
626
|
+
const label = (name) => paint("dim", name.length < 4 ? name.padEnd(4) : `${name} `);
|
|
627
|
+
const rows = [["at", pointer && paint("cyan", pointer)], ["fix", help]];
|
|
628
|
+
if (severity !== "error") {
|
|
629
|
+
const first = rows.find(([, value]) => value);
|
|
630
|
+
return [
|
|
631
|
+
headline,
|
|
632
|
+
...frame,
|
|
633
|
+
...first ? [` ${label(first[0])} ${first[1]}`] : []
|
|
634
|
+
];
|
|
635
|
+
}
|
|
636
|
+
rows.push(["caused by", causes[0]], ["report", problem?.issues && paint("cyan", problem.issues)]);
|
|
637
|
+
const details = [...frame, ...rows.flatMap(([name, value]) => value ? [` ${label(name)} ${value}`] : [])];
|
|
638
|
+
if (frames?.length) details.push(` ${paint("dim", "stack")}`, ...frames);
|
|
639
|
+
if (code !== diagnosticCode.unknown) details.push(` ${paint("dim", "↳ Learn more")} ${paint("cyan", Diagnostics.docsUrl(code).replace(/^https:\/\//, ""))}`);
|
|
640
|
+
return [headline, ...details];
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/Diagnostics.ts
|
|
644
|
+
/**
|
|
645
|
+
* Docs major version, derived from the package version so the link tracks the published major.
|
|
646
|
+
*/
|
|
647
|
+
const docsMajor = version.split(".")[0] ?? "5";
|
|
648
|
+
/**
|
|
649
|
+
* Builds a type guard that narrows a {@link Diagnostic} to the variant for `kind`. A diagnostic
|
|
650
|
+
* with no `kind` is treated as a `problem`.
|
|
651
|
+
*/
|
|
652
|
+
function isKind(kind) {
|
|
653
|
+
return (diagnostic) => (diagnostic.kind ?? "problem") === kind;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Returns `true` when the diagnostic is a build {@link ProblemDiagnostic}.
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```ts
|
|
660
|
+
* if (isProblem(diagnostic)) {
|
|
661
|
+
* console.log(diagnostic.location)
|
|
662
|
+
* }
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
const isProblem = isKind("problem");
|
|
666
|
+
/**
|
|
667
|
+
* Returns `true` when the diagnostic is a per-plugin {@link PerformanceDiagnostic}.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* const timings = diagnostics.filter(isPerformance)
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
const isPerformance = isKind("performance");
|
|
675
|
+
/**
|
|
676
|
+
* Returns `true` when the diagnostic is a version-update {@link UpdateDiagnostic}.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* if (isUpdate(diagnostic)) {
|
|
681
|
+
* console.log(diagnostic.latestVersion)
|
|
682
|
+
* }
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
const isUpdate = isKind("update");
|
|
686
|
+
const failedCode = {
|
|
687
|
+
plugin: diagnosticCode.pluginFailed,
|
|
688
|
+
adapter: diagnosticCode.adapterFailed,
|
|
689
|
+
parser: diagnosticCode.parserFailed
|
|
690
|
+
};
|
|
691
|
+
const docsByCode = new Map(Object.values(diagnosticCatalog).map((doc) => [doc.code, doc]));
|
|
692
|
+
const countKey = {
|
|
693
|
+
error: "errors",
|
|
694
|
+
warning: "warnings",
|
|
695
|
+
info: "infos"
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
|
|
699
|
+
* that lets deep code report a diagnostic without threading a callback.
|
|
700
|
+
*
|
|
701
|
+
* The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
|
|
702
|
+
* `Diagnostics.scope` activates it for a run, so anything inside that run (the
|
|
703
|
+
* adapter parse, a generator) reports through `Diagnostics.report` and lands
|
|
704
|
+
* in the same run.
|
|
705
|
+
*/
|
|
706
|
+
var Diagnostics = class Diagnostics {
|
|
707
|
+
static #reporterStorage = new node_async_hooks.AsyncLocalStorage();
|
|
708
|
+
/**
|
|
709
|
+
* The diagnostic code catalog, exposed as `Diagnostics.code` (e.g. `Diagnostics.code.refNotFound`).
|
|
710
|
+
*/
|
|
711
|
+
static code = diagnosticCode;
|
|
712
|
+
/**
|
|
713
|
+
* Type guard for a build {@link ProblemDiagnostic}.
|
|
714
|
+
*/
|
|
715
|
+
static isProblem = isProblem;
|
|
716
|
+
/**
|
|
717
|
+
* Type guard for a version-update {@link UpdateDiagnostic}.
|
|
718
|
+
*/
|
|
719
|
+
static isUpdate = isUpdate;
|
|
720
|
+
/**
|
|
721
|
+
* Type guard for a per-plugin {@link PerformanceDiagnostic}.
|
|
722
|
+
*/
|
|
723
|
+
static isPerformance = isPerformance;
|
|
724
|
+
/**
|
|
725
|
+
* An `Error` that carries a {@link Diagnostic}, so structured problems can flow
|
|
726
|
+
* through the existing throw/catch paths while keeping their code and location.
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* ```ts
|
|
730
|
+
* throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
static Error = class DiagnosticError extends Error {
|
|
734
|
+
diagnostic;
|
|
735
|
+
constructor(diagnostic) {
|
|
736
|
+
super(diagnostic.message, { cause: diagnostic.cause });
|
|
737
|
+
this.name = "DiagnosticError";
|
|
738
|
+
this.diagnostic = diagnostic;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* Structural check for a {@link Diagnostics.Error}, including one thrown from a duplicated
|
|
743
|
+
* `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
|
|
744
|
+
* that carries a `code`.
|
|
745
|
+
*/
|
|
746
|
+
static isError(error) {
|
|
747
|
+
if (error instanceof Diagnostics.Error) return true;
|
|
748
|
+
if (!(error instanceof Error) || error.name !== "DiagnosticError") return false;
|
|
749
|
+
const { diagnostic } = error;
|
|
750
|
+
return typeof diagnostic === "object" && diagnostic !== null && typeof diagnostic.code === "string";
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Runs `fn` with `sink` as the active diagnostic sink for the whole async
|
|
754
|
+
* subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
|
|
755
|
+
*/
|
|
756
|
+
static scope(sink, fn) {
|
|
757
|
+
return Diagnostics.#reporterStorage.run(sink, fn);
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Collects a diagnostic into the active build via the run-scoped sink, without throwing.
|
|
761
|
+
* Returns `true` when a run consumed it, `false` when called outside a {@link Diagnostics.scope}
|
|
762
|
+
* (so callers can fall back to throwing). Use a `warning`/`info` severity for non-fatal issues.
|
|
763
|
+
* For rendering a diagnostic live on the hook bus, use {@link Diagnostics.emit} instead.
|
|
764
|
+
*/
|
|
765
|
+
static report(diagnostic) {
|
|
766
|
+
const sink = Diagnostics.#reporterStorage.getStore();
|
|
767
|
+
if (!sink) return false;
|
|
768
|
+
sink(diagnostic);
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Emits a diagnostic, or any thrown value, on the run's hooks so the loggers render it live.
|
|
773
|
+
* A coded problem or an update goes to `kubb:diagnostic`. An uncoded one goes to `kubb:error`
|
|
774
|
+
* whole, so every wrapper's message, its help, and the stack survive. To collect a diagnostic into
|
|
775
|
+
* the build result from deep in a run, use {@link Diagnostics.report} instead.
|
|
776
|
+
*/
|
|
777
|
+
static async emit(hooks, value) {
|
|
778
|
+
const thrown = value instanceof Error || typeof value?.code !== "string";
|
|
779
|
+
const diagnostic = thrown ? Diagnostics.from(value) : value;
|
|
780
|
+
if (!isProblem(diagnostic) || diagnostic.code !== diagnosticCode.unknown) {
|
|
781
|
+
await hooks.callHook("kubb:diagnostic", { diagnostic });
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
const { cause, help, message } = diagnostic;
|
|
785
|
+
const bare = cause && !help && cause.message === message;
|
|
786
|
+
await hooks.callHook("kubb:error", { error: thrown ? toError(value) : bare ? cause : new Diagnostics.Error(diagnostic) });
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link Diagnostics.Error}
|
|
790
|
+
* keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
|
|
791
|
+
*/
|
|
792
|
+
static from(error) {
|
|
793
|
+
const chain = getErrorChain(error);
|
|
794
|
+
const coded = chain.findLast((current) => Diagnostics.isError(current));
|
|
795
|
+
if (coded) {
|
|
796
|
+
const { diagnostic } = coded;
|
|
797
|
+
return diagnostic.cause || !crashCodes.has(diagnostic.code) ? diagnostic : {
|
|
798
|
+
...diagnostic,
|
|
799
|
+
cause: coded
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
const root = chain.at(-1);
|
|
803
|
+
return {
|
|
804
|
+
code: diagnosticCode.unknown,
|
|
805
|
+
severity: "error",
|
|
806
|
+
message: root ? root.message : getErrorMessage(error),
|
|
807
|
+
cause: root
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Coerces an error thrown by a plugin, adapter, or parser into a diagnostic attributed to it.
|
|
812
|
+
* A structured {@link Diagnostics.Error} keeps its code. Any other error is a crash: it gets the
|
|
813
|
+
* kind's `*_FAILED` code and the extension's `meta.issues` link, so the user reports it to the
|
|
814
|
+
* extension's maintainers instead of to Kubb.
|
|
815
|
+
*/
|
|
816
|
+
static fromExtension(error, { kind, extension }) {
|
|
817
|
+
const diagnostic = Diagnostics.from(error);
|
|
818
|
+
const name = extension.meta?.name ?? extension.name;
|
|
819
|
+
const owner = kind === "plugin" ? { plugin: diagnostic.plugin ?? name } : {};
|
|
820
|
+
const crashed = diagnostic.code === diagnosticCode.unknown && diagnostic.cause?.name !== "AbortError";
|
|
821
|
+
const failed = Object.values(failedCode).includes(diagnostic.code);
|
|
822
|
+
if (!crashed && !failed) return {
|
|
823
|
+
...diagnostic,
|
|
824
|
+
...owner
|
|
825
|
+
};
|
|
826
|
+
const issues = extension.meta?.issues;
|
|
827
|
+
return {
|
|
828
|
+
...diagnostic,
|
|
829
|
+
...owner,
|
|
830
|
+
code: crashed ? failedCode[kind] : diagnostic.code,
|
|
831
|
+
message: crashed && kind !== "plugin" ? `${kind} "${name}" crashed: ${diagnostic.message}` : diagnostic.message,
|
|
832
|
+
...issues ? { issues } : {}
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Builds a per-plugin performance record. Reporters sum these into the run total.
|
|
837
|
+
*/
|
|
838
|
+
static performance({ plugin, duration }) {
|
|
839
|
+
return {
|
|
840
|
+
kind: "performance",
|
|
841
|
+
code: diagnosticCode.performance,
|
|
842
|
+
severity: "info",
|
|
843
|
+
message: `${plugin} generated in ${Math.round(duration)}ms`,
|
|
844
|
+
plugin,
|
|
845
|
+
duration
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Builds the version-update notice shown when a newer Kubb is published on npm.
|
|
850
|
+
*/
|
|
851
|
+
static update({ currentVersion, latestVersion }) {
|
|
852
|
+
return {
|
|
853
|
+
kind: "update",
|
|
854
|
+
code: diagnosticCode.updateAvailable,
|
|
855
|
+
severity: "info",
|
|
856
|
+
message: `Update available: v${currentVersion} → v${latestVersion}. Run \`npm install -g @kubb/cli\` to update.`,
|
|
857
|
+
currentVersion,
|
|
858
|
+
latestVersion
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* True when any diagnostic is an error, the severity that fails a build. Non-error
|
|
863
|
+
* diagnostics are ignored.
|
|
864
|
+
*/
|
|
865
|
+
static hasError(diagnostics) {
|
|
866
|
+
return diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Names of the plugins that failed, deduped, derived from the error diagnostics
|
|
870
|
+
* that carry a `plugin`.
|
|
871
|
+
*/
|
|
872
|
+
static failedPlugins(diagnostics) {
|
|
873
|
+
return [...new Set(diagnostics.flatMap((diagnostic) => diagnostic.severity === "error" && diagnostic.plugin ? [diagnostic.plugin] : []))];
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Counts `problem` diagnostics by severity for the run summary. `performance` and
|
|
877
|
+
* `update` diagnostics are ignored.
|
|
878
|
+
*/
|
|
879
|
+
static count(diagnostics) {
|
|
880
|
+
const counts = {
|
|
881
|
+
errors: 0,
|
|
882
|
+
warnings: 0,
|
|
883
|
+
infos: 0
|
|
884
|
+
};
|
|
885
|
+
for (const diagnostic of diagnostics.filter(isProblem)) counts[countKey[diagnostic.severity]] += 1;
|
|
886
|
+
return counts;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Drops duplicate `problem` diagnostics that share a code, location pointer, and
|
|
890
|
+
* plugin, so the same issue reported across several passes is shown once. Non-problem
|
|
891
|
+
* diagnostics are always kept.
|
|
892
|
+
*/
|
|
893
|
+
static dedupe(diagnostics) {
|
|
894
|
+
const seen = /* @__PURE__ */ new Set();
|
|
895
|
+
const result = [];
|
|
896
|
+
for (const diagnostic of diagnostics) {
|
|
897
|
+
if (!isProblem(diagnostic)) {
|
|
898
|
+
result.push(diagnostic);
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
const pointer = diagnostic.location && "pointer" in diagnostic.location ? diagnostic.location.pointer : "";
|
|
902
|
+
const key = `${diagnostic.code} ${pointer} ${diagnostic.plugin ?? ""}`;
|
|
903
|
+
if (seen.has(key)) continue;
|
|
904
|
+
seen.add(key);
|
|
905
|
+
result.push(diagnostic);
|
|
906
|
+
}
|
|
907
|
+
return result;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Builds the kubb.dev docs URL for a diagnostic code, e.g.
|
|
911
|
+
* `KUBB_REF_NOT_FOUND` → `https://kubb.dev/docs/5.x/reference/diagnostics#kubb-ref-not-found`.
|
|
912
|
+
*/
|
|
913
|
+
static docsUrl(code) {
|
|
914
|
+
const slug = code.toLowerCase().replaceAll("_", "-");
|
|
915
|
+
return `https://kubb.dev/docs/${docsMajor}.x/reference/diagnostics#${slug}`;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* The catalog entry for a code: its title, cause, and fix. Mirrors the kubb.dev
|
|
919
|
+
* `/reference/diagnostics#<slug>` section.
|
|
920
|
+
*/
|
|
921
|
+
static explain(code) {
|
|
922
|
+
return docsByCode.get(code);
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
|
|
926
|
+
* consumers, with the catalog `title`, `cause`, and fix, and the `cause` error as `causes` and
|
|
927
|
+
* `stack`. Absent optional fields are omitted.
|
|
928
|
+
*/
|
|
929
|
+
static serialize = serialize;
|
|
930
|
+
/**
|
|
931
|
+
* Renders a diagnostic as lines for an `agent` (the default) or a `human`. See {@link format}.
|
|
932
|
+
*/
|
|
933
|
+
static format = format;
|
|
934
|
+
};
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/defineExtension.ts
|
|
937
|
+
/**
|
|
938
|
+
* Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
|
|
939
|
+
*/
|
|
940
|
+
function resolveMeta(extension) {
|
|
941
|
+
const { name, meta } = extension;
|
|
942
|
+
if (meta) return meta;
|
|
943
|
+
if (name) return { name };
|
|
944
|
+
const keys = Object.keys(extension);
|
|
945
|
+
throw new Diagnostics.Error({
|
|
946
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
947
|
+
severity: "error",
|
|
948
|
+
message: `An extension has neither \`meta.name\` nor \`name\`. Received keys: ${keys.length ? keys.join(", ") : "none"}.`,
|
|
949
|
+
help: "Set `meta: { name }` on the plugin or parser.",
|
|
950
|
+
location: { kind: "config" }
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Throws `KUBB_INCOMPATIBLE_EXTENSION` when the running Kubb or Node.js version is outside `meta.compatibility`.
|
|
955
|
+
*/
|
|
956
|
+
function checkCompatibility(meta) {
|
|
957
|
+
const checks = [{
|
|
958
|
+
target: "Kubb",
|
|
959
|
+
range: meta.compatibility?.kubb,
|
|
960
|
+
version
|
|
961
|
+
}, {
|
|
962
|
+
target: "Node.js",
|
|
963
|
+
range: meta.compatibility?.node,
|
|
964
|
+
version: process.versions.node
|
|
965
|
+
}];
|
|
966
|
+
for (const { target, range, version } of checks) {
|
|
967
|
+
if (!range || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
|
|
968
|
+
throw new Diagnostics.Error({
|
|
969
|
+
code: Diagnostics.code.incompatibleExtension,
|
|
970
|
+
severity: "error",
|
|
971
|
+
message: `"${meta.name}" requires ${target} ${range}, but ${version} is running.`,
|
|
972
|
+
help: `Use a ${target} version that satisfies ${range}, or a version of "${meta.name}" that supports ${target} ${version}.`,
|
|
973
|
+
location: { kind: "config" },
|
|
974
|
+
plugin: meta.name
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Throws `KUBB_MISSING_DEPENDENCY` for a missing required entry in a `dependencies` record, and
|
|
980
|
+
* `KUBB_INCOMPATIBLE_DEPENDENCY` when an entry's `meta.version` is out of range. Arrays are not checked.
|
|
981
|
+
*/
|
|
982
|
+
function checkDependencies({ name, dependencies, plugins }) {
|
|
983
|
+
if (!dependencies || Array.isArray(dependencies)) return;
|
|
984
|
+
for (const [dependencyName, dependency] of Object.entries(dependencies)) {
|
|
985
|
+
const target = plugins.get(dependencyName);
|
|
986
|
+
if (!target) {
|
|
987
|
+
if (dependency?.optional) continue;
|
|
988
|
+
throw new Diagnostics.Error({
|
|
989
|
+
code: Diagnostics.code.missingDependency,
|
|
990
|
+
severity: "error",
|
|
991
|
+
message: `Plugin "${dependencyName}" is required by "${name}" but not found.`,
|
|
992
|
+
help: `Add "${dependencyName}" to the \`plugins\` array in kubb.config.ts.`,
|
|
993
|
+
location: { kind: "config" },
|
|
994
|
+
plugin: name
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
const range = dependency?.version;
|
|
998
|
+
const version = target.meta?.version;
|
|
999
|
+
if (!range || !version || (0, verkit.satisfies)(version, range, { includePrerelease: true })) continue;
|
|
1000
|
+
throw new Diagnostics.Error({
|
|
1001
|
+
code: Diagnostics.code.incompatibleDependency,
|
|
1002
|
+
severity: "error",
|
|
1003
|
+
message: `"${name}" requires "${dependencyName}" ${range}, but ${version} is configured.`,
|
|
1004
|
+
help: `Install a version of "${dependencyName}" that satisfies ${range}.`,
|
|
1005
|
+
location: { kind: "config" },
|
|
1006
|
+
plugin: name
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
/**
|
|
1011
|
+
* Builds the factory behind `defineExtension`. It passes `{}` when called without options, and carries `kind` and
|
|
1012
|
+
* `meta` so tools can read them without calling it.
|
|
1013
|
+
*
|
|
1014
|
+
* @internal
|
|
1015
|
+
*/
|
|
1016
|
+
function createExtensionFactory({ kind, meta, build }) {
|
|
1017
|
+
return Object.assign((options = {}) => build(options), {
|
|
1018
|
+
kind,
|
|
1019
|
+
meta
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
function defineExtension(definition) {
|
|
1023
|
+
switch (definition.kind) {
|
|
1024
|
+
case "plugin": {
|
|
1025
|
+
const { meta, dependencies, enforce, hooks = {}, setup } = definition;
|
|
1026
|
+
return createExtensionFactory({
|
|
1027
|
+
kind: "plugin",
|
|
1028
|
+
meta,
|
|
1029
|
+
build: (options) => ({
|
|
1030
|
+
name: meta.name,
|
|
1031
|
+
meta,
|
|
1032
|
+
options,
|
|
1033
|
+
dependencies,
|
|
1034
|
+
enforce,
|
|
1035
|
+
hooks,
|
|
1036
|
+
setup
|
|
1037
|
+
})
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
case "adapter": {
|
|
1041
|
+
const { meta, setup, build } = definition;
|
|
1042
|
+
return createExtensionFactory({
|
|
1043
|
+
kind: "adapter",
|
|
1044
|
+
meta,
|
|
1045
|
+
build: (raw) => {
|
|
1046
|
+
const options = setup ? setup(raw) : raw;
|
|
1047
|
+
return Object.assign(build(options), {
|
|
1048
|
+
name: meta.name,
|
|
1049
|
+
meta,
|
|
1050
|
+
options
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
case "parser": {
|
|
1056
|
+
const { meta, build } = definition;
|
|
1057
|
+
return createExtensionFactory({
|
|
1058
|
+
kind: "parser",
|
|
1059
|
+
meta,
|
|
1060
|
+
build: (options) => ({
|
|
1061
|
+
...build(options),
|
|
1062
|
+
name: meta.name,
|
|
1063
|
+
meta,
|
|
1064
|
+
options
|
|
1065
|
+
})
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
//#endregion
|
|
1071
|
+
//#region src/composables.ts
|
|
1072
|
+
const kubbContextKey = Symbol.for("kubb.context");
|
|
1073
|
+
const host = globalThis;
|
|
1074
|
+
/**
|
|
1075
|
+
* Holds the setup context of the plugin whose `setup` or `kubb:plugin:setup` is running. `KubbDriver` sets it for each plugin.
|
|
1076
|
+
*
|
|
1077
|
+
* The store lives on `globalThis`, so the ESM and CommonJS builds of `@kubb/core` share one. A plugin that a
|
|
1078
|
+
* CommonJS config loads would otherwise read an empty store and fail with `KUBB_NO_CONTEXT`.
|
|
1079
|
+
*/
|
|
1080
|
+
const kubbContext = host[kubbContextKey] ??= new node_async_hooks.AsyncLocalStorage();
|
|
1081
|
+
function requireContext(caller) {
|
|
1082
|
+
const ctx = kubbContext.getStore();
|
|
1083
|
+
if (ctx) return ctx;
|
|
1084
|
+
throw new Diagnostics.Error({
|
|
1085
|
+
code: Diagnostics.code.noContext,
|
|
1086
|
+
severity: "error",
|
|
1087
|
+
message: `\`${caller}()\` was called outside a plugin setup.`,
|
|
1088
|
+
help: `Call \`${caller}()\` inside \`setup\` or \`kubb:plugin:setup\`, including in code that setup awaits.`
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Returns the context of the plugin whose `kubb:plugin:setup` is running. It stays available after an `await`.
|
|
1093
|
+
* Throws `KUBB_NO_CONTEXT` outside setup.
|
|
1094
|
+
*/
|
|
1095
|
+
function useKubb() {
|
|
1096
|
+
return requireContext("useKubb");
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Returns the same context as {@link useKubb}, or `undefined` outside `setup` and `kubb:plugin:setup`.
|
|
1100
|
+
*/
|
|
1101
|
+
function tryUseKubb() {
|
|
1102
|
+
return kubbContext.getStore();
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Registers generators on the plugin being set up, like `ctx.addGenerator`.
|
|
1106
|
+
*
|
|
1107
|
+
* @example
|
|
1108
|
+
* `addGenerator(typeGenerator, enumGenerator)`
|
|
1109
|
+
*/
|
|
1110
|
+
function addGenerator(...generators) {
|
|
1111
|
+
requireContext("addGenerator").addGenerator(...generators);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Sets the resolver of the plugin being set up, like `ctx.setResolver`.
|
|
1115
|
+
*/
|
|
1116
|
+
function setResolver(resolver) {
|
|
1117
|
+
requireContext("setResolver").setResolver(resolver);
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Adds a macro to the plugin being set up, like `ctx.addMacro`.
|
|
1121
|
+
*/
|
|
1122
|
+
function addMacro(macro) {
|
|
1123
|
+
requireContext("addMacro").addMacro(macro);
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Replaces the macros of the plugin being set up, like `ctx.setMacros`.
|
|
1127
|
+
*/
|
|
1128
|
+
function setMacros(macros) {
|
|
1129
|
+
requireContext("setMacros").setMacros(macros);
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Adds a raw file to the build output, like `ctx.injectFile`.
|
|
1133
|
+
*/
|
|
1134
|
+
function injectFile(file) {
|
|
1135
|
+
requireContext("injectFile").injectFile(file);
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Returns the options the user passed to the plugin being set up, like `ctx.options`.
|
|
1139
|
+
*/
|
|
1140
|
+
function useOptions() {
|
|
1141
|
+
return requireContext("useOptions").options;
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Sets the resolved options of the plugin being set up, like `ctx.setOptions`.
|
|
1145
|
+
*/
|
|
1146
|
+
function setOptions(options) {
|
|
1147
|
+
requireContext("setOptions").setOptions(options);
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Returns the resolved build configuration, like `ctx.config`.
|
|
1151
|
+
*/
|
|
1152
|
+
function useConfig() {
|
|
1153
|
+
return requireContext("useConfig").config;
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Returns another plugin from the config, typed through `Kubb.PluginRegistry`, like `ctx.requirePlugin`.
|
|
1157
|
+
*/
|
|
1158
|
+
function requirePlugin(name) {
|
|
1159
|
+
return requireContext("requirePlugin").requirePlugin(name);
|
|
1160
|
+
}
|
|
1161
|
+
//#endregion
|
|
1162
|
+
//#region src/definePlugin.ts
|
|
1163
|
+
/**
|
|
1164
|
+
* Merges the `output.mode` default into the output config and validates the combination.
|
|
1165
|
+
* Throws `KUBB_INVALID_PLUGIN_OPTIONS` when `mode: 'file'` is paired with a `group` option,
|
|
1166
|
+
* since a single-file output has nothing to group.
|
|
1167
|
+
*
|
|
1168
|
+
* An omitted `mode` follows the shape of `path`: an extension means a single file, anything
|
|
1169
|
+
* else is a directory. Plugin defaults such as `path: 'types'` name a directory, so they
|
|
1170
|
+
* generate without the caller spelling out `mode`.
|
|
1171
|
+
*/
|
|
1172
|
+
function normalizeOutput({ output, group, pluginName }) {
|
|
1173
|
+
const mode = output.mode ?? (node_path.default.extname(output.path) ? "file" : "directory");
|
|
1174
|
+
if (mode === "file" && group) throw new Diagnostics.Error({
|
|
1175
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
1176
|
+
severity: "error",
|
|
1177
|
+
message: `Plugin "${pluginName}" resolves \`output.mode\` to 'file' but also configures a \`group\` option.`,
|
|
1178
|
+
help: "A single-file output has nothing to group. Remove the `group` option, give `output.path` an extensionless directory name, or set `output.mode: 'directory'` explicitly.",
|
|
1179
|
+
location: { kind: "config" },
|
|
1180
|
+
plugin: pluginName
|
|
1181
|
+
});
|
|
1182
|
+
return {
|
|
1183
|
+
...output,
|
|
1184
|
+
mode
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
/** Throws `KUBB_INVALID_PLUGIN_OPTIONS`, listing the allowed values, when `value` is not one of `allowed`. */
|
|
1188
|
+
function assertPluginOption({ plugin, option, value, allowed }) {
|
|
1189
|
+
if (allowed.includes(value)) return;
|
|
1190
|
+
const format = (item) => typeof item === "string" ? JSON.stringify(item) : String(item);
|
|
1191
|
+
const expected = allowed.map(format).join(", ");
|
|
1192
|
+
throw new Diagnostics.Error({
|
|
1193
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
1194
|
+
severity: "error",
|
|
1195
|
+
message: `Plugin "${plugin}" option \`${option}\` is ${format(value)}, but it must be one of ${expected}.`,
|
|
1196
|
+
help: `Set \`${option}\` to one of ${expected}.`,
|
|
1197
|
+
location: { kind: "config" },
|
|
1198
|
+
plugin
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Defines a plugin from one object and returns a factory that takes the user's options.
|
|
1203
|
+
*
|
|
1204
|
+
* @deprecated Use `defineExtension` with `kind: 'plugin'` instead.
|
|
1205
|
+
*/
|
|
1206
|
+
function definePlugin(definition) {
|
|
1207
|
+
return defineExtension({
|
|
1208
|
+
kind: "plugin",
|
|
1209
|
+
...definition
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
//#endregion
|
|
1213
|
+
//#region src/input.ts
|
|
1214
|
+
/**
|
|
1215
|
+
* Classifies an `input` value so callers branch on it once instead of repeating the checks.
|
|
1216
|
+
*
|
|
1217
|
+
* A non-string is a parsed spec (`object`). A string is `inline` when it holds OpenAPI content,
|
|
1218
|
+
* meaning it starts with `{` or `[`, spans multiple lines, or opens with a YAML `openapi:` or
|
|
1219
|
+
* `swagger:` key. Otherwise a string is a `url` when it parses as one, or a `file` path.
|
|
1220
|
+
*/
|
|
1221
|
+
function getInputKind(input) {
|
|
1222
|
+
if (typeof input !== "string") return "object";
|
|
1223
|
+
const trimmed = input.trimStart();
|
|
1224
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[") || input.includes("\n") || /^(openapi|swagger)\s*:/i.test(trimmed)) return "inline";
|
|
1225
|
+
if (URL.canParse(input)) return "url";
|
|
1226
|
+
return "file";
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* The v4 `input` wrapper keys. v4 typed `input` as `{ path }` or `{ data }`; v5 takes the value
|
|
1230
|
+
* directly, so the wrapper now matches the "already-parsed document" branch and silently yields
|
|
1231
|
+
* an empty build.
|
|
1232
|
+
*/
|
|
1233
|
+
const legacyInputKeys = ["path", "data"];
|
|
1234
|
+
/**
|
|
1235
|
+
* Detects the v4 `{ path }` / `{ data }` wrapper so it fails loudly instead of being read as a
|
|
1236
|
+
* document. A real spec always carries more than these keys, so an object whose keys are drawn
|
|
1237
|
+
* only from them is the old shape rather than a document that happens to have a `path` property.
|
|
1238
|
+
*/
|
|
1239
|
+
function isLegacyInput(input) {
|
|
1240
|
+
if (Array.isArray(input)) return input.some(isLegacyInput);
|
|
1241
|
+
if (typeof input !== "object" || input === null) return false;
|
|
1242
|
+
const keys = Object.keys(input);
|
|
1243
|
+
return keys.length > 0 && keys.every((key) => legacyInputKeys.includes(key));
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Normalizes `config.input` into an `AdapterSource` the adapter can parse.
|
|
1247
|
+
*
|
|
1248
|
+
* A parsed object and inline content become `{ type: 'data' }`; a URL is kept verbatim and a
|
|
1249
|
+
* local path is resolved against `config.root`, both as `{ type: 'path' }`.
|
|
1250
|
+
*/
|
|
1251
|
+
function inputToAdapterSource(config) {
|
|
1252
|
+
const input = config.input;
|
|
1253
|
+
if (input && isLegacyInput(input)) throw new Diagnostics.Error({
|
|
1254
|
+
code: Diagnostics.code.legacyInput,
|
|
1255
|
+
severity: "error",
|
|
1256
|
+
message: "The `input` option uses the v4 `{ path }` / `{ data }` wrapper.",
|
|
1257
|
+
help: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`.",
|
|
1258
|
+
location: { kind: "config" }
|
|
1259
|
+
});
|
|
1260
|
+
if (!input) throw new Diagnostics.Error({
|
|
1261
|
+
code: Diagnostics.code.inputRequired,
|
|
1262
|
+
severity: "error",
|
|
1263
|
+
message: "An adapter is configured without an input.",
|
|
1264
|
+
help: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config.",
|
|
1265
|
+
location: { kind: "config" }
|
|
1266
|
+
});
|
|
1267
|
+
if (typeof input !== "string") return {
|
|
1268
|
+
type: "data",
|
|
1269
|
+
data: input
|
|
1270
|
+
};
|
|
1271
|
+
const kind = getInputKind(input);
|
|
1272
|
+
if (kind === "inline") return {
|
|
1273
|
+
type: "data",
|
|
1274
|
+
data: input
|
|
1275
|
+
};
|
|
1276
|
+
if (kind === "url") return {
|
|
1277
|
+
type: "path",
|
|
1278
|
+
path: input
|
|
1279
|
+
};
|
|
1280
|
+
return {
|
|
1281
|
+
type: "path",
|
|
1282
|
+
path: (0, node_path.resolve)(config.root, input)
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
//#endregion
|
|
1286
|
+
//#region src/Resolver.ts
|
|
1287
|
+
function isNamespace(value) {
|
|
1288
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Shared brand for reaching a resolver's build options. `Resolver.merge` reads this instead of
|
|
1292
|
+
* relying on `instanceof`, which fails when a CommonJS config and the ESM CLI each load their own
|
|
1293
|
+
* copy of `@kubb/core`. `Symbol.for` resolves to one key across those copies, so the options stay
|
|
1294
|
+
* reachable and a `file` override is never dropped.
|
|
1295
|
+
*/
|
|
1296
|
+
const resolverOptions = Symbol.for("@kubb/core/resolver/options");
|
|
1297
|
+
/**
|
|
1298
|
+
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
1299
|
+
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
1300
|
+
* every segment, and joins with `/`.
|
|
1301
|
+
*
|
|
1302
|
+
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
1303
|
+
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
1304
|
+
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
1305
|
+
* absolute path, letting generated files escape the configured output directory.
|
|
1306
|
+
*
|
|
1307
|
+
* @example Nested path from a dotted name
|
|
1308
|
+
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
1309
|
+
*/
|
|
1310
|
+
function toFilePath(name) {
|
|
1311
|
+
return name.split(/\.(?=[a-zA-Z])/).map((part) => camelCase(part)).filter(Boolean).join("/");
|
|
1312
|
+
}
|
|
1313
|
+
/** Throws `KUBB_PATH_TRAVERSAL` when `target` lies outside `parent`; `target === parent` stays allowed. */
|
|
1314
|
+
function assertInside({ target, parent, message, help }) {
|
|
1315
|
+
const parentWithSep = parent.endsWith(node_path.default.sep) ? parent : `${parent}${node_path.default.sep}`;
|
|
1316
|
+
if (target === parent || target.startsWith(parentWithSep)) return;
|
|
1317
|
+
throw new Diagnostics.Error({
|
|
1318
|
+
code: Diagnostics.code.pathTraversal,
|
|
1319
|
+
severity: "error",
|
|
1320
|
+
message,
|
|
1321
|
+
help,
|
|
1322
|
+
location: { kind: "config" }
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Built-in `file.baseName`: casts the identifier with `toFilePath` and appends the extension.
|
|
1327
|
+
*/
|
|
1328
|
+
function toBaseName({ name, extname }) {
|
|
1329
|
+
return `${toFilePath(name)}${extname}`;
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Base constraint for all plugin resolver objects.
|
|
1333
|
+
*
|
|
1334
|
+
* The built-in machinery lives under `default`. Generators call the top-level `name`, `file`,
|
|
1335
|
+
* and `imports`, and a plugin overrides `name` and `file` to set its conventions. Extend with
|
|
1336
|
+
* top-level helpers (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
|
|
1337
|
+
*
|
|
1338
|
+
* @example Top-level helper
|
|
1339
|
+
* ```ts
|
|
1340
|
+
* type MyResolver = Resolver & {
|
|
1341
|
+
* typeName(name: string): string
|
|
1342
|
+
* }
|
|
1343
|
+
* ```
|
|
1344
|
+
*
|
|
1345
|
+
* @example Grouped namespace
|
|
1346
|
+
* ```ts
|
|
1347
|
+
* type MyResolver = Resolver & {
|
|
1348
|
+
* query: {
|
|
1349
|
+
* name(node: OperationNode): string
|
|
1350
|
+
* keyName(node: OperationNode): string
|
|
1351
|
+
* }
|
|
1352
|
+
* }
|
|
1353
|
+
* ```
|
|
1354
|
+
*/
|
|
1355
|
+
var Resolver = class Resolver {
|
|
1356
|
+
static #patternCache = /* @__PURE__ */ new Map();
|
|
1357
|
+
static #optionsCache = /* @__PURE__ */ new WeakMap();
|
|
1358
|
+
pluginName;
|
|
1359
|
+
/** The built-in machinery, untouched by `name`/`file` overrides and built once since the driver reads it per node. */
|
|
1360
|
+
default;
|
|
1361
|
+
#options;
|
|
1362
|
+
#baseName;
|
|
1363
|
+
#filePath;
|
|
1364
|
+
constructor(options) {
|
|
1365
|
+
this.pluginName = options.pluginName;
|
|
1366
|
+
this.#options = options;
|
|
1367
|
+
this.#baseName = options.file?.baseName ? options.file.baseName.bind(this) : toBaseName;
|
|
1368
|
+
this.#filePath = options.file?.path ? options.file.path.bind(this) : void 0;
|
|
1369
|
+
this.default = {
|
|
1370
|
+
name: camelCase,
|
|
1371
|
+
options: this.#resolveOptions.bind(this),
|
|
1372
|
+
path: this.#resolvePath.bind(this),
|
|
1373
|
+
file: this.#resolveFile.bind(this),
|
|
1374
|
+
banner: this.#resolveBanner.bind(this),
|
|
1375
|
+
footer: this.#resolveFooter.bind(this)
|
|
1376
|
+
};
|
|
1377
|
+
this.#apply(options);
|
|
1378
|
+
}
|
|
1379
|
+
/** Exposes the raw build options so `Resolver.merge` can read them across `@kubb/core` copies. */
|
|
1380
|
+
get [resolverOptions]() {
|
|
1381
|
+
return this.#options;
|
|
1382
|
+
}
|
|
1383
|
+
name(name) {
|
|
1384
|
+
return this.default.name(name);
|
|
1385
|
+
}
|
|
1386
|
+
file(options) {
|
|
1387
|
+
return this.#resolveFile(options);
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
|
|
1391
|
+
* order. Each ref's target resolves through `resolveRefName`, so collision- or macro-renamed
|
|
1392
|
+
* schemas (`targetName`) import the emitted name. Names and paths go through the top-level
|
|
1393
|
+
* `name` and `file`, so import entries follow the plugin's conventions, and a per-call
|
|
1394
|
+
* `name` override wins over both.
|
|
1395
|
+
*
|
|
1396
|
+
* The subtree scan runs through `collectImportedRefNames`, which memoizes by node identity, so a
|
|
1397
|
+
* schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
|
|
1398
|
+
* reads the same ref set instead of re-scanning it per plugin.
|
|
1399
|
+
*/
|
|
1400
|
+
imports(options) {
|
|
1401
|
+
const { node, root, output, group, extname = ".ts", name } = options;
|
|
1402
|
+
const resolveName = name ?? ((schemaName) => this.name(schemaName));
|
|
1403
|
+
return (0, _kubb_ast.collectImportedRefNames)(node).map((schemaName) => _kubb_ast.ast.factory.createImport({
|
|
1404
|
+
name: [resolveName(schemaName)],
|
|
1405
|
+
path: this.file({
|
|
1406
|
+
name: schemaName,
|
|
1407
|
+
extname,
|
|
1408
|
+
root,
|
|
1409
|
+
output,
|
|
1410
|
+
group
|
|
1411
|
+
}).path
|
|
1412
|
+
}));
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Folds each `override` over `base`, left to right, and returns a new resolver with helpers
|
|
1416
|
+
* re-bound. Top-level keys replace, and a namespace (or `file`) merges per method, so overriding
|
|
1417
|
+
* `query.name` keeps the base `query.keyName`. The last override wins per key. Used when applying
|
|
1418
|
+
* `setResolver` partial overrides, and to compose shared resolver fragments without spreading each
|
|
1419
|
+
* namespace by hand. Reads a resolver's options through the shared brand rather than `instanceof`,
|
|
1420
|
+
* so a `file` override survives even when `base` and `override` come from different `@kubb/core`
|
|
1421
|
+
* copies.
|
|
1422
|
+
*
|
|
1423
|
+
* @example Fold several partial overrides onto a resolver
|
|
1424
|
+
* ```ts
|
|
1425
|
+
* const resolver = Resolver.merge(defaultResolver, sharedNamingPatch, { name: (name) => name.toUpperCase() })
|
|
1426
|
+
* ```
|
|
1427
|
+
*/
|
|
1428
|
+
static merge(base, ...overrides) {
|
|
1429
|
+
const merged = overrides.reduce((acc, override) => {
|
|
1430
|
+
const patch = resolverOptions in override ? override[resolverOptions] : override;
|
|
1431
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
1432
|
+
if (value === void 0) continue;
|
|
1433
|
+
const current = acc[key];
|
|
1434
|
+
acc[key] = isNamespace(value) && isNamespace(current) ? {
|
|
1435
|
+
...current,
|
|
1436
|
+
...value
|
|
1437
|
+
} : value;
|
|
1438
|
+
}
|
|
1439
|
+
return acc;
|
|
1440
|
+
}, { ...base[resolverOptions] });
|
|
1441
|
+
return new Resolver(merged);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Binds each entry of `options` onto the resolver, so `this.name`, `this.default`, and
|
|
1445
|
+
* `this.file` resolve there for top-level helpers and namespace methods alike. `default`
|
|
1446
|
+
* is skipped so it can't be shadowed.
|
|
1447
|
+
*/
|
|
1448
|
+
#apply(options) {
|
|
1449
|
+
const root = this;
|
|
1450
|
+
const bind = (value) => typeof value === "function" ? value.bind(root) : value;
|
|
1451
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1452
|
+
if (key === "pluginName" || key === "default" || key === "file" || value === void 0) continue;
|
|
1453
|
+
root[key] = isNamespace(value) ? Object.fromEntries(Object.entries(value).map(([method, member]) => [method, bind(member)])) : bind(value);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
static #testPattern(value, pattern) {
|
|
1457
|
+
if (typeof pattern === "string") {
|
|
1458
|
+
let regex = Resolver.#patternCache.get(pattern);
|
|
1459
|
+
regex ??= new RegExp(pattern);
|
|
1460
|
+
Resolver.#patternCache.set(pattern, regex);
|
|
1461
|
+
return regex.test(value);
|
|
1462
|
+
}
|
|
1463
|
+
return value.match(pattern) !== null;
|
|
1464
|
+
}
|
|
1465
|
+
static #matchesOperation(node, { type, pattern }) {
|
|
1466
|
+
if (type === "tag") return node.tags.some((tag) => Resolver.#testPattern(tag, pattern));
|
|
1467
|
+
if (type === "operationId") return Resolver.#testPattern(node.operationId, pattern);
|
|
1468
|
+
if (type === "path") return node.path !== void 0 && Resolver.#testPattern(node.path, pattern);
|
|
1469
|
+
if (type === "method") return node.method !== void 0 && Resolver.#testPattern(node.method.toLowerCase(), pattern);
|
|
1470
|
+
if (type === "contentType") return node.requestBody?.content?.some((c) => Resolver.#testPattern(c.contentType, pattern)) ?? false;
|
|
1471
|
+
return false;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Returns `null` when the filter type doesn't apply to schemas, so include rules built
|
|
1475
|
+
* from operation filters (e.g. `tag`) don't exclude every schema.
|
|
1476
|
+
*/
|
|
1477
|
+
static #matchesSchema(node, { type, pattern }) {
|
|
1478
|
+
if (type === "schemaName") return node.name ? Resolver.#testPattern(node.name, pattern) : false;
|
|
1479
|
+
return null;
|
|
1480
|
+
}
|
|
1481
|
+
static #computeOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1482
|
+
if (node.kind === "Operation") {
|
|
1483
|
+
if (exclude.some((filter) => Resolver.#matchesOperation(node, filter))) return null;
|
|
1484
|
+
if (include && !include.some((filter) => Resolver.#matchesOperation(node, filter))) return null;
|
|
1485
|
+
return {
|
|
1486
|
+
...options,
|
|
1487
|
+
...override.find((filter) => Resolver.#matchesOperation(node, filter))?.options
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
if (node.kind === "Schema") {
|
|
1491
|
+
if (exclude.some((filter) => Resolver.#matchesSchema(node, filter) === true)) return null;
|
|
1492
|
+
if (include) {
|
|
1493
|
+
const applicable = include.map((filter) => Resolver.#matchesSchema(node, filter)).filter((result) => result !== null);
|
|
1494
|
+
if (applicable.length > 0 && !applicable.includes(true)) return null;
|
|
1495
|
+
}
|
|
1496
|
+
return {
|
|
1497
|
+
...options,
|
|
1498
|
+
...override.find((filter) => Resolver.#matchesSchema(node, filter) === true)?.options
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
return options;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Applies include/exclude filters and merges matching override options, caching the result
|
|
1505
|
+
* per `(options, node)` pair. Returns `null` when the node is filtered out.
|
|
1506
|
+
*/
|
|
1507
|
+
#resolveOptions(node, context) {
|
|
1508
|
+
const { options } = context;
|
|
1509
|
+
if (typeof options !== "object" || options === null) return Resolver.#computeOptions(node, context);
|
|
1510
|
+
let byOptions = Resolver.#optionsCache.get(options);
|
|
1511
|
+
if (!byOptions) {
|
|
1512
|
+
byOptions = /* @__PURE__ */ new WeakMap();
|
|
1513
|
+
Resolver.#optionsCache.set(options, byOptions);
|
|
1514
|
+
}
|
|
1515
|
+
const cached = byOptions.get(node);
|
|
1516
|
+
if (cached) return cached.value;
|
|
1517
|
+
const result = Resolver.#computeOptions(node, context);
|
|
1518
|
+
byOptions.set(node, { value: result });
|
|
1519
|
+
return result;
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* A custom `group.name` wins; otherwise `tag` groups use the camelCased tag and `path`
|
|
1523
|
+
* groups use the first non-traversal segment (`''` when none remain, placing the file in
|
|
1524
|
+
* the output root, kept safe by the caller's boundary check).
|
|
1525
|
+
*/
|
|
1526
|
+
static #resolveGroupDir(group, groupValue) {
|
|
1527
|
+
if (group.name) return group.name({ group: groupValue });
|
|
1528
|
+
if (group.type === "tag") return camelCase(groupValue);
|
|
1529
|
+
const segment = groupValue.split("/").filter((part) => part !== "" && part !== "." && part !== "..")[0];
|
|
1530
|
+
return segment ? camelCase(segment) : "";
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* `mode: 'file'` (default) resolves directly to `output.path`. `mode: 'directory'` resolves
|
|
1534
|
+
* to `output.path/{baseName}`, or into a subdirectory when `group` and a `tag`/`path` value
|
|
1535
|
+
* are provided.
|
|
1536
|
+
*/
|
|
1537
|
+
#resolvePath({ baseName, tag, path: groupPath, root, output, group }) {
|
|
1538
|
+
if (output.mode !== "directory") return node_path.default.resolve(root, output.path);
|
|
1539
|
+
const outputDir = node_path.default.resolve(root, output.path);
|
|
1540
|
+
const result = group && (groupPath || tag) ? node_path.default.resolve(outputDir, Resolver.#resolveGroupDir(group, group.type === "path" ? groupPath : tag), baseName) : node_path.default.resolve(outputDir, baseName);
|
|
1541
|
+
assertInside({
|
|
1542
|
+
target: result,
|
|
1543
|
+
parent: outputDir,
|
|
1544
|
+
message: `Resolved path "${result}" is outside the output directory "${outputDir}".`,
|
|
1545
|
+
help: "This can stem from a path traversal in the OpenAPI specification or a misconfigured `group.name` function. Keep generated paths within the output directory."
|
|
1546
|
+
});
|
|
1547
|
+
return result;
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
1551
|
+
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
1552
|
+
* spec-derived values from writing outside the project.
|
|
1553
|
+
*/
|
|
1554
|
+
#resolveOverridePath(filePath, root) {
|
|
1555
|
+
const resolved = node_path.default.resolve(root, filePath);
|
|
1556
|
+
assertInside({
|
|
1557
|
+
target: resolved,
|
|
1558
|
+
parent: root,
|
|
1559
|
+
message: `Resolved path "${resolved}" is outside the project root "${root}".`,
|
|
1560
|
+
help: "A resolver `file.path` must return a path inside the project root."
|
|
1561
|
+
});
|
|
1562
|
+
return resolved;
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Builds a `FileNode`. When `#filePath` (the resolver's `file.path`) is set it owns the whole
|
|
1566
|
+
* path; otherwise the base name (from `#baseName`, the resolver's `file.baseName` or the
|
|
1567
|
+
* built-in `toBaseName`) is placed by the `output.path`/`group` layout. The resolved file starts
|
|
1568
|
+
* with empty `sources`, `imports`, and `exports`, which consumers populate separately.
|
|
1569
|
+
*/
|
|
1570
|
+
#resolveFile(options) {
|
|
1571
|
+
const { name, extname, tag, path: groupPath, root, output, group } = options;
|
|
1572
|
+
const baseName = this.#baseName({
|
|
1573
|
+
name,
|
|
1574
|
+
extname
|
|
1575
|
+
});
|
|
1576
|
+
const filePath = this.#filePath ? this.#resolveOverridePath(this.#filePath({
|
|
1577
|
+
baseName,
|
|
1578
|
+
output
|
|
1579
|
+
}), root) : this.#resolvePath({
|
|
1580
|
+
baseName,
|
|
1581
|
+
tag,
|
|
1582
|
+
path: groupPath,
|
|
1583
|
+
root,
|
|
1584
|
+
output,
|
|
1585
|
+
group
|
|
1586
|
+
});
|
|
1587
|
+
return _kubb_ast.ast.factory.createFile({
|
|
1588
|
+
path: filePath,
|
|
1589
|
+
baseName: node_path.default.basename(filePath),
|
|
1590
|
+
meta: { pluginName: this.pluginName },
|
|
1591
|
+
sources: [],
|
|
1592
|
+
imports: [],
|
|
1593
|
+
exports: []
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Missing fields default to empty/`false` so the `BannerMeta` shape stays stable even when
|
|
1598
|
+
* a caller (e.g. the barrel plugin) has no document metadata.
|
|
1599
|
+
*/
|
|
1600
|
+
static #buildBannerMeta(meta, file) {
|
|
1601
|
+
return {
|
|
1602
|
+
title: meta?.title,
|
|
1603
|
+
description: meta?.description,
|
|
1604
|
+
version: meta?.version,
|
|
1605
|
+
baseURL: meta?.baseURL,
|
|
1606
|
+
circularNames: meta?.circularNames ?? [],
|
|
1607
|
+
enumNames: meta?.enumNames ?? [],
|
|
1608
|
+
filePath: file?.path ?? "",
|
|
1609
|
+
baseName: file?.baseName ?? "",
|
|
1610
|
+
isBarrel: file?.isBarrel ?? false,
|
|
1611
|
+
isAggregation: file?.isAggregation ?? false
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Resolves a user-configured banner/footer value. `undefined` means not configured.
|
|
1616
|
+
*/
|
|
1617
|
+
static #resolveUserText(value, meta, file) {
|
|
1618
|
+
if (typeof value === "function") return value(Resolver.#buildBannerMeta(meta, file));
|
|
1619
|
+
if (typeof value === "string") return value;
|
|
1620
|
+
}
|
|
1621
|
+
static #buildDefaultBanner({ title, version, config }) {
|
|
1622
|
+
const lines = [
|
|
1623
|
+
"/**",
|
|
1624
|
+
"* Generated by Kubb (https://kubb.dev/).",
|
|
1625
|
+
"* Do not edit manually."
|
|
1626
|
+
];
|
|
1627
|
+
if (config.output.defaultBanner !== "simple") {
|
|
1628
|
+
const input = config.input;
|
|
1629
|
+
const source = typeof input === "string" ? getInputKind(input) === "inline" ? "text content" : node_path.default.basename(input) : input ? "text content" : "";
|
|
1630
|
+
if (source) lines.push(`* Source: ${source}`);
|
|
1631
|
+
if (title) lines.push(`* Title: ${title}`);
|
|
1632
|
+
if (version) lines.push(`* OpenAPI spec version: ${version}`);
|
|
1633
|
+
}
|
|
1634
|
+
return `${lines.join("\n")}\n*/\n`;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* A user-supplied `output.banner` overrides the default Kubb notice. When
|
|
1638
|
+
* `config.output.defaultBanner` is `false` and no user banner is set, returns `null`.
|
|
1639
|
+
*/
|
|
1640
|
+
#resolveBanner(meta, { output, config, file }) {
|
|
1641
|
+
const userBanner = Resolver.#resolveUserText(output?.banner, meta, file);
|
|
1642
|
+
if (userBanner !== void 0) return userBanner;
|
|
1643
|
+
if (config.output.defaultBanner === false) return null;
|
|
1644
|
+
return Resolver.#buildDefaultBanner({
|
|
1645
|
+
title: meta?.title,
|
|
1646
|
+
version: meta?.version,
|
|
1647
|
+
config
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
#resolveFooter(meta, { output, file }) {
|
|
1651
|
+
return Resolver.#resolveUserText(output?.footer, meta, file) ?? null;
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
//#endregion
|
|
1655
|
+
//#region src/createResolver.ts
|
|
1656
|
+
/**
|
|
1657
|
+
* Defines a plugin resolver, the object that decides what every generated symbol and file
|
|
1658
|
+
* path is called. Override the top-level `name` and `file` to set the plugin's conventions,
|
|
1659
|
+
* and add your own naming helpers, top-level (`typeName`, …) or grouped in namespaces
|
|
1660
|
+
* (`query`, `schema`, …). Every method reaches sibling helpers and the built-in machinery
|
|
1661
|
+
* through `this.name`, `this.file`, and `this.default`.
|
|
1662
|
+
*
|
|
1663
|
+
* @example Custom identifier casing
|
|
1664
|
+
* ```ts
|
|
1665
|
+
* export const resolverTs = createResolver<PluginTs>({
|
|
1666
|
+
* pluginName: 'plugin-ts',
|
|
1667
|
+
* name(name) {
|
|
1668
|
+
* return ensureValidVarName(pascalCase(name))
|
|
1669
|
+
* },
|
|
1670
|
+
* })
|
|
1671
|
+
* ```
|
|
1672
|
+
*
|
|
1673
|
+
* @example Rename generated files with `file.baseName`
|
|
1674
|
+
* ```ts
|
|
1675
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
1676
|
+
* pluginName: 'plugin-faker',
|
|
1677
|
+
* name(name) {
|
|
1678
|
+
* return camelCase(name, { prefix: 'create' })
|
|
1679
|
+
* },
|
|
1680
|
+
* file: {
|
|
1681
|
+
* baseName({ name, extname }) {
|
|
1682
|
+
* return `${camelCase(name, { prefix: 'create' })}${extname}`
|
|
1683
|
+
* },
|
|
1684
|
+
* },
|
|
1685
|
+
* })
|
|
1686
|
+
* ```
|
|
1687
|
+
*
|
|
1688
|
+
* @example Own the full path with `file.path`
|
|
1689
|
+
* ```ts
|
|
1690
|
+
* export const resolverFaker = createResolver<PluginFaker>({
|
|
1691
|
+
* pluginName: 'plugin-faker',
|
|
1692
|
+
* file: {
|
|
1693
|
+
* path({ baseName, output }) {
|
|
1694
|
+
* return `${output.path}/mocks/${baseName}`
|
|
1695
|
+
* },
|
|
1696
|
+
* },
|
|
1697
|
+
* })
|
|
1698
|
+
* ```
|
|
1699
|
+
*/
|
|
1700
|
+
function createResolver(options) {
|
|
1701
|
+
return new Resolver(options);
|
|
1702
|
+
}
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/usingCtx.js
|
|
1705
|
+
function _usingCtx() {
|
|
1706
|
+
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
1707
|
+
var n = Error();
|
|
1708
|
+
return n.name = "SuppressedError", n.error = r, n.suppressed = e, n;
|
|
1709
|
+
}, e = {}, n = [];
|
|
1710
|
+
function using(r, e) {
|
|
1711
|
+
if (null != e) {
|
|
1712
|
+
if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
1713
|
+
if (r) var o = e[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
1714
|
+
if (void 0 === o && (o = e[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r)) var t = o;
|
|
1715
|
+
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
1716
|
+
t && (o = function o() {
|
|
1717
|
+
try {
|
|
1718
|
+
t.call(e);
|
|
1719
|
+
} catch (r) {
|
|
1720
|
+
return Promise.reject(r);
|
|
1721
|
+
}
|
|
1722
|
+
}), n.push({
|
|
1723
|
+
v: e,
|
|
1724
|
+
d: o,
|
|
1725
|
+
a: r
|
|
1726
|
+
});
|
|
1727
|
+
} else r && n.push({
|
|
1728
|
+
d: e,
|
|
1729
|
+
a: r
|
|
1730
|
+
});
|
|
1731
|
+
return e;
|
|
1732
|
+
}
|
|
1733
|
+
return {
|
|
1734
|
+
e,
|
|
1735
|
+
u: using.bind(null, !1),
|
|
1736
|
+
a: using.bind(null, !0),
|
|
1737
|
+
d: function d() {
|
|
1738
|
+
var o, t = this.e, s = 0;
|
|
1739
|
+
function next() {
|
|
1740
|
+
for (; o = n.pop();) try {
|
|
1741
|
+
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
1742
|
+
if (o.d) {
|
|
1743
|
+
var r = o.d.call(o.v);
|
|
1744
|
+
if (o.a) return s |= 2, Promise.resolve(r).then(next, err);
|
|
1745
|
+
} else s |= 1;
|
|
1746
|
+
} catch (r) {
|
|
1747
|
+
return err(r);
|
|
1748
|
+
}
|
|
1749
|
+
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
1750
|
+
if (t !== e) throw t;
|
|
1751
|
+
}
|
|
1752
|
+
function err(n) {
|
|
1753
|
+
return t = t !== e ? new r(n, t) : n, next();
|
|
1754
|
+
}
|
|
1755
|
+
return next();
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
function joinSources(file) {
|
|
1760
|
+
return file.sources.map((source) => (0, _kubb_ast.extractStringsFromNodes)(source.nodes)).filter(Boolean).join("\n\n");
|
|
1761
|
+
}
|
|
1762
|
+
/** Runs a parser call and turns a crash into a `KUBB_PARSER_FAILED` diagnostic that names the parser. */
|
|
1763
|
+
function runParser(parser, print) {
|
|
1764
|
+
try {
|
|
1765
|
+
return print();
|
|
1766
|
+
} catch (error) {
|
|
1767
|
+
throw new Diagnostics.Error(Diagnostics.fromExtension(error, {
|
|
1768
|
+
kind: "parser",
|
|
1769
|
+
extension: parser
|
|
1770
|
+
}));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Reads a `copy` file and prints it through the parser's `copy` hook, or verbatim with `banner`/`footer` when there is none.
|
|
1775
|
+
*/
|
|
1776
|
+
async function parseCopy(file, parser) {
|
|
1777
|
+
let content;
|
|
1778
|
+
try {
|
|
1779
|
+
content = await (0, node_fs_promises.readFile)(file.copy, "utf8");
|
|
1780
|
+
} catch (err) {
|
|
1781
|
+
throw new Diagnostics.Error({
|
|
1782
|
+
code: Diagnostics.code.pluginFailed,
|
|
1783
|
+
severity: "error",
|
|
1784
|
+
message: `Could not copy file into output: ${file.copy}`,
|
|
1785
|
+
help: "Check that the file a plugin copies into the output exists and is readable.",
|
|
1786
|
+
cause: toError(err)
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
if (parser?.copy) return runParser(parser, () => parser.parse(_kubb_ast.ast.factory.createFile(parser.copy(file, content))));
|
|
1790
|
+
return [
|
|
1791
|
+
file.banner,
|
|
1792
|
+
content,
|
|
1793
|
+
file.footer
|
|
1794
|
+
].filter((segment) => Boolean(segment)).map((segment) => segment.trimEnd()).join("\n");
|
|
1795
|
+
}
|
|
1796
|
+
function mergeFile(a, b) {
|
|
1797
|
+
return {
|
|
1798
|
+
...a,
|
|
1799
|
+
banner: b.banner,
|
|
1800
|
+
footer: b.footer,
|
|
1801
|
+
copy: b.copy ?? a.copy,
|
|
1802
|
+
sources: a.sources.length ? b.sources.length ? [...a.sources, ...b.sources] : a.sources : b.sources,
|
|
1803
|
+
imports: a.imports.length ? b.imports.length ? [...a.imports, ...b.imports] : a.imports : b.imports,
|
|
1804
|
+
exports: a.exports.length ? b.exports.length ? [...a.exports, ...b.exports] : a.exports : b.exports
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1807
|
+
function isIndexPath(path) {
|
|
1808
|
+
return path.endsWith("/index.ts") || path === "index.ts";
|
|
1809
|
+
}
|
|
1810
|
+
function compareFiles(a, b) {
|
|
1811
|
+
return a.path.length - b.path.length || Number(isIndexPath(a.path)) - Number(isIndexPath(b.path));
|
|
1812
|
+
}
|
|
1813
|
+
function isUnchanged({ stored, source, key, manifest }) {
|
|
1814
|
+
if (stored === null) return false;
|
|
1815
|
+
if (matchesStored({
|
|
1816
|
+
stored,
|
|
1817
|
+
source
|
|
1818
|
+
})) return true;
|
|
1819
|
+
return manifest?.isUpToDate({
|
|
1820
|
+
key,
|
|
1821
|
+
source,
|
|
1822
|
+
disk: stored
|
|
1823
|
+
}) ?? false;
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* In-memory file store for generated files, and the writer that turns them into source
|
|
1827
|
+
* strings on `storage`. Files sharing a `path` are merged (sources/imports/exports
|
|
1828
|
+
* concatenated). The `files` getter is sorted by path length (barrel `index.ts` last
|
|
1829
|
+
* within a bucket).
|
|
1830
|
+
*
|
|
1831
|
+
* @example
|
|
1832
|
+
* ```ts
|
|
1833
|
+
* const manager = new FileManager()
|
|
1834
|
+
* manager.upsert(myFile)
|
|
1835
|
+
* manager.files // sorted view
|
|
1836
|
+
* await manager.write(manager.files, { storage: fsStorage() })
|
|
1837
|
+
* ```
|
|
1838
|
+
*/
|
|
1839
|
+
var FileManager = class {
|
|
1840
|
+
#cache = /* @__PURE__ */ new Map();
|
|
1841
|
+
#sorted = null;
|
|
1842
|
+
add(...files) {
|
|
1843
|
+
return this.#store(files, false);
|
|
1844
|
+
}
|
|
1845
|
+
upsert(...files) {
|
|
1846
|
+
return this.#store(files, true);
|
|
1847
|
+
}
|
|
1848
|
+
/** Stores a generator result: a file array is upserted as is, an element renders through `renderer` first, falsy is a no-op. */
|
|
1849
|
+
async dispatch({ result, renderer }) {
|
|
1850
|
+
try {
|
|
1851
|
+
var _usingCtx$1 = _usingCtx();
|
|
1852
|
+
if (!result) return;
|
|
1853
|
+
if (Array.isArray(result)) {
|
|
1854
|
+
this.upsert(...result);
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
if (!renderer) return;
|
|
1858
|
+
const instance = _usingCtx$1.u(renderer());
|
|
1859
|
+
await instance.render(result);
|
|
1860
|
+
this.upsert(...instance.files);
|
|
1861
|
+
} catch (_) {
|
|
1862
|
+
_usingCtx$1.e = _;
|
|
1863
|
+
} finally {
|
|
1864
|
+
_usingCtx$1.d();
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
#store(files, mergeExisting) {
|
|
1868
|
+
const batch = files.length > 1 ? this.#dedupe(files) : files;
|
|
1869
|
+
const resolved = [];
|
|
1870
|
+
for (const file of batch) {
|
|
1871
|
+
const existing = this.#cache.get(file.path);
|
|
1872
|
+
const merged = existing && mergeExisting ? _kubb_ast.ast.factory.createFile(mergeFile(existing, file)) : _kubb_ast.ast.factory.createFile(file);
|
|
1873
|
+
this.#cache.set(merged.path, merged);
|
|
1874
|
+
resolved.push(merged);
|
|
1875
|
+
}
|
|
1876
|
+
if (resolved.length > 0) this.#sorted = null;
|
|
1877
|
+
return resolved;
|
|
1878
|
+
}
|
|
1879
|
+
#dedupe(files) {
|
|
1880
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1881
|
+
for (const file of files) {
|
|
1882
|
+
const prev = seen.get(file.path);
|
|
1883
|
+
seen.set(file.path, prev ? mergeFile(prev, file) : file);
|
|
1884
|
+
}
|
|
1885
|
+
return [...seen.values()];
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Releases all stored files. Called by the core after `kubb:build:end`.
|
|
1889
|
+
*/
|
|
1890
|
+
dispose() {
|
|
1891
|
+
this.#cache.clear();
|
|
1892
|
+
this.#sorted = null;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* All stored files in stable sort order (shortest path first, barrel files
|
|
1896
|
+
* last within a length bucket). Returns a cached view, do not mutate.
|
|
1897
|
+
*/
|
|
1898
|
+
get files() {
|
|
1899
|
+
return this.#sorted ??= [...this.#cache.values()].sort(compareFiles);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Converts a file's AST sources (or its `copy` source) into the final on-disk string.
|
|
1903
|
+
*/
|
|
1904
|
+
async parse(file, { parsers } = {}) {
|
|
1905
|
+
const parser = parsers?.get(file.extname);
|
|
1906
|
+
if (file.copy) return parseCopy(file, parser);
|
|
1907
|
+
if (!parser) return joinSources(file);
|
|
1908
|
+
return runParser(parser, () => parser.parse(file));
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Parses and writes every file through a bounded pool of workers. A small spec runs all its files
|
|
1912
|
+
* at once; a spec with thousands of files keeps at most {@link FILE_CONCURRENCY} parsed sources in
|
|
1913
|
+
* memory rather than holding every source, while still overlapping each file's write with the
|
|
1914
|
+
* next file's parse. Files finish in whatever order they parse, so the update rows are sorted back
|
|
1915
|
+
* into input order before `kubb:files:processing:update` fires once with the whole batch.
|
|
1916
|
+
*
|
|
1917
|
+
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
1918
|
+
* writes nothing and leaves every mtime where it was.
|
|
1919
|
+
*/
|
|
1920
|
+
async write(files, { storage, parsers, manifest, signal, hooks, config }) {
|
|
1921
|
+
if (files.length === 0) return;
|
|
1922
|
+
await hooks?.callHook("kubb:files:processing:start", { files });
|
|
1923
|
+
const total = files.length;
|
|
1924
|
+
const updates = [];
|
|
1925
|
+
await inParallel({
|
|
1926
|
+
items: files,
|
|
1927
|
+
limit: 50,
|
|
1928
|
+
run: async (file, index) => {
|
|
1929
|
+
signal?.throwIfAborted();
|
|
1930
|
+
const source = await this.parse(file, { parsers });
|
|
1931
|
+
if (config) updates.push({
|
|
1932
|
+
file,
|
|
1933
|
+
processed: index + 1,
|
|
1934
|
+
total,
|
|
1935
|
+
percentage: (index + 1) / total * 100,
|
|
1936
|
+
config
|
|
1937
|
+
});
|
|
1938
|
+
if (!source) return;
|
|
1939
|
+
signal?.throwIfAborted();
|
|
1940
|
+
const stored = await storage.readItem(file.path);
|
|
1941
|
+
if (isUnchanged({
|
|
1942
|
+
stored,
|
|
1943
|
+
source,
|
|
1944
|
+
key: file.path,
|
|
1945
|
+
manifest
|
|
1946
|
+
})) return;
|
|
1947
|
+
signal?.throwIfAborted();
|
|
1948
|
+
await storage.writeItem(file.path, source, { stored });
|
|
1949
|
+
manifest?.track({
|
|
1950
|
+
key: file.path,
|
|
1951
|
+
source
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
updates.sort((a, b) => a.processed - b.processed);
|
|
1956
|
+
await hooks?.callHook("kubb:files:processing:update", { files: updates });
|
|
1957
|
+
await hooks?.callHook("kubb:files:processing:end", { files });
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
//#endregion
|
|
1961
|
+
//#region src/nodeCache.ts
|
|
1962
|
+
/**
|
|
1963
|
+
* Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate
|
|
1964
|
+
* walk.
|
|
1965
|
+
*/
|
|
1966
|
+
function createNodeCache() {
|
|
1967
|
+
const store = /* @__PURE__ */ new Map();
|
|
1968
|
+
return {
|
|
1969
|
+
readItem(key) {
|
|
1970
|
+
return store.get(key);
|
|
1971
|
+
},
|
|
1972
|
+
writeItem(key, value) {
|
|
1973
|
+
store.set(key, value);
|
|
1974
|
+
return value;
|
|
1975
|
+
},
|
|
1976
|
+
ensureItem(key, factory) {
|
|
1977
|
+
if (store.has(key)) return store.get(key);
|
|
1978
|
+
const value = factory();
|
|
1979
|
+
store.set(key, value);
|
|
1980
|
+
return value;
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
//#endregion
|
|
1985
|
+
//#region src/KubbDriver.ts
|
|
1986
|
+
const ENFORCE_ORDER = {
|
|
1987
|
+
pre: -1,
|
|
1988
|
+
post: 1
|
|
1989
|
+
};
|
|
1990
|
+
/** `include` filter types that select operations, and so prune the schemas they do not reach. */
|
|
1991
|
+
const OPERATION_FILTER_TYPES = /* @__PURE__ */ new Set([
|
|
1992
|
+
"tag",
|
|
1993
|
+
"operationId",
|
|
1994
|
+
"path",
|
|
1995
|
+
"method",
|
|
1996
|
+
"contentType"
|
|
1997
|
+
]);
|
|
1998
|
+
const enforceWeight = (plugin) => plugin.enforce ? ENFORCE_ORDER[plugin.enforce] : 0;
|
|
1999
|
+
/**
|
|
2000
|
+
* The options bag a `NormalizedPlugin` starts with before a plugin refines it: a directory output
|
|
2001
|
+
* at the plugin root and empty filter lists.
|
|
2002
|
+
*/
|
|
2003
|
+
const defaultPluginOptions = () => ({
|
|
2004
|
+
output: {
|
|
2005
|
+
path: ".",
|
|
2006
|
+
mode: "directory"
|
|
2007
|
+
},
|
|
2008
|
+
exclude: [],
|
|
2009
|
+
override: []
|
|
2010
|
+
});
|
|
2011
|
+
/**
|
|
2012
|
+
* Fills in the `output`, `exclude`, and `override` a `NormalizedPlugin` needs from a plugin's raw
|
|
2013
|
+
* options, running `output` through `normalizeOutput`. Idempotent, so the driver can apply it after
|
|
2014
|
+
* `setOptions` has already run without disturbing an already-normalized bag.
|
|
2015
|
+
*/
|
|
2016
|
+
function normalizePluginOptions(rawOptions, pluginName) {
|
|
2017
|
+
const options = {
|
|
2018
|
+
...defaultPluginOptions(),
|
|
2019
|
+
...rawOptions ?? {}
|
|
2020
|
+
};
|
|
2021
|
+
const group = "group" in options ? options.group : void 0;
|
|
2022
|
+
options.output = normalizeOutput({
|
|
2023
|
+
output: options.output,
|
|
2024
|
+
group,
|
|
2025
|
+
pluginName
|
|
2026
|
+
});
|
|
2027
|
+
return options;
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* Throws `KUBB_INVALID_PLUGIN_OPTIONS` when a `plugins` entry is not a plugin object, such as a
|
|
2031
|
+
* factory passed without calling it.
|
|
2032
|
+
*/
|
|
2033
|
+
function assertPluginEntry(entry, index) {
|
|
2034
|
+
if (typeof entry === "function") {
|
|
2035
|
+
const name = entry.name || "pluginName";
|
|
2036
|
+
throw new Diagnostics.Error({
|
|
2037
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
2038
|
+
severity: "error",
|
|
2039
|
+
message: `plugins[${index}] is a function ("${name}"), not a plugin.`,
|
|
2040
|
+
help: `Call it: ${name}()`,
|
|
2041
|
+
location: { kind: "config" }
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
2044
|
+
if (typeof entry !== "object" || entry === null) throw new Diagnostics.Error({
|
|
2045
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
2046
|
+
severity: "error",
|
|
2047
|
+
message: `plugins[${index}] is ${entry === null ? "null" : typeof entry}, not a plugin.`,
|
|
2048
|
+
help: "Pass the result of a plugin factory, for example `pluginTs()`, or remove the entry.",
|
|
2049
|
+
location: { kind: "config" }
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Where a generator crashed: a label naming the node and, when the node has one, a JSON pointer
|
|
2054
|
+
* to it. Built from the node fields so core stays adapter-agnostic.
|
|
2055
|
+
*/
|
|
2056
|
+
function getCrashSite(node) {
|
|
2057
|
+
if (node.kind === "Schema") return node.name ? {
|
|
2058
|
+
label: `schema "${node.name}"`,
|
|
2059
|
+
location: {
|
|
2060
|
+
kind: "schema",
|
|
2061
|
+
pointer: `#/components/schemas/${escapePointerToken(node.name)}`
|
|
2062
|
+
}
|
|
2063
|
+
} : { label: "an inline schema" };
|
|
2064
|
+
if (!node.method || !node.path) return { label: `operation "${node.operationId}"` };
|
|
2065
|
+
return {
|
|
2066
|
+
label: `operation "${node.operationId}" (${node.method.toUpperCase()} ${node.path})`,
|
|
2067
|
+
location: {
|
|
2068
|
+
kind: "operation",
|
|
2069
|
+
pointer: `#/paths/${escapePointerToken(node.path)}/${node.method.toLowerCase()}`
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
}
|
|
2073
|
+
var KubbDriver = class {
|
|
2074
|
+
config;
|
|
2075
|
+
options;
|
|
2076
|
+
/**
|
|
2077
|
+
* The `InputNode` produced by the adapter. Set after adapter setup.
|
|
2078
|
+
*/
|
|
2079
|
+
inputNode = null;
|
|
2080
|
+
adapter = null;
|
|
2081
|
+
/**
|
|
2082
|
+
* Raw adapter source so `adapter.parse()` can run lazily.
|
|
2083
|
+
* Intentionally outlives the build, cleared by `dispose()`.
|
|
2084
|
+
*/
|
|
2085
|
+
#adapterSource = null;
|
|
2086
|
+
/**
|
|
2087
|
+
* Central file store for all generated files.
|
|
2088
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
2089
|
+
* add files. This property gives direct read/write access when needed.
|
|
2090
|
+
*/
|
|
2091
|
+
fileManager = new FileManager();
|
|
2092
|
+
plugins = /* @__PURE__ */ new Map();
|
|
2093
|
+
/**
|
|
2094
|
+
* Removers for every listener the driver added (plugin, generator) so `dispose()` can detach
|
|
2095
|
+
* them in one pass. External `hooks.hook(...)` listeners are not tracked.
|
|
2096
|
+
*/
|
|
2097
|
+
#unhooks = [];
|
|
2098
|
+
constructor(config, options) {
|
|
2099
|
+
this.config = config;
|
|
2100
|
+
this.options = options;
|
|
2101
|
+
this.adapter = config.adapter ?? null;
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Checks the adapter's and parsers' `meta.compatibility`, then normalizes and checks every configured plugin, orders them, and registers their lifecycle handlers.
|
|
2105
|
+
* A plugin that another lists as a dependency runs first, then `enforce: 'pre'` before
|
|
2106
|
+
* `'post'`. When the config has an adapter, the adapter source is resolved from the input
|
|
2107
|
+
* so `run` can parse it later.
|
|
2108
|
+
*/
|
|
2109
|
+
async setup() {
|
|
2110
|
+
this.options.signal?.throwIfAborted();
|
|
2111
|
+
for (const extension of [this.config.adapter, ...this.config.parsers]) if (extension?.meta) checkCompatibility(extension.meta);
|
|
2112
|
+
const names = /* @__PURE__ */ new Set();
|
|
2113
|
+
const normalized = this.#sortPlugins(this.config.plugins.map((rawPlugin, index) => {
|
|
2114
|
+
assertPluginEntry(rawPlugin, index);
|
|
2115
|
+
if (rawPlugin.meta) checkCompatibility(rawPlugin.meta);
|
|
2116
|
+
const meta = resolveMeta(rawPlugin);
|
|
2117
|
+
if (names.has(meta.name)) throw new Diagnostics.Error({
|
|
2118
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
2119
|
+
severity: "error",
|
|
2120
|
+
message: `Plugin "${meta.name}" appears twice in \`plugins\`.`,
|
|
2121
|
+
help: "Remove the duplicate, or merge its options.",
|
|
2122
|
+
location: { kind: "config" }
|
|
2123
|
+
});
|
|
2124
|
+
names.add(meta.name);
|
|
2125
|
+
return {
|
|
2126
|
+
name: meta.name,
|
|
2127
|
+
meta,
|
|
2128
|
+
dependencies: typeof rawPlugin.dependencies === "function" ? rawPlugin.dependencies(rawPlugin.options ?? {}, { config: this.config }) : rawPlugin.dependencies,
|
|
2129
|
+
enforce: rawPlugin.enforce,
|
|
2130
|
+
hooks: rawPlugin.hooks,
|
|
2131
|
+
setup: rawPlugin.setup,
|
|
2132
|
+
options: rawPlugin.options ?? defaultPluginOptions(),
|
|
2133
|
+
resolver: createResolver({ pluginName: meta.name })
|
|
2134
|
+
};
|
|
2135
|
+
}));
|
|
2136
|
+
const byName = new Map(normalized.map((plugin) => [plugin.name, plugin]));
|
|
2137
|
+
for (const plugin of normalized) checkDependencies({
|
|
2138
|
+
name: plugin.name,
|
|
2139
|
+
dependencies: plugin.dependencies,
|
|
2140
|
+
plugins: byName
|
|
2141
|
+
});
|
|
2142
|
+
for (const plugin of normalized) {
|
|
2143
|
+
this.#registerPlugin(plugin);
|
|
2144
|
+
this.plugins.set(plugin.name, plugin);
|
|
2145
|
+
}
|
|
2146
|
+
if (this.config.adapter) this.#adapterSource = inputToAdapterSource(this.config);
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Orders plugins so every dependency runs before its dependents (Kahn's algorithm), with
|
|
2150
|
+
* `enforce` (`'pre'` before normal before `'post'`) and declaration order as tiebreaks.
|
|
2151
|
+
* A pairwise `Array.sort` comparator cannot do this: dependency relations are not transitive
|
|
2152
|
+
* at the comparator level, so a chain where A depends on B and B depends on C could come out
|
|
2153
|
+
* wrong when A and C are never compared directly. Dependencies on plugins missing from the
|
|
2154
|
+
* config are ignored here and surface later through `requirePlugin`.
|
|
2155
|
+
*/
|
|
2156
|
+
#sortPlugins(plugins) {
|
|
2157
|
+
const queue = [...plugins].sort((a, b) => enforceWeight(a) - enforceWeight(b));
|
|
2158
|
+
const names = new Set(queue.map((plugin) => plugin.name));
|
|
2159
|
+
const blockedBy = new Map(queue.map((plugin) => {
|
|
2160
|
+
const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
|
|
2161
|
+
return [plugin.name, new Set(dependencies.filter((name) => names.has(name) && name !== plugin.name))];
|
|
2162
|
+
}));
|
|
2163
|
+
const sorted = [];
|
|
2164
|
+
for (const _ of plugins) {
|
|
2165
|
+
const index = queue.findIndex((plugin) => blockedBy.get(plugin.name)?.size === 0);
|
|
2166
|
+
if (index === -1) throw new Diagnostics.Error({
|
|
2167
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
2168
|
+
severity: "error",
|
|
2169
|
+
message: `Plugin dependencies form a cycle: ${queue.map((plugin) => plugin.name).join(" → ")}.`,
|
|
2170
|
+
help: "Remove one of the `dependencies` entries so the plugins can be ordered.",
|
|
2171
|
+
location: { kind: "config" }
|
|
2172
|
+
});
|
|
2173
|
+
const [plugin] = queue.splice(index, 1);
|
|
2174
|
+
if (!plugin) break;
|
|
2175
|
+
sorted.push(plugin);
|
|
2176
|
+
for (const blockers of blockedBy.values()) blockers.delete(plugin.name);
|
|
2177
|
+
}
|
|
2178
|
+
return sorted;
|
|
2179
|
+
}
|
|
2180
|
+
get hooks() {
|
|
2181
|
+
return this.options.hooks;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Parses the adapter source into `this.inputNode`. Idempotent, so repeated calls from
|
|
2185
|
+
* `run` do not re-parse.
|
|
2186
|
+
*/
|
|
2187
|
+
async #parseInput() {
|
|
2188
|
+
if (this.inputNode || !this.adapter || !this.#adapterSource) return;
|
|
2189
|
+
this.options.signal?.throwIfAborted();
|
|
2190
|
+
try {
|
|
2191
|
+
this.inputNode = await this.adapter.parse(this.#adapterSource, { signal: this.options.signal });
|
|
2192
|
+
} catch (caughtError) {
|
|
2193
|
+
throw new Diagnostics.Error(Diagnostics.fromExtension(caughtError, {
|
|
2194
|
+
kind: "adapter",
|
|
2195
|
+
extension: this.adapter
|
|
2196
|
+
}));
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* Registers a plugin's lifecycle hooks on the shared `Hookable` as pass-through listeners that
|
|
2201
|
+
* external tooling can observe via `hooks.hook(...)`. The returned remover is tracked for
|
|
2202
|
+
* `dispose`. `kubb:plugin:setup` is skipped here; `setupHooks` invokes it directly with a
|
|
2203
|
+
* plugin-scoped context.
|
|
2204
|
+
*
|
|
2205
|
+
* @internal
|
|
2206
|
+
*/
|
|
2207
|
+
#registerPlugin(plugin) {
|
|
2208
|
+
const { hooks } = plugin;
|
|
2209
|
+
if (!hooks) return;
|
|
2210
|
+
const { "kubb:plugin:setup": _setup, ...configHooks } = hooks;
|
|
2211
|
+
this.#unhooks.push(this.hooks.addHooks(configHooks));
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* Runs each plugin's `setup` and `kubb:plugin:setup` handler, in plugin order, with a context scoped to that
|
|
2215
|
+
* plugin so `addGenerator`, `setResolver`, `addMacro`, `setMacros`, and `setOptions` target its
|
|
2216
|
+
* `NormalizedPlugin` entry. Called once from `run` before the plugin execution loop begins, so
|
|
2217
|
+
* plugins can configure generators, resolvers, macros, and options before `buildStart`.
|
|
2218
|
+
*/
|
|
2219
|
+
async setupHooks() {
|
|
2220
|
+
for (const plugin of this.plugins.values()) {
|
|
2221
|
+
const setupHook = plugin.hooks?.["kubb:plugin:setup"];
|
|
2222
|
+
if (!plugin.setup && !setupHook) continue;
|
|
2223
|
+
const ctx = {
|
|
2224
|
+
config: this.config,
|
|
2225
|
+
options: plugin.options ?? {},
|
|
2226
|
+
addGenerator: (...generators) => {
|
|
2227
|
+
plugin.generators = [...plugin.generators ?? [], ...generators];
|
|
2228
|
+
},
|
|
2229
|
+
setResolver: (resolver) => {
|
|
2230
|
+
plugin.resolver = Resolver.merge(createResolver({ pluginName: plugin.name }), resolver);
|
|
2231
|
+
},
|
|
2232
|
+
addMacro: (macro) => {
|
|
2233
|
+
plugin.macros = [...plugin.macros ?? [], macro];
|
|
2234
|
+
},
|
|
2235
|
+
setMacros: (macros) => {
|
|
2236
|
+
plugin.macros = [...macros];
|
|
2237
|
+
},
|
|
2238
|
+
setOptions: (opts) => {
|
|
2239
|
+
plugin.options = normalizePluginOptions({
|
|
2240
|
+
...plugin.options,
|
|
2241
|
+
...opts
|
|
2242
|
+
}, plugin.name);
|
|
2243
|
+
},
|
|
2244
|
+
injectFile: (userFileNode) => {
|
|
2245
|
+
this.fileManager.add(_kubb_ast.ast.factory.createFile(userFileNode));
|
|
2246
|
+
},
|
|
2247
|
+
requirePlugin: ((name) => this.requirePlugin(name, { requiredBy: plugin.name }))
|
|
2248
|
+
};
|
|
2249
|
+
try {
|
|
2250
|
+
await kubbContext.run(ctx, async () => {
|
|
2251
|
+
if (plugin.setup) plugin.options = normalizePluginOptions(await plugin.setup(ctx.options, ctx), plugin.name);
|
|
2252
|
+
await setupHook?.(ctx);
|
|
2253
|
+
});
|
|
2254
|
+
} catch (caughtError) {
|
|
2255
|
+
throw new Diagnostics.Error(Diagnostics.fromExtension(caughtError, {
|
|
2256
|
+
kind: "plugin",
|
|
2257
|
+
extension: plugin
|
|
2258
|
+
}));
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Runs the full plugin pipeline. Returns the diagnostics collected so far even
|
|
2264
|
+
* when an outer hook throws, since the orchestrator preserves partial state by capturing
|
|
2265
|
+
* the failure as a {@link Diagnostic} instead of propagating. Each plugin also
|
|
2266
|
+
* contributes a `timing` diagnostic for the run summary.
|
|
2267
|
+
*/
|
|
2268
|
+
async run() {
|
|
2269
|
+
const { hooks, config, fileManager } = this;
|
|
2270
|
+
const diagnostics = [];
|
|
2271
|
+
const parsersMap = /* @__PURE__ */ new Map();
|
|
2272
|
+
for (const parser of config.parsers) if (parser.extNames) for (const ext of parser.extNames) parsersMap.set(ext, parser);
|
|
2273
|
+
return Diagnostics.scope((diagnostic) => diagnostics.push(diagnostic), async () => {
|
|
2274
|
+
try {
|
|
2275
|
+
this.options.signal?.throwIfAborted();
|
|
2276
|
+
const outputRoot = (0, node_path.resolve)(config.root, config.output.path);
|
|
2277
|
+
await this.#parseInput();
|
|
2278
|
+
await this.setupHooks();
|
|
2279
|
+
for (const plugin of this.plugins.values()) {
|
|
2280
|
+
this.options.signal?.throwIfAborted();
|
|
2281
|
+
plugin.options = normalizePluginOptions(plugin.options, plugin.name);
|
|
2282
|
+
}
|
|
2283
|
+
if (this.adapter && this.inputNode) {
|
|
2284
|
+
const buildStartContext = this.#withFiles({
|
|
2285
|
+
config,
|
|
2286
|
+
adapter: this.adapter,
|
|
2287
|
+
meta: this.inputNode.meta,
|
|
2288
|
+
getPlugin: this.getPlugin.bind(this)
|
|
2289
|
+
});
|
|
2290
|
+
await hooks.callHook("kubb:build:start", buildStartContext);
|
|
2291
|
+
}
|
|
2292
|
+
const generatorPlugins = [];
|
|
2293
|
+
for (const plugin of this.plugins.values()) {
|
|
2294
|
+
const context = this.getContext(plugin);
|
|
2295
|
+
const hrStart = process.hrtime();
|
|
2296
|
+
try {
|
|
2297
|
+
await hooks.callHook("kubb:plugin:start", { plugin });
|
|
2298
|
+
} catch (caughtError) {
|
|
2299
|
+
const error = toError(caughtError);
|
|
2300
|
+
const duration = getElapsedMs(hrStart);
|
|
2301
|
+
await this.#emitPluginEnd({
|
|
2302
|
+
plugin,
|
|
2303
|
+
duration,
|
|
2304
|
+
success: false,
|
|
2305
|
+
error
|
|
2306
|
+
});
|
|
2307
|
+
diagnostics.push(Diagnostics.fromExtension(error, {
|
|
2308
|
+
kind: "plugin",
|
|
2309
|
+
extension: plugin
|
|
2310
|
+
}), Diagnostics.performance({
|
|
2311
|
+
plugin: plugin.name,
|
|
2312
|
+
duration
|
|
2313
|
+
}));
|
|
2314
|
+
continue;
|
|
2315
|
+
}
|
|
2316
|
+
if ((plugin.generators?.length ?? 0) > 0) {
|
|
2317
|
+
generatorPlugins.push({
|
|
2318
|
+
plugin,
|
|
2319
|
+
context,
|
|
2320
|
+
hrStart
|
|
2321
|
+
});
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
const duration = getElapsedMs(hrStart);
|
|
2325
|
+
diagnostics.push(Diagnostics.performance({
|
|
2326
|
+
plugin: plugin.name,
|
|
2327
|
+
duration
|
|
2328
|
+
}));
|
|
2329
|
+
await this.#emitPluginEnd({
|
|
2330
|
+
plugin,
|
|
2331
|
+
duration,
|
|
2332
|
+
success: true
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
diagnostics.push(...await this.#runGenerators(generatorPlugins));
|
|
2336
|
+
await hooks.callHook("kubb:plugins:end", this.#withFiles({ config }));
|
|
2337
|
+
if (this.options.cleanPath) await config.storage.empty(this.options.cleanPath);
|
|
2338
|
+
await fileManager.write(fileManager.files, {
|
|
2339
|
+
storage: config.storage,
|
|
2340
|
+
parsers: parsersMap,
|
|
2341
|
+
manifest: this.options.manifest,
|
|
2342
|
+
signal: this.options.signal,
|
|
2343
|
+
hooks,
|
|
2344
|
+
config
|
|
2345
|
+
});
|
|
2346
|
+
await hooks.callHook("kubb:build:end", {
|
|
2347
|
+
files: this.fileManager.files,
|
|
2348
|
+
config,
|
|
2349
|
+
outputDir: outputRoot
|
|
2350
|
+
});
|
|
2351
|
+
return { diagnostics: Diagnostics.dedupe(diagnostics) };
|
|
2352
|
+
} catch (caughtError) {
|
|
2353
|
+
diagnostics.push(Diagnostics.from(caughtError));
|
|
2354
|
+
return { diagnostics: Diagnostics.dedupe(diagnostics) };
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Widens `extra` with the files present at emit time and a bound `upsertFile`, the shape every
|
|
2360
|
+
* file-carrying hook context shares. Building it here in one place keeps the `files` and
|
|
2361
|
+
* `upsertFile` keys from being dropped by a stray spread at the call site.
|
|
2362
|
+
*/
|
|
2363
|
+
#withFiles(extra) {
|
|
2364
|
+
return {
|
|
2365
|
+
...extra,
|
|
2366
|
+
files: this.fileManager.files,
|
|
2367
|
+
upsertFile: (...files) => this.fileManager.upsert(...files)
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
#emitPluginEnd({ plugin, duration, success, error }) {
|
|
2371
|
+
return this.hooks.callHook("kubb:plugin:end", this.#withFiles({
|
|
2372
|
+
plugin,
|
|
2373
|
+
duration,
|
|
2374
|
+
success,
|
|
2375
|
+
...error ? { error } : {},
|
|
2376
|
+
config: this.config
|
|
2377
|
+
}));
|
|
2378
|
+
}
|
|
2379
|
+
/**
|
|
2380
|
+
* Runs schemas and operations through every plugin's generators. The walk is node-outer: each
|
|
2381
|
+
* schema is visited once and each operation once, and the node fans out to the matching
|
|
2382
|
+
* generators of every plugin in dependency order. A per-node cache (`createNodeCache`) is created
|
|
2383
|
+
* once per node and shared by all of that node's plugins, so node-derived work is computed once
|
|
2384
|
+
* and reused instead of recomputed per plugin. Each node still runs through the plugin's macros
|
|
2385
|
+
* and its exclude/include/override filters before that plugin's
|
|
2386
|
+
* generator sees it, so plugins stay isolated. Schemas run before operations so file output
|
|
2387
|
+
* stays deterministic across runs. A generator with a `match` predicate that resolves `false`
|
|
2388
|
+
* for a node is skipped for that node, without calling `schema`/`operation`.
|
|
2389
|
+
*
|
|
2390
|
+
* A failing plugin is dropped from the remaining walk, contributes an error diagnostic, and no
|
|
2391
|
+
* longer aborts the other plugins. `kubb:plugin:end` and each plugin's `timing` diagnostic fire
|
|
2392
|
+
* in dependency order once the walk finishes, driving the CLI's `Plugins N/M` counter. The
|
|
2393
|
+
* `operations` batch fires once per plugin after the single operation walk.
|
|
2394
|
+
*
|
|
2395
|
+
* When `this.inputNode` is `null`, every entry still gets a `kubb:plugin:end` so
|
|
2396
|
+
* post-plugin listeners (the barrel writer and friends) complete.
|
|
2397
|
+
*/
|
|
2398
|
+
async #runGenerators(entries) {
|
|
2399
|
+
const diagnostics = [];
|
|
2400
|
+
if (entries.length === 0) return diagnostics;
|
|
2401
|
+
if (!this.inputNode) {
|
|
2402
|
+
for (const { plugin, hrStart } of entries) {
|
|
2403
|
+
const duration = getElapsedMs(hrStart);
|
|
2404
|
+
diagnostics.push(Diagnostics.performance({
|
|
2405
|
+
plugin: plugin.name,
|
|
2406
|
+
duration
|
|
2407
|
+
}));
|
|
2408
|
+
await this.#emitPluginEnd({
|
|
2409
|
+
plugin,
|
|
2410
|
+
duration,
|
|
2411
|
+
success: true
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
return diagnostics;
|
|
2415
|
+
}
|
|
2416
|
+
const { schemas, operations } = this.inputNode;
|
|
2417
|
+
const allowedSchemaNamesByPlugin = /* @__PURE__ */ new Map();
|
|
2418
|
+
for (const { plugin } of entries) {
|
|
2419
|
+
const { exclude, include, override } = plugin.options;
|
|
2420
|
+
if (!((include?.some(({ type }) => OPERATION_FILTER_TYPES.has(type)) ?? false) && !(include?.some(({ type }) => type === "schemaName") ?? false))) continue;
|
|
2421
|
+
const resolver = this.getResolver(plugin.name);
|
|
2422
|
+
const includedOps = operations.filter((operation) => resolver.default.options(operation, {
|
|
2423
|
+
options: plugin.options,
|
|
2424
|
+
exclude,
|
|
2425
|
+
include,
|
|
2426
|
+
override
|
|
2427
|
+
}) !== null);
|
|
2428
|
+
allowedSchemaNamesByPlugin.set(plugin.name, (0, _kubb_ast.collectUsedSchemaNames)(includedOps, schemas));
|
|
2429
|
+
}
|
|
2430
|
+
const states = entries.map(({ plugin, context, hrStart }) => {
|
|
2431
|
+
const generatorContext = {
|
|
2432
|
+
...context,
|
|
2433
|
+
resolver: this.getResolver(plugin.name)
|
|
2434
|
+
};
|
|
2435
|
+
const { exclude, include, override } = plugin.options;
|
|
2436
|
+
const generators = plugin.generators ?? [];
|
|
2437
|
+
return {
|
|
2438
|
+
plugin,
|
|
2439
|
+
hrStart,
|
|
2440
|
+
generatorContext,
|
|
2441
|
+
exclude,
|
|
2442
|
+
include,
|
|
2443
|
+
override,
|
|
2444
|
+
optionsAreStatic: !exclude?.length && !include?.length && !override?.length,
|
|
2445
|
+
allowedSchemaNames: allowedSchemaNamesByPlugin.get(plugin.name) ?? null,
|
|
2446
|
+
schemaGenerators: generators.filter((generator) => generator.schema),
|
|
2447
|
+
operationGenerators: generators.filter((generator) => generator.operation),
|
|
2448
|
+
operationsGenerators: generators.filter((generator) => generator.operations),
|
|
2449
|
+
pluginOperations: [],
|
|
2450
|
+
error: null,
|
|
2451
|
+
crashSite: void 0
|
|
2452
|
+
};
|
|
2453
|
+
});
|
|
2454
|
+
const resolveForPlugin = (state, node) => {
|
|
2455
|
+
const transformedNode = _kubb_ast.ast.applyMacros(node, state.plugin.macros ?? []);
|
|
2456
|
+
if (state.optionsAreStatic) return {
|
|
2457
|
+
transformedNode,
|
|
2458
|
+
options: state.plugin.options
|
|
2459
|
+
};
|
|
2460
|
+
const options = state.generatorContext.resolver.default.options(transformedNode, {
|
|
2461
|
+
options: state.plugin.options,
|
|
2462
|
+
exclude: state.exclude,
|
|
2463
|
+
include: state.include,
|
|
2464
|
+
override: state.override
|
|
2465
|
+
});
|
|
2466
|
+
if (options === null) return null;
|
|
2467
|
+
return {
|
|
2468
|
+
transformedNode,
|
|
2469
|
+
options
|
|
2470
|
+
};
|
|
2471
|
+
};
|
|
2472
|
+
for (const node of schemas) {
|
|
2473
|
+
const cache = createNodeCache();
|
|
2474
|
+
for (const state of states) {
|
|
2475
|
+
if (state.error || !state.schemaGenerators.length) continue;
|
|
2476
|
+
try {
|
|
2477
|
+
const resolved = resolveForPlugin(state, node);
|
|
2478
|
+
if (!resolved) continue;
|
|
2479
|
+
const { transformedNode, options } = resolved;
|
|
2480
|
+
if (state.allowedSchemaNames !== null && transformedNode.name && !state.allowedSchemaNames.has(transformedNode.name)) continue;
|
|
2481
|
+
const ctx = {
|
|
2482
|
+
...state.generatorContext,
|
|
2483
|
+
options,
|
|
2484
|
+
cache
|
|
2485
|
+
};
|
|
2486
|
+
await this.#dispatchNode({
|
|
2487
|
+
generators: state.schemaGenerators,
|
|
2488
|
+
node: transformedNode,
|
|
2489
|
+
ctx,
|
|
2490
|
+
generate: (generator) => generator.schema(transformedNode, ctx)
|
|
2491
|
+
});
|
|
2492
|
+
await this.hooks.callHook("kubb:generate:schema", transformedNode, ctx);
|
|
2493
|
+
} catch (caughtError) {
|
|
2494
|
+
state.error = toError(caughtError);
|
|
2495
|
+
state.crashSite = getCrashSite(node);
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
for (const node of operations) {
|
|
2500
|
+
const cache = createNodeCache();
|
|
2501
|
+
for (const state of states) {
|
|
2502
|
+
if (state.error || !state.operationGenerators.length && !state.operationsGenerators.length) continue;
|
|
2503
|
+
try {
|
|
2504
|
+
const resolved = resolveForPlugin(state, node);
|
|
2505
|
+
if (!resolved) continue;
|
|
2506
|
+
state.pluginOperations.push(resolved.transformedNode);
|
|
2507
|
+
if (state.operationGenerators.length) {
|
|
2508
|
+
const { transformedNode } = resolved;
|
|
2509
|
+
const ctx = {
|
|
2510
|
+
...state.generatorContext,
|
|
2511
|
+
options: resolved.options,
|
|
2512
|
+
cache
|
|
2513
|
+
};
|
|
2514
|
+
await this.#dispatchNode({
|
|
2515
|
+
generators: state.operationGenerators,
|
|
2516
|
+
node: transformedNode,
|
|
2517
|
+
ctx,
|
|
2518
|
+
generate: (generator) => generator.operation(transformedNode, ctx)
|
|
2519
|
+
});
|
|
2520
|
+
await this.hooks.callHook("kubb:generate:operation", transformedNode, ctx);
|
|
2521
|
+
}
|
|
2522
|
+
} catch (caughtError) {
|
|
2523
|
+
state.error = toError(caughtError);
|
|
2524
|
+
state.crashSite = getCrashSite(node);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
for (const state of states) {
|
|
2529
|
+
if (state.error || !state.operationsGenerators.length) continue;
|
|
2530
|
+
try {
|
|
2531
|
+
const ctx = {
|
|
2532
|
+
...state.generatorContext,
|
|
2533
|
+
options: state.plugin.options,
|
|
2534
|
+
cache: createNodeCache()
|
|
2535
|
+
};
|
|
2536
|
+
for (const generator of state.operationsGenerators) await this.fileManager.dispatch({
|
|
2537
|
+
result: await generator.operations(state.pluginOperations, ctx),
|
|
2538
|
+
renderer: generator.renderer
|
|
2539
|
+
});
|
|
2540
|
+
await this.hooks.callHook("kubb:generate:operations", state.pluginOperations, ctx);
|
|
2541
|
+
} catch (caughtError) {
|
|
2542
|
+
state.error = toError(caughtError);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
for (const state of states) {
|
|
2546
|
+
const duration = getElapsedMs(state.hrStart);
|
|
2547
|
+
await this.#emitPluginEnd({
|
|
2548
|
+
plugin: state.plugin,
|
|
2549
|
+
duration,
|
|
2550
|
+
success: !state.error,
|
|
2551
|
+
error: state.error ?? void 0
|
|
2552
|
+
});
|
|
2553
|
+
if (state.error) {
|
|
2554
|
+
const diagnostic = Diagnostics.fromExtension(state.error, {
|
|
2555
|
+
kind: "plugin",
|
|
2556
|
+
extension: state.plugin
|
|
2557
|
+
});
|
|
2558
|
+
const site = diagnostic.code === Diagnostics.code.pluginFailed && !diagnostic.location ? state.crashSite : void 0;
|
|
2559
|
+
diagnostics.push(site ? {
|
|
2560
|
+
...diagnostic,
|
|
2561
|
+
message: `While generating ${site.label}: ${diagnostic.message}`,
|
|
2562
|
+
...site.location ? { location: site.location } : {}
|
|
2563
|
+
} : diagnostic);
|
|
2564
|
+
}
|
|
2565
|
+
diagnostics.push(Diagnostics.performance({
|
|
2566
|
+
plugin: state.plugin.name,
|
|
2567
|
+
duration
|
|
2568
|
+
}));
|
|
2569
|
+
}
|
|
2570
|
+
return diagnostics;
|
|
2571
|
+
}
|
|
2572
|
+
/** Runs `node` through the generators whose `match` accepts it; `generate` picks the method for the node kind. */
|
|
2573
|
+
async #dispatchNode({ generators, node, ctx, generate }) {
|
|
2574
|
+
for (const generator of generators) {
|
|
2575
|
+
if (!(generator.match ? await generator.match(node, ctx) : true)) continue;
|
|
2576
|
+
await this.fileManager.dispatch({
|
|
2577
|
+
result: await generate(generator),
|
|
2578
|
+
renderer: generator.renderer
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Removes every listener the driver added. Listeners attached directly to `hooks` from outside
|
|
2584
|
+
* the driver survive. Called at the end of a build to prevent leaks across repeated builds.
|
|
2585
|
+
*
|
|
2586
|
+
* @internal
|
|
2587
|
+
*/
|
|
2588
|
+
dispose() {
|
|
2589
|
+
for (const unhook of this.#unhooks) unhook();
|
|
2590
|
+
this.#unhooks.length = 0;
|
|
2591
|
+
this.fileManager.dispose();
|
|
2592
|
+
this.inputNode = null;
|
|
2593
|
+
this.#adapterSource = null;
|
|
2594
|
+
}
|
|
2595
|
+
[Symbol.dispose]() {
|
|
2596
|
+
this.dispose();
|
|
2597
|
+
}
|
|
2598
|
+
getResolver(pluginName) {
|
|
2599
|
+
return this.plugins.get(pluginName)?.resolver ?? createResolver({ pluginName });
|
|
2600
|
+
}
|
|
2601
|
+
getContext(plugin) {
|
|
2602
|
+
const driver = this;
|
|
2603
|
+
const report = (diagnostic) => {
|
|
2604
|
+
Diagnostics.report({
|
|
2605
|
+
...diagnostic,
|
|
2606
|
+
plugin: plugin.name
|
|
2607
|
+
});
|
|
2608
|
+
};
|
|
2609
|
+
return {
|
|
2610
|
+
config: driver.config,
|
|
2611
|
+
signal: driver.options.signal,
|
|
2612
|
+
get root() {
|
|
2613
|
+
return (0, node_path.resolve)(driver.config.root, driver.config.output.path);
|
|
2614
|
+
},
|
|
2615
|
+
hooks: driver.hooks,
|
|
2616
|
+
plugin,
|
|
2617
|
+
getPlugin: driver.getPlugin.bind(driver),
|
|
2618
|
+
requirePlugin: ((name) => driver.requirePlugin(name, { requiredBy: plugin.name })),
|
|
2619
|
+
getResolver: driver.getResolver.bind(driver),
|
|
2620
|
+
driver,
|
|
2621
|
+
addFile: async (...files) => {
|
|
2622
|
+
driver.fileManager.add(...files);
|
|
2623
|
+
},
|
|
2624
|
+
upsertFile: async (...files) => {
|
|
2625
|
+
driver.fileManager.upsert(...files);
|
|
2626
|
+
},
|
|
2627
|
+
get meta() {
|
|
2628
|
+
return driver.inputNode?.meta ?? {
|
|
2629
|
+
circularNames: [],
|
|
2630
|
+
enumNames: []
|
|
2631
|
+
};
|
|
2632
|
+
},
|
|
2633
|
+
get adapter() {
|
|
2634
|
+
return driver.adapter;
|
|
2635
|
+
},
|
|
2636
|
+
get resolver() {
|
|
2637
|
+
return driver.getResolver(plugin.name);
|
|
2638
|
+
},
|
|
2639
|
+
warn(message, options) {
|
|
2640
|
+
report({
|
|
2641
|
+
code: Diagnostics.code.pluginWarning,
|
|
2642
|
+
severity: "warning",
|
|
2643
|
+
message,
|
|
2644
|
+
...options
|
|
2645
|
+
});
|
|
2646
|
+
},
|
|
2647
|
+
error(error, options) {
|
|
2648
|
+
if (Diagnostics.isError(error)) {
|
|
2649
|
+
report({
|
|
2650
|
+
...options,
|
|
2651
|
+
...error.diagnostic
|
|
2652
|
+
});
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
const cause = typeof error === "string" ? void 0 : error;
|
|
2656
|
+
report({
|
|
2657
|
+
code: Diagnostics.code.pluginFailed,
|
|
2658
|
+
severity: "error",
|
|
2659
|
+
message: typeof error === "string" ? error : error.message,
|
|
2660
|
+
cause,
|
|
2661
|
+
...options
|
|
2662
|
+
});
|
|
2663
|
+
},
|
|
2664
|
+
info(message, options) {
|
|
2665
|
+
report({
|
|
2666
|
+
code: Diagnostics.code.pluginInfo,
|
|
2667
|
+
severity: "info",
|
|
2668
|
+
message,
|
|
2669
|
+
...options
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2674
|
+
getPlugin(pluginName) {
|
|
2675
|
+
return this.plugins.get(pluginName);
|
|
2676
|
+
}
|
|
2677
|
+
requirePlugin(pluginName, context) {
|
|
2678
|
+
const plugin = this.getPlugin(pluginName);
|
|
2679
|
+
if (plugin) return plugin;
|
|
2680
|
+
throw pluginNotFoundError({
|
|
2681
|
+
pluginName,
|
|
2682
|
+
requiredBy: context?.requiredBy
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
};
|
|
2686
|
+
/** The `KUBB_PLUGIN_NOT_FOUND` error `requirePlugin` throws, naming the plugin that needed it. */
|
|
2687
|
+
function pluginNotFoundError({ pluginName, requiredBy }) {
|
|
2688
|
+
const by = requiredBy ? ` by "${requiredBy}"` : "";
|
|
2689
|
+
const help = requiredBy ? ` (required by "${requiredBy}")` : "";
|
|
2690
|
+
return new Diagnostics.Error({
|
|
2691
|
+
code: Diagnostics.code.pluginNotFound,
|
|
2692
|
+
severity: "error",
|
|
2693
|
+
message: `Plugin "${pluginName}" is required${by} but not found. Make sure it is included in your Kubb config.`,
|
|
2694
|
+
help: `Add "${pluginName}" to the \`plugins\` array in kubb.config.ts${help}, or remove the dependency on it.`,
|
|
2695
|
+
location: { kind: "config" },
|
|
2696
|
+
...requiredBy ? { plugin: requiredBy } : {}
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
//#endregion
|
|
2700
|
+
//#region src/Hookable.ts
|
|
2701
|
+
/**
|
|
2702
|
+
* Typed hook emitter that awaits all async listeners before resolving.
|
|
2703
|
+
*
|
|
2704
|
+
* @example
|
|
2705
|
+
* ```ts
|
|
2706
|
+
* const hooks = new Hookable<{ build: [name: string] }>()
|
|
2707
|
+
* hooks.hook('build', async (name) => { console.log(name) })
|
|
2708
|
+
* await hooks.callHook('build', 'petstore') // all listeners awaited
|
|
2709
|
+
* ```
|
|
2710
|
+
*/
|
|
2711
|
+
var Hookable = class {
|
|
2712
|
+
#listeners = /* @__PURE__ */ new Map();
|
|
2713
|
+
/**
|
|
2714
|
+
* Calls `hookName` and awaits all registered listeners sequentially.
|
|
2715
|
+
* Throws if any listener rejects, wrapping the cause in an error that names the hook.
|
|
2716
|
+
*
|
|
2717
|
+
* @example
|
|
2718
|
+
* ```ts
|
|
2719
|
+
* await hooks.callHook('build', 'petstore')
|
|
2720
|
+
* ```
|
|
2721
|
+
*/
|
|
2722
|
+
callHook(hookName, ...hookArgs) {
|
|
2723
|
+
const listeners = this.#listeners.get(hookName);
|
|
2724
|
+
if (!listeners?.size) return;
|
|
2725
|
+
return this.#emitAll(hookName, [...listeners], hookArgs);
|
|
2726
|
+
}
|
|
2727
|
+
async #emitAll(hookName, listeners, hookArgs) {
|
|
2728
|
+
for (const listener of listeners) try {
|
|
2729
|
+
await listener(...hookArgs);
|
|
2730
|
+
} catch (err) {
|
|
2731
|
+
throw new Error(`Error in async listener for "${hookName}"`, { cause: toError(err) });
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
/**
|
|
2735
|
+
* Registers a persistent listener for `hookName` and returns a function that removes it.
|
|
2736
|
+
*
|
|
2737
|
+
* @example
|
|
2738
|
+
* ```ts
|
|
2739
|
+
* const unhook = hooks.hook('build', async (name) => { console.log(name) })
|
|
2740
|
+
* unhook() // removes it
|
|
2741
|
+
* ```
|
|
2742
|
+
*/
|
|
2743
|
+
hook(hookName, handler) {
|
|
2744
|
+
let listeners = this.#listeners.get(hookName);
|
|
2745
|
+
if (!listeners) this.#listeners.set(hookName, listeners = /* @__PURE__ */ new Set());
|
|
2746
|
+
listeners.add(handler);
|
|
2747
|
+
return () => this.removeHook(hookName, handler);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* Registers every handler in `configHooks` at once and returns a function that removes them
|
|
2751
|
+
* all. Undefined entries are skipped, so a partial hook object registers only its present keys.
|
|
2752
|
+
*
|
|
2753
|
+
* @example
|
|
2754
|
+
* ```ts
|
|
2755
|
+
* const unhook = hooks.addHooks({ build: onBuild, done: onDone })
|
|
2756
|
+
* unhook() // removes both
|
|
2757
|
+
* ```
|
|
2758
|
+
*/
|
|
2759
|
+
addHooks(configHooks) {
|
|
2760
|
+
const unhooks = Object.keys(configHooks).filter((name) => configHooks[name]).map((name) => this.hook(name, configHooks[name]));
|
|
2761
|
+
return () => {
|
|
2762
|
+
for (const unhook of unhooks) unhook();
|
|
2763
|
+
};
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Removes a previously registered listener.
|
|
2767
|
+
*
|
|
2768
|
+
* @example
|
|
2769
|
+
* ```ts
|
|
2770
|
+
* hooks.removeHook('build', handler)
|
|
2771
|
+
* ```
|
|
2772
|
+
*/
|
|
2773
|
+
removeHook(hookName, handler) {
|
|
2774
|
+
this.#listeners.get(hookName)?.delete(handler);
|
|
2775
|
+
}
|
|
2776
|
+
/**
|
|
2777
|
+
* Returns the number of listeners registered for `hookName`.
|
|
2778
|
+
*
|
|
2779
|
+
* @example
|
|
2780
|
+
* ```ts
|
|
2781
|
+
* hooks.hook('build', handler)
|
|
2782
|
+
* hooks.listenerCount('build') // 1
|
|
2783
|
+
* ```
|
|
2784
|
+
*/
|
|
2785
|
+
listenerCount(hookName) {
|
|
2786
|
+
return this.#listeners.get(hookName)?.size ?? 0;
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
|
|
2790
|
+
*
|
|
2791
|
+
* @deprecated There is no listener ceiling anymore.
|
|
2792
|
+
*/
|
|
2793
|
+
setMaxListeners(_max) {}
|
|
2794
|
+
/**
|
|
2795
|
+
* Removes all listeners from every hook channel.
|
|
2796
|
+
*
|
|
2797
|
+
* @example
|
|
2798
|
+
* ```ts
|
|
2799
|
+
* hooks.removeAllHooks()
|
|
2800
|
+
* ```
|
|
2801
|
+
*/
|
|
2802
|
+
removeAllHooks() {
|
|
2803
|
+
this.#listeners.clear();
|
|
2804
|
+
}
|
|
2805
|
+
};
|
|
2806
|
+
//#endregion
|
|
2807
|
+
Object.defineProperty(exports, "Diagnostics", {
|
|
2808
|
+
enumerable: true,
|
|
2809
|
+
get: function() {
|
|
2810
|
+
return Diagnostics;
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
Object.defineProperty(exports, "FileManager", {
|
|
2814
|
+
enumerable: true,
|
|
2815
|
+
get: function() {
|
|
2816
|
+
return FileManager;
|
|
2817
|
+
}
|
|
2818
|
+
});
|
|
2819
|
+
Object.defineProperty(exports, "Hookable", {
|
|
2820
|
+
enumerable: true,
|
|
2821
|
+
get: function() {
|
|
2822
|
+
return Hookable;
|
|
2823
|
+
}
|
|
2824
|
+
});
|
|
2825
|
+
Object.defineProperty(exports, "KubbDriver", {
|
|
2826
|
+
enumerable: true,
|
|
2827
|
+
get: function() {
|
|
2828
|
+
return KubbDriver;
|
|
2829
|
+
}
|
|
2830
|
+
});
|
|
2831
|
+
Object.defineProperty(exports, "Resolver", {
|
|
2832
|
+
enumerable: true,
|
|
2833
|
+
get: function() {
|
|
2834
|
+
return Resolver;
|
|
2835
|
+
}
|
|
2836
|
+
});
|
|
2837
|
+
Object.defineProperty(exports, "__toESM", {
|
|
2838
|
+
enumerable: true,
|
|
2839
|
+
get: function() {
|
|
2840
|
+
return __toESM;
|
|
2841
|
+
}
|
|
2842
|
+
});
|
|
2843
|
+
Object.defineProperty(exports, "_usingCtx", {
|
|
2844
|
+
enumerable: true,
|
|
2845
|
+
get: function() {
|
|
2846
|
+
return _usingCtx;
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
Object.defineProperty(exports, "addGenerator", {
|
|
2850
|
+
enumerable: true,
|
|
2851
|
+
get: function() {
|
|
2852
|
+
return addGenerator;
|
|
2853
|
+
}
|
|
2854
|
+
});
|
|
2855
|
+
Object.defineProperty(exports, "addMacro", {
|
|
2856
|
+
enumerable: true,
|
|
2857
|
+
get: function() {
|
|
2858
|
+
return addMacro;
|
|
2859
|
+
}
|
|
2860
|
+
});
|
|
2861
|
+
Object.defineProperty(exports, "assertPluginOption", {
|
|
2862
|
+
enumerable: true,
|
|
2863
|
+
get: function() {
|
|
2864
|
+
return assertPluginOption;
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
Object.defineProperty(exports, "camelCase", {
|
|
2868
|
+
enumerable: true,
|
|
2869
|
+
get: function() {
|
|
2870
|
+
return camelCase;
|
|
2871
|
+
}
|
|
2872
|
+
});
|
|
2873
|
+
Object.defineProperty(exports, "checkCompatibility", {
|
|
2874
|
+
enumerable: true,
|
|
2875
|
+
get: function() {
|
|
2876
|
+
return checkCompatibility;
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
Object.defineProperty(exports, "createNodeCache", {
|
|
2880
|
+
enumerable: true,
|
|
2881
|
+
get: function() {
|
|
2882
|
+
return createNodeCache;
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
Object.defineProperty(exports, "createResolver", {
|
|
2886
|
+
enumerable: true,
|
|
2887
|
+
get: function() {
|
|
2888
|
+
return createResolver;
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
Object.defineProperty(exports, "defineExtension", {
|
|
2892
|
+
enumerable: true,
|
|
2893
|
+
get: function() {
|
|
2894
|
+
return defineExtension;
|
|
2895
|
+
}
|
|
2896
|
+
});
|
|
2897
|
+
Object.defineProperty(exports, "definePlugin", {
|
|
2898
|
+
enumerable: true,
|
|
2899
|
+
get: function() {
|
|
2900
|
+
return definePlugin;
|
|
2901
|
+
}
|
|
2902
|
+
});
|
|
2903
|
+
Object.defineProperty(exports, "formatMs", {
|
|
2904
|
+
enumerable: true,
|
|
2905
|
+
get: function() {
|
|
2906
|
+
return formatMs;
|
|
2907
|
+
}
|
|
2908
|
+
});
|
|
2909
|
+
Object.defineProperty(exports, "getElapsedMs", {
|
|
2910
|
+
enumerable: true,
|
|
2911
|
+
get: function() {
|
|
2912
|
+
return getElapsedMs;
|
|
2913
|
+
}
|
|
2914
|
+
});
|
|
2915
|
+
Object.defineProperty(exports, "getInputKind", {
|
|
2916
|
+
enumerable: true,
|
|
2917
|
+
get: function() {
|
|
2918
|
+
return getInputKind;
|
|
2919
|
+
}
|
|
2920
|
+
});
|
|
2921
|
+
Object.defineProperty(exports, "inParallel", {
|
|
2922
|
+
enumerable: true,
|
|
2923
|
+
get: function() {
|
|
2924
|
+
return inParallel;
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
Object.defineProperty(exports, "injectFile", {
|
|
2928
|
+
enumerable: true,
|
|
2929
|
+
get: function() {
|
|
2930
|
+
return injectFile;
|
|
2931
|
+
}
|
|
2932
|
+
});
|
|
2933
|
+
Object.defineProperty(exports, "isPathInside", {
|
|
2934
|
+
enumerable: true,
|
|
2935
|
+
get: function() {
|
|
2936
|
+
return isPathInside;
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
Object.defineProperty(exports, "kubbContext", {
|
|
2940
|
+
enumerable: true,
|
|
2941
|
+
get: function() {
|
|
2942
|
+
return kubbContext;
|
|
2943
|
+
}
|
|
2944
|
+
});
|
|
2945
|
+
Object.defineProperty(exports, "pluginNotFoundError", {
|
|
2946
|
+
enumerable: true,
|
|
2947
|
+
get: function() {
|
|
2948
|
+
return pluginNotFoundError;
|
|
2949
|
+
}
|
|
2950
|
+
});
|
|
2951
|
+
Object.defineProperty(exports, "read", {
|
|
2952
|
+
enumerable: true,
|
|
2953
|
+
get: function() {
|
|
2954
|
+
return read;
|
|
2955
|
+
}
|
|
2956
|
+
});
|
|
2957
|
+
Object.defineProperty(exports, "requirePlugin", {
|
|
2958
|
+
enumerable: true,
|
|
2959
|
+
get: function() {
|
|
2960
|
+
return requirePlugin;
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
Object.defineProperty(exports, "resolveMeta", {
|
|
2964
|
+
enumerable: true,
|
|
2965
|
+
get: function() {
|
|
2966
|
+
return resolveMeta;
|
|
2967
|
+
}
|
|
2968
|
+
});
|
|
2969
|
+
Object.defineProperty(exports, "setMacros", {
|
|
2970
|
+
enumerable: true,
|
|
2971
|
+
get: function() {
|
|
2972
|
+
return setMacros;
|
|
2973
|
+
}
|
|
2974
|
+
});
|
|
2975
|
+
Object.defineProperty(exports, "setOptions", {
|
|
2976
|
+
enumerable: true,
|
|
2977
|
+
get: function() {
|
|
2978
|
+
return setOptions;
|
|
2979
|
+
}
|
|
2980
|
+
});
|
|
2981
|
+
Object.defineProperty(exports, "setResolver", {
|
|
2982
|
+
enumerable: true,
|
|
2983
|
+
get: function() {
|
|
2984
|
+
return setResolver;
|
|
2985
|
+
}
|
|
2986
|
+
});
|
|
2987
|
+
Object.defineProperty(exports, "toError", {
|
|
2988
|
+
enumerable: true,
|
|
2989
|
+
get: function() {
|
|
2990
|
+
return toError;
|
|
2991
|
+
}
|
|
2992
|
+
});
|
|
2993
|
+
Object.defineProperty(exports, "toPosixPath", {
|
|
2994
|
+
enumerable: true,
|
|
2995
|
+
get: function() {
|
|
2996
|
+
return toPosixPath;
|
|
2997
|
+
}
|
|
2998
|
+
});
|
|
2999
|
+
Object.defineProperty(exports, "tryUseKubb", {
|
|
3000
|
+
enumerable: true,
|
|
3001
|
+
get: function() {
|
|
3002
|
+
return tryUseKubb;
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
Object.defineProperty(exports, "useConfig", {
|
|
3006
|
+
enumerable: true,
|
|
3007
|
+
get: function() {
|
|
3008
|
+
return useConfig;
|
|
3009
|
+
}
|
|
3010
|
+
});
|
|
3011
|
+
Object.defineProperty(exports, "useKubb", {
|
|
3012
|
+
enumerable: true,
|
|
3013
|
+
get: function() {
|
|
3014
|
+
return useKubb;
|
|
3015
|
+
}
|
|
3016
|
+
});
|
|
3017
|
+
Object.defineProperty(exports, "useOptions", {
|
|
3018
|
+
enumerable: true,
|
|
3019
|
+
get: function() {
|
|
3020
|
+
return useOptions;
|
|
3021
|
+
}
|
|
3022
|
+
});
|
|
3023
|
+
Object.defineProperty(exports, "write", {
|
|
3024
|
+
enumerable: true,
|
|
3025
|
+
get: function() {
|
|
3026
|
+
return write;
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
|
|
3030
|
+
//# sourceMappingURL=Hookable-C4S0gBso.cjs.map
|