@kubb/core 5.15.1 → 5.15.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/index.cjs +219 -325
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -101
- package/dist/index.d.ts +3268 -21
- package/dist/index.js +3287 -147
- package/dist/index.js.map +1 -1
- package/package.json +2 -21
- package/dist/Hookable-C9bM5HsI.js +0 -3265
- package/dist/Hookable-C9bM5HsI.js.map +0 -1
- package/dist/createAdapter-CCe-Oddm.d.ts +0 -3294
- package/dist/mocks.d.ts +0 -105
- package/dist/mocks.js +0 -204
- package/dist/mocks.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
6
|
+
value,
|
|
7
|
+
configurable: true
|
|
8
|
+
});
|
|
5
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -41,7 +45,7 @@ let node_readline = require("node:readline");
|
|
|
41
45
|
let node_url = require("node:url");
|
|
42
46
|
let node_module = require("node:module");
|
|
43
47
|
// package.json
|
|
44
|
-
var version = "5.15.
|
|
48
|
+
var version = "5.15.3";
|
|
45
49
|
// ../../internals/utils/src/casing.ts
|
|
46
50
|
/**
|
|
47
51
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -250,19 +254,8 @@ async function write(path, data, options = {}) {
|
|
|
250
254
|
if (trimmed === "") return null;
|
|
251
255
|
const content = `${trimmed}\n`;
|
|
252
256
|
const resolved = (0, node_path.resolve)(path);
|
|
253
|
-
let stored = options.stored;
|
|
254
|
-
if (stored === void 0) {
|
|
255
|
-
if (runtime.isBun) {
|
|
256
|
-
const file = Bun.file(resolved);
|
|
257
|
-
stored = await file.exists() ? await file.text() : null;
|
|
258
|
-
} else try {
|
|
259
|
-
stored = await (0, node_fs_promises.readFile)(resolved, { encoding: "utf-8" });
|
|
260
|
-
} catch {
|
|
261
|
-
stored = null;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
257
|
if (matchesStored({
|
|
265
|
-
stored: stored ?? "",
|
|
258
|
+
stored: (options.stored === void 0 ? await read(resolved).catch(() => null) : options.stored) ?? "",
|
|
266
259
|
source: trimmed
|
|
267
260
|
})) return null;
|
|
268
261
|
await writeRaw(resolved, content);
|
|
@@ -357,6 +350,21 @@ function isPathInside(path, parent) {
|
|
|
357
350
|
}
|
|
358
351
|
// ../../internals/utils/src/promise.ts
|
|
359
352
|
/**
|
|
353
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
354
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
355
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
359
|
+
*/
|
|
360
|
+
function memo$1(store, key, compute) {
|
|
361
|
+
if (store.has(key)) return store.get(key);
|
|
362
|
+
const value = compute();
|
|
363
|
+
store.set(key, value);
|
|
364
|
+
return value;
|
|
365
|
+
}
|
|
366
|
+
__name(memo$1, "memo");
|
|
367
|
+
/**
|
|
360
368
|
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
361
369
|
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
362
370
|
*
|
|
@@ -1111,19 +1119,14 @@ var Diagnostics = class Diagnostics {
|
|
|
1111
1119
|
*/
|
|
1112
1120
|
static dedupe(diagnostics) {
|
|
1113
1121
|
const seen = /* @__PURE__ */ new Set();
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
if (!isProblem(diagnostic)) {
|
|
1117
|
-
result.push(diagnostic);
|
|
1118
|
-
continue;
|
|
1119
|
-
}
|
|
1122
|
+
return diagnostics.filter((diagnostic) => {
|
|
1123
|
+
if (!isProblem(diagnostic)) return true;
|
|
1120
1124
|
const pointer = diagnostic.location && "pointer" in diagnostic.location ? diagnostic.location.pointer : "";
|
|
1121
1125
|
const key = `${diagnostic.code} ${pointer} ${diagnostic.plugin ?? ""}`;
|
|
1122
|
-
if (seen.has(key))
|
|
1126
|
+
if (seen.has(key)) return false;
|
|
1123
1127
|
seen.add(key);
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
return result;
|
|
1128
|
+
return true;
|
|
1129
|
+
});
|
|
1127
1130
|
}
|
|
1128
1131
|
/**
|
|
1129
1132
|
* Builds the kubb.dev docs URL for a diagnostic code, e.g.
|
|
@@ -1446,13 +1449,6 @@ function definePlugin(definition) {
|
|
|
1446
1449
|
...definition
|
|
1447
1450
|
});
|
|
1448
1451
|
}
|
|
1449
|
-
// src/memo.ts
|
|
1450
|
-
function memoize(store, key, compute) {
|
|
1451
|
-
if (store.has(key)) return store.get(key);
|
|
1452
|
-
const value = compute();
|
|
1453
|
-
store.set(key, value);
|
|
1454
|
-
return value;
|
|
1455
|
-
}
|
|
1456
1452
|
// src/publicAddress.ts
|
|
1457
1453
|
function createBlockList() {
|
|
1458
1454
|
const list = new node_net.default.BlockList();
|
|
@@ -1739,15 +1735,10 @@ function inputToAdapterSource(config) {
|
|
|
1739
1735
|
};
|
|
1740
1736
|
}
|
|
1741
1737
|
// src/resolveOptions.ts
|
|
1742
|
-
const
|
|
1743
|
-
const
|
|
1738
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
1739
|
+
const nodeCaches = /* @__PURE__ */ new WeakMap();
|
|
1744
1740
|
function testPattern(value, pattern) {
|
|
1745
|
-
if (typeof pattern === "string")
|
|
1746
|
-
let regex = patternCache.get(pattern);
|
|
1747
|
-
regex ??= new RegExp(pattern);
|
|
1748
|
-
patternCache.set(pattern, regex);
|
|
1749
|
-
return regex.test(value);
|
|
1750
|
-
}
|
|
1741
|
+
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1751
1742
|
return value.match(pattern) !== null;
|
|
1752
1743
|
}
|
|
1753
1744
|
function matchesOperation(node, filter) {
|
|
@@ -1795,16 +1786,7 @@ function computeOptions(node, { options, exclude = [], include, override = [] })
|
|
|
1795
1786
|
function resolveOptions(node, context) {
|
|
1796
1787
|
const { options } = context;
|
|
1797
1788
|
if (typeof options !== "object" || options === null) return computeOptions(node, context);
|
|
1798
|
-
|
|
1799
|
-
if (!byOptions) {
|
|
1800
|
-
byOptions = /* @__PURE__ */ new WeakMap();
|
|
1801
|
-
optionsCache.set(options, byOptions);
|
|
1802
|
-
}
|
|
1803
|
-
const cached = byOptions.get(node);
|
|
1804
|
-
if (cached) return cached.value;
|
|
1805
|
-
const result = computeOptions(node, context);
|
|
1806
|
-
byOptions.set(node, { value: result });
|
|
1807
|
-
return result;
|
|
1789
|
+
return memo$1(memo$1(nodeCaches, options, () => /* @__PURE__ */ new WeakMap()), node, () => computeOptions(node, context));
|
|
1808
1790
|
}
|
|
1809
1791
|
// src/Resolver.ts
|
|
1810
1792
|
function isNamespace(value) {
|
|
@@ -1910,7 +1892,7 @@ var Resolver = class Resolver {
|
|
|
1910
1892
|
* Returns what `compute` produced the first time this build asked for `key`. A resolver lives for one build.
|
|
1911
1893
|
*/
|
|
1912
1894
|
memo(key, compute) {
|
|
1913
|
-
return
|
|
1895
|
+
return memo$1(this.#memo, key, compute);
|
|
1914
1896
|
}
|
|
1915
1897
|
/**
|
|
1916
1898
|
* Reserves emitted identifiers before allocating other declarations. The driver reserves component
|
|
@@ -2113,8 +2095,6 @@ var Resolver = class Resolver {
|
|
|
2113
2095
|
description: meta?.description,
|
|
2114
2096
|
version: meta?.version,
|
|
2115
2097
|
baseURL: meta?.baseURL,
|
|
2116
|
-
circularNames: meta?.circularNames ?? /* @__PURE__ */ new Set(),
|
|
2117
|
-
enumNames: meta?.enumNames ?? /* @__PURE__ */ new Set(),
|
|
2118
2098
|
filePath: file?.path ?? "",
|
|
2119
2099
|
baseName: file?.baseName ?? "",
|
|
2120
2100
|
isBarrel: file?.isBarrel ?? false,
|
|
@@ -2501,6 +2481,7 @@ var FileManager = class {
|
|
|
2501
2481
|
* memory rather than holding every source, while still overlapping each file's write with the
|
|
2502
2482
|
* next file's parse. Files finish in whatever order they parse, so each finished file flushes the
|
|
2503
2483
|
* run of finished files ahead of it as one `kubb:files:processing:update`, keeping rows in input order.
|
|
2484
|
+
* Each parsed source goes out once on `kubb:file:processed`, so listeners read it without the pool holding it.
|
|
2504
2485
|
*
|
|
2505
2486
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
2506
2487
|
* writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
|
|
@@ -2517,14 +2498,20 @@ var FileManager = class {
|
|
|
2517
2498
|
run: async (file, index) => {
|
|
2518
2499
|
signal?.throwIfAborted();
|
|
2519
2500
|
const source = await this.parse(file, { parsers });
|
|
2520
|
-
if (source
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2501
|
+
if (source) {
|
|
2502
|
+
if (!await writeChanged({
|
|
2503
|
+
storage,
|
|
2504
|
+
manifest,
|
|
2505
|
+
file,
|
|
2506
|
+
source,
|
|
2507
|
+
signal,
|
|
2508
|
+
cleaned
|
|
2509
|
+
})) unchanged.push(file.path);
|
|
2510
|
+
await hooks?.callHook("kubb:file:processed", {
|
|
2511
|
+
file,
|
|
2512
|
+
source
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2528
2515
|
await progress?.(index);
|
|
2529
2516
|
}
|
|
2530
2517
|
});
|
|
@@ -2534,34 +2521,7 @@ var FileManager = class {
|
|
|
2534
2521
|
});
|
|
2535
2522
|
}
|
|
2536
2523
|
};
|
|
2537
|
-
// src/nodeCache.ts
|
|
2538
|
-
/**
|
|
2539
|
-
* Builds an empty {@link NodeCache} backed by a plain `Map`. Called once per node in the generate
|
|
2540
|
-
* walk.
|
|
2541
|
-
*/
|
|
2542
|
-
function createNodeCache() {
|
|
2543
|
-
const store = /* @__PURE__ */ new Map();
|
|
2544
|
-
return {
|
|
2545
|
-
readItem(key) {
|
|
2546
|
-
return store.get(key);
|
|
2547
|
-
},
|
|
2548
|
-
writeItem(key, value) {
|
|
2549
|
-
store.set(key, value);
|
|
2550
|
-
return value;
|
|
2551
|
-
},
|
|
2552
|
-
ensureItem(key, factory) {
|
|
2553
|
-
if (store.has(key)) return store.get(key);
|
|
2554
|
-
const value = factory();
|
|
2555
|
-
store.set(key, value);
|
|
2556
|
-
return value;
|
|
2557
|
-
}
|
|
2558
|
-
};
|
|
2559
|
-
}
|
|
2560
2524
|
// src/KubbDriver.ts
|
|
2561
|
-
const ENFORCE_ORDER = {
|
|
2562
|
-
pre: -1,
|
|
2563
|
-
post: 1
|
|
2564
|
-
};
|
|
2565
2525
|
/** `include` filter types that select operations, and so prune the schemas they do not reach. */
|
|
2566
2526
|
const OPERATION_FILTER_TYPES = /* @__PURE__ */ new Set([
|
|
2567
2527
|
"tag",
|
|
@@ -2571,7 +2531,6 @@ const OPERATION_FILTER_TYPES = /* @__PURE__ */ new Set([
|
|
|
2571
2531
|
"contentType",
|
|
2572
2532
|
"extension"
|
|
2573
2533
|
]);
|
|
2574
|
-
const enforceWeight = (plugin) => plugin.enforce ? ENFORCE_ORDER[plugin.enforce] : 0;
|
|
2575
2534
|
/**
|
|
2576
2535
|
* The options bag a `NormalizedPlugin` starts with before a plugin refines it: a directory output
|
|
2577
2536
|
* at the plugin root and empty filter lists.
|
|
@@ -2607,21 +2566,13 @@ function normalizePluginOptions(rawOptions, pluginName) {
|
|
|
2607
2566
|
* factory passed without calling it.
|
|
2608
2567
|
*/
|
|
2609
2568
|
function assertPluginEntry(entry, index) {
|
|
2610
|
-
if (typeof entry === "
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
code: Diagnostics.code.invalidPluginOptions,
|
|
2614
|
-
severity: "error",
|
|
2615
|
-
message: `plugins[${index}] is a function ("${name}"), not a plugin.`,
|
|
2616
|
-
help: `Call it: ${name}()`,
|
|
2617
|
-
location: { kind: "config" }
|
|
2618
|
-
});
|
|
2619
|
-
}
|
|
2620
|
-
if (typeof entry !== "object" || entry === null) throw new Diagnostics.Error({
|
|
2569
|
+
if (typeof entry === "object" && entry !== null) return;
|
|
2570
|
+
const name = typeof entry === "function" ? entry.name || "pluginName" : void 0;
|
|
2571
|
+
throw new Diagnostics.Error({
|
|
2621
2572
|
code: Diagnostics.code.invalidPluginOptions,
|
|
2622
2573
|
severity: "error",
|
|
2623
|
-
message: `plugins[${index}] is ${entry === null ? "null" : typeof entry}, not a plugin.`,
|
|
2624
|
-
help: "Pass the result of a plugin factory, for example `pluginTs()`, or remove the entry.",
|
|
2574
|
+
message: name ? `plugins[${index}] is a function ("${name}"), not a plugin.` : `plugins[${index}] is ${entry === null ? "null" : typeof entry}, not a plugin.`,
|
|
2575
|
+
help: name ? `Call it: ${name}()` : "Pass the result of a plugin factory, for example `pluginTs()`, or remove the entry.",
|
|
2625
2576
|
location: { kind: "config" }
|
|
2626
2577
|
});
|
|
2627
2578
|
}
|
|
@@ -2730,7 +2681,7 @@ var KubbDriver = class {
|
|
|
2730
2681
|
* config are ignored here and surface later through `requirePlugin`.
|
|
2731
2682
|
*/
|
|
2732
2683
|
#sortPlugins(plugins) {
|
|
2733
|
-
const queue = [...plugins].sort((a, b) =>
|
|
2684
|
+
const queue = [...plugins].sort((a, b) => (0, _kubb_ast.compareEnforce)(a.enforce, b.enforce));
|
|
2734
2685
|
const names = new Set(queue.map((plugin) => plugin.name));
|
|
2735
2686
|
const blockedBy = new Map(queue.map((plugin) => {
|
|
2736
2687
|
const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
|
|
@@ -2885,20 +2836,10 @@ var KubbDriver = class {
|
|
|
2885
2836
|
try {
|
|
2886
2837
|
await hooks.callHook("kubb:plugin:start", { plugin });
|
|
2887
2838
|
} catch (caughtError) {
|
|
2888
|
-
|
|
2889
|
-
const duration = getElapsedMs(hrStart);
|
|
2890
|
-
await this.#emitPluginEnd({
|
|
2839
|
+
diagnostics.push(...await this.#finishPlugin({
|
|
2891
2840
|
plugin,
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
error
|
|
2895
|
-
});
|
|
2896
|
-
diagnostics.push(Diagnostics.fromExtension(error, {
|
|
2897
|
-
kind: "plugin",
|
|
2898
|
-
extension: plugin
|
|
2899
|
-
}), Diagnostics.performance({
|
|
2900
|
-
plugin: plugin.name,
|
|
2901
|
-
duration
|
|
2841
|
+
hrStart,
|
|
2842
|
+
error: toError(caughtError)
|
|
2902
2843
|
}));
|
|
2903
2844
|
continue;
|
|
2904
2845
|
}
|
|
@@ -2910,16 +2851,10 @@ var KubbDriver = class {
|
|
|
2910
2851
|
});
|
|
2911
2852
|
continue;
|
|
2912
2853
|
}
|
|
2913
|
-
|
|
2914
|
-
diagnostics.push(Diagnostics.performance({
|
|
2915
|
-
plugin: plugin.name,
|
|
2916
|
-
duration
|
|
2917
|
-
}));
|
|
2918
|
-
await this.#emitPluginEnd({
|
|
2854
|
+
diagnostics.push(...await this.#finishPlugin({
|
|
2919
2855
|
plugin,
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
});
|
|
2856
|
+
hrStart
|
|
2857
|
+
}));
|
|
2923
2858
|
}
|
|
2924
2859
|
diagnostics.push(...await this.#runGenerators(generatorPlugins));
|
|
2925
2860
|
this.#inlineFiles(parsersMap);
|
|
@@ -2976,21 +2911,35 @@ var KubbDriver = class {
|
|
|
2976
2911
|
upsertFile: (...files) => this.fileManager.upsert(...files)
|
|
2977
2912
|
};
|
|
2978
2913
|
}
|
|
2979
|
-
#
|
|
2980
|
-
|
|
2914
|
+
async #finishPlugin({ plugin, hrStart, error, crashSite }) {
|
|
2915
|
+
const duration = getElapsedMs(hrStart);
|
|
2916
|
+
await this.hooks.callHook("kubb:plugin:end", this.#withFiles({
|
|
2981
2917
|
plugin,
|
|
2982
2918
|
duration,
|
|
2983
|
-
success,
|
|
2919
|
+
success: !error,
|
|
2984
2920
|
...error ? { error } : {},
|
|
2985
2921
|
config: this.config
|
|
2986
2922
|
}));
|
|
2923
|
+
const timing = Diagnostics.performance({
|
|
2924
|
+
plugin: plugin.name,
|
|
2925
|
+
duration
|
|
2926
|
+
});
|
|
2927
|
+
if (!error) return [timing];
|
|
2928
|
+
const diagnostic = Diagnostics.fromExtension(error, {
|
|
2929
|
+
kind: "plugin",
|
|
2930
|
+
extension: plugin
|
|
2931
|
+
});
|
|
2932
|
+
const site = diagnostic.code === Diagnostics.code.pluginFailed && !diagnostic.location ? crashSite : void 0;
|
|
2933
|
+
return [site ? {
|
|
2934
|
+
...diagnostic,
|
|
2935
|
+
message: `While generating ${site.label}: ${diagnostic.message}`,
|
|
2936
|
+
...site.location ? { location: site.location } : {}
|
|
2937
|
+
} : diagnostic, timing];
|
|
2987
2938
|
}
|
|
2988
2939
|
/**
|
|
2989
2940
|
* Runs schemas and operations through every plugin's generators. The walk is node-outer: each
|
|
2990
2941
|
* schema is visited once and each operation once, and the node fans out to the matching
|
|
2991
|
-
* generators of every plugin in dependency order.
|
|
2992
|
-
* once per node and shared by all of that node's plugins, so node-derived work is computed once
|
|
2993
|
-
* and reused instead of recomputed per plugin. Each node still runs through the plugin's macros
|
|
2942
|
+
* generators of every plugin in dependency order. Each node still runs through the plugin's macros
|
|
2994
2943
|
* and its exclude/include/override filters before that plugin's
|
|
2995
2944
|
* generator sees it, so plugins stay isolated. Schemas run before operations so file output
|
|
2996
2945
|
* stays deterministic across runs. A generator with a `match` predicate that resolves `false`
|
|
@@ -3008,18 +2957,10 @@ var KubbDriver = class {
|
|
|
3008
2957
|
const diagnostics = [];
|
|
3009
2958
|
if (entries.length === 0) return diagnostics;
|
|
3010
2959
|
if (!this.inputNode) {
|
|
3011
|
-
for (const { plugin, hrStart } of entries) {
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
duration
|
|
3016
|
-
}));
|
|
3017
|
-
await this.#emitPluginEnd({
|
|
3018
|
-
plugin,
|
|
3019
|
-
duration,
|
|
3020
|
-
success: true
|
|
3021
|
-
});
|
|
3022
|
-
}
|
|
2960
|
+
for (const { plugin, hrStart } of entries) diagnostics.push(...await this.#finishPlugin({
|
|
2961
|
+
plugin,
|
|
2962
|
+
hrStart
|
|
2963
|
+
}));
|
|
3023
2964
|
return diagnostics;
|
|
3024
2965
|
}
|
|
3025
2966
|
const { schemas, operations } = this.inputNode;
|
|
@@ -3093,60 +3034,52 @@ var KubbDriver = class {
|
|
|
3093
3034
|
break;
|
|
3094
3035
|
}
|
|
3095
3036
|
}
|
|
3096
|
-
for (const node of schemas) {
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3037
|
+
for (const node of schemas) for (const state of states) {
|
|
3038
|
+
if (state.error || !state.schemaGenerators.length) continue;
|
|
3039
|
+
try {
|
|
3040
|
+
const resolved = state.schemas.get(node);
|
|
3041
|
+
if (resolved instanceof Error) throw resolved;
|
|
3042
|
+
if (!resolved) continue;
|
|
3043
|
+
const { transformedNode, options } = resolved;
|
|
3044
|
+
const ctx = {
|
|
3045
|
+
...state.generatorContext,
|
|
3046
|
+
options
|
|
3047
|
+
};
|
|
3048
|
+
await this.#dispatchNode({
|
|
3049
|
+
generators: state.schemaGenerators,
|
|
3050
|
+
node: transformedNode,
|
|
3051
|
+
ctx,
|
|
3052
|
+
generate: (generator) => generator.schema(transformedNode, ctx)
|
|
3053
|
+
});
|
|
3054
|
+
await this.hooks.callHook("kubb:generate:schema", transformedNode, ctx);
|
|
3055
|
+
} catch (caughtError) {
|
|
3056
|
+
state.error = toError(caughtError);
|
|
3057
|
+
state.crashSite = getCrashSite(node);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
for (const node of operations) for (const state of states) {
|
|
3061
|
+
if (state.error || !state.operationGenerators.length && !state.operationsGenerators.length) continue;
|
|
3062
|
+
try {
|
|
3063
|
+
const resolved = resolveForPlugin(state, node);
|
|
3064
|
+
if (!resolved) continue;
|
|
3065
|
+
state.pluginOperations.push(resolved.transformedNode);
|
|
3066
|
+
if (state.operationGenerators.length) {
|
|
3067
|
+
const { transformedNode } = resolved;
|
|
3105
3068
|
const ctx = {
|
|
3106
3069
|
...state.generatorContext,
|
|
3107
|
-
options
|
|
3108
|
-
cache
|
|
3070
|
+
options: resolved.options
|
|
3109
3071
|
};
|
|
3110
3072
|
await this.#dispatchNode({
|
|
3111
|
-
generators: state.
|
|
3073
|
+
generators: state.operationGenerators,
|
|
3112
3074
|
node: transformedNode,
|
|
3113
3075
|
ctx,
|
|
3114
|
-
generate: (generator) => generator.
|
|
3076
|
+
generate: (generator) => generator.operation(transformedNode, ctx)
|
|
3115
3077
|
});
|
|
3116
|
-
await this.hooks.callHook("kubb:generate:
|
|
3117
|
-
} catch (caughtError) {
|
|
3118
|
-
state.error = toError(caughtError);
|
|
3119
|
-
state.crashSite = getCrashSite(node);
|
|
3120
|
-
}
|
|
3121
|
-
}
|
|
3122
|
-
}
|
|
3123
|
-
for (const node of operations) {
|
|
3124
|
-
const cache = createNodeCache();
|
|
3125
|
-
for (const state of states) {
|
|
3126
|
-
if (state.error || !state.operationGenerators.length && !state.operationsGenerators.length) continue;
|
|
3127
|
-
try {
|
|
3128
|
-
const resolved = resolveForPlugin(state, node);
|
|
3129
|
-
if (!resolved) continue;
|
|
3130
|
-
state.pluginOperations.push(resolved.transformedNode);
|
|
3131
|
-
if (state.operationGenerators.length) {
|
|
3132
|
-
const { transformedNode } = resolved;
|
|
3133
|
-
const ctx = {
|
|
3134
|
-
...state.generatorContext,
|
|
3135
|
-
options: resolved.options,
|
|
3136
|
-
cache
|
|
3137
|
-
};
|
|
3138
|
-
await this.#dispatchNode({
|
|
3139
|
-
generators: state.operationGenerators,
|
|
3140
|
-
node: transformedNode,
|
|
3141
|
-
ctx,
|
|
3142
|
-
generate: (generator) => generator.operation(transformedNode, ctx)
|
|
3143
|
-
});
|
|
3144
|
-
await this.hooks.callHook("kubb:generate:operation", transformedNode, ctx);
|
|
3145
|
-
}
|
|
3146
|
-
} catch (caughtError) {
|
|
3147
|
-
state.error = toError(caughtError);
|
|
3148
|
-
state.crashSite = getCrashSite(node);
|
|
3078
|
+
await this.hooks.callHook("kubb:generate:operation", transformedNode, ctx);
|
|
3149
3079
|
}
|
|
3080
|
+
} catch (caughtError) {
|
|
3081
|
+
state.error = toError(caughtError);
|
|
3082
|
+
state.crashSite = getCrashSite(node);
|
|
3150
3083
|
}
|
|
3151
3084
|
}
|
|
3152
3085
|
for (const state of states) {
|
|
@@ -3154,8 +3087,7 @@ var KubbDriver = class {
|
|
|
3154
3087
|
try {
|
|
3155
3088
|
const ctx = {
|
|
3156
3089
|
...state.generatorContext,
|
|
3157
|
-
options: state.plugin.options
|
|
3158
|
-
cache: createNodeCache()
|
|
3090
|
+
options: state.plugin.options
|
|
3159
3091
|
};
|
|
3160
3092
|
for (const generator of state.operationsGenerators) await this.fileManager.dispatch({
|
|
3161
3093
|
result: await generator.operations(state.pluginOperations, ctx),
|
|
@@ -3166,31 +3098,12 @@ var KubbDriver = class {
|
|
|
3166
3098
|
state.error = toError(caughtError);
|
|
3167
3099
|
}
|
|
3168
3100
|
}
|
|
3169
|
-
for (const
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
error: state.error ?? void 0
|
|
3176
|
-
});
|
|
3177
|
-
if (state.error) {
|
|
3178
|
-
const diagnostic = Diagnostics.fromExtension(state.error, {
|
|
3179
|
-
kind: "plugin",
|
|
3180
|
-
extension: state.plugin
|
|
3181
|
-
});
|
|
3182
|
-
const site = diagnostic.code === Diagnostics.code.pluginFailed && !diagnostic.location ? state.crashSite : void 0;
|
|
3183
|
-
diagnostics.push(site ? {
|
|
3184
|
-
...diagnostic,
|
|
3185
|
-
message: `While generating ${site.label}: ${diagnostic.message}`,
|
|
3186
|
-
...site.location ? { location: site.location } : {}
|
|
3187
|
-
} : diagnostic);
|
|
3188
|
-
}
|
|
3189
|
-
diagnostics.push(Diagnostics.performance({
|
|
3190
|
-
plugin: state.plugin.name,
|
|
3191
|
-
duration
|
|
3192
|
-
}));
|
|
3193
|
-
}
|
|
3101
|
+
for (const { plugin, hrStart, error, crashSite } of states) diagnostics.push(...await this.#finishPlugin({
|
|
3102
|
+
plugin,
|
|
3103
|
+
hrStart,
|
|
3104
|
+
error: error ?? void 0,
|
|
3105
|
+
crashSite
|
|
3106
|
+
}));
|
|
3194
3107
|
return diagnostics;
|
|
3195
3108
|
}
|
|
3196
3109
|
/**
|
|
@@ -3228,7 +3141,7 @@ var KubbDriver = class {
|
|
|
3228
3141
|
return this.plugins.get(pluginName)?.resolver ?? createResolver({ pluginName });
|
|
3229
3142
|
}
|
|
3230
3143
|
memo(key, compute) {
|
|
3231
|
-
return
|
|
3144
|
+
return memo$1(this.#memo, key, compute);
|
|
3232
3145
|
}
|
|
3233
3146
|
getContext(plugin) {
|
|
3234
3147
|
const driver = this;
|
|
@@ -3258,10 +3171,7 @@ var KubbDriver = class {
|
|
|
3258
3171
|
driver.fileManager.upsert(...files);
|
|
3259
3172
|
},
|
|
3260
3173
|
get meta() {
|
|
3261
|
-
return driver.inputNode?.meta ?? {
|
|
3262
|
-
circularNames: /* @__PURE__ */ new Set(),
|
|
3263
|
-
enumNames: /* @__PURE__ */ new Set()
|
|
3264
|
-
};
|
|
3174
|
+
return driver.inputNode?.meta ?? {};
|
|
3265
3175
|
},
|
|
3266
3176
|
get adapter() {
|
|
3267
3177
|
return driver.adapter;
|
|
@@ -3475,12 +3385,7 @@ const fsStorage = createStorage(() => ({
|
|
|
3475
3385
|
await (0, node_fs_promises.rm)((0, node_path.resolve)(key), { force: true });
|
|
3476
3386
|
},
|
|
3477
3387
|
async readKeys(base) {
|
|
3478
|
-
|
|
3479
|
-
const keys = [];
|
|
3480
|
-
try {
|
|
3481
|
-
for await (const path of listFiles(resolvedBase)) keys.push(path);
|
|
3482
|
-
} catch (_error) {}
|
|
3483
|
-
return keys;
|
|
3388
|
+
return Array.fromAsync(listFiles((0, node_path.resolve)(base ?? process.cwd()))).catch(() => []);
|
|
3484
3389
|
},
|
|
3485
3390
|
async empty(base) {
|
|
3486
3391
|
if (!base) return;
|
|
@@ -3633,12 +3538,6 @@ var Hookable = class {
|
|
|
3633
3538
|
return this.#listeners.get(hookName)?.size ?? 0;
|
|
3634
3539
|
}
|
|
3635
3540
|
/**
|
|
3636
|
-
* No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
|
|
3637
|
-
*
|
|
3638
|
-
* @deprecated There is no listener ceiling anymore.
|
|
3639
|
-
*/
|
|
3640
|
-
setMaxListeners(_max) {}
|
|
3641
|
-
/**
|
|
3642
3541
|
* Removes all listeners from every hook channel.
|
|
3643
3542
|
*
|
|
3644
3543
|
* @example
|
|
@@ -4118,27 +4017,96 @@ const logLevel = {
|
|
|
4118
4017
|
*/
|
|
4119
4018
|
function createReporter(reporter) {
|
|
4120
4019
|
const { name, needsPluginFiles, drain } = reporter;
|
|
4121
|
-
if (!drain) return {
|
|
4122
|
-
name,
|
|
4123
|
-
needsPluginFiles,
|
|
4124
|
-
async report(result, context) {
|
|
4125
|
-
await reporter.report(result, context);
|
|
4126
|
-
}
|
|
4127
|
-
};
|
|
4128
4020
|
const reports = [];
|
|
4129
4021
|
return {
|
|
4130
4022
|
name,
|
|
4131
4023
|
needsPluginFiles,
|
|
4132
4024
|
async report(result, context) {
|
|
4133
|
-
|
|
4025
|
+
const report = await reporter.report(result, context);
|
|
4026
|
+
if (drain) reports.push(report);
|
|
4134
4027
|
},
|
|
4135
|
-
async drain(context) {
|
|
4028
|
+
...drain && { async drain(context) {
|
|
4136
4029
|
await drain(context, reports.splice(0));
|
|
4030
|
+
} }
|
|
4031
|
+
};
|
|
4032
|
+
}
|
|
4033
|
+
// src/storages/kubbStorage.ts
|
|
4034
|
+
function ensurePrivateDir(dir) {
|
|
4035
|
+
(0, node_fs.mkdirSync)(dir, {
|
|
4036
|
+
recursive: true,
|
|
4037
|
+
mode: 448
|
|
4038
|
+
});
|
|
4039
|
+
(0, node_fs.chmodSync)(dir, 448);
|
|
4040
|
+
return dir;
|
|
4041
|
+
}
|
|
4042
|
+
/**
|
|
4043
|
+
* Folder Kubb keeps its own files in, created with mode 0700. `base` resolves inside `KUBB_HOME`
|
|
4044
|
+
* (default `~/.kubb`). When that folder is not writable, it falls back to a folder in the OS temp directory.
|
|
4045
|
+
*
|
|
4046
|
+
* @example
|
|
4047
|
+
* `resolveKubbDir('cache') // '/home/me/.kubb/cache'`
|
|
4048
|
+
*/
|
|
4049
|
+
function resolveKubbDir(base = "") {
|
|
4050
|
+
const dir = (0, node_path.resolve)(node_process.default.env.KUBB_HOME ?? (0, node_path.join)((0, node_os.homedir)(), ".kubb"), base);
|
|
4051
|
+
try {
|
|
4052
|
+
return ensurePrivateDir(dir);
|
|
4053
|
+
} catch {
|
|
4054
|
+
return ensurePrivateDir((0, node_path.join)((0, node_os.tmpdir)(), "kubb", (0, node_crypto.hash)("sha256", dir).slice(0, 16)));
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
/**
|
|
4058
|
+
* Key-value files rooted at {@link resolveKubbDir}. Each key is a file path inside that folder.
|
|
4059
|
+
* Strings are stored as is and other values as JSON. `getItem` parses JSON and falls back to the
|
|
4060
|
+
* raw string. The 0700 folder keeps files such as a stored token private.
|
|
4061
|
+
*
|
|
4062
|
+
* @example
|
|
4063
|
+
* ```ts
|
|
4064
|
+
* const storage = kubbStorage({ base: 'cache' })
|
|
4065
|
+
* await storage.setItem('machine-secret', secret)
|
|
4066
|
+
* ```
|
|
4067
|
+
*/
|
|
4068
|
+
function kubbStorage({ base } = {}) {
|
|
4069
|
+
const dir = resolveKubbDir(base);
|
|
4070
|
+
const pathOf = (key) => {
|
|
4071
|
+
const path = (0, node_path.resolve)(dir, key.replaceAll(":", "/"));
|
|
4072
|
+
if (path === dir || !isPathInside(path, dir)) throw new Error(`Invalid key: ${JSON.stringify(key)}. It should not leave the storage folder`);
|
|
4073
|
+
return path;
|
|
4074
|
+
};
|
|
4075
|
+
return {
|
|
4076
|
+
async getItem(key) {
|
|
4077
|
+
const path = pathOf(key);
|
|
4078
|
+
if (!await exists(path)) return null;
|
|
4079
|
+
const raw = await read(path);
|
|
4080
|
+
try {
|
|
4081
|
+
return JSON.parse(raw);
|
|
4082
|
+
} catch {
|
|
4083
|
+
return raw;
|
|
4084
|
+
}
|
|
4085
|
+
},
|
|
4086
|
+
async setItem(key, value) {
|
|
4087
|
+
await writeRaw(pathOf(key), typeof value === "string" ? value : JSON.stringify(value));
|
|
4088
|
+
},
|
|
4089
|
+
async removeItem(key) {
|
|
4090
|
+
await (0, node_fs_promises.rm)(pathOf(key), { force: true });
|
|
4137
4091
|
}
|
|
4138
4092
|
};
|
|
4139
4093
|
}
|
|
4140
4094
|
// src/reporters/report.ts
|
|
4141
4095
|
/**
|
|
4096
|
+
* The `.kubb` folder and file name a reporter writes to; the sanitized name keeps the file inside the folder.
|
|
4097
|
+
*/
|
|
4098
|
+
function reportTarget(config) {
|
|
4099
|
+
const name = config.name?.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4100
|
+
return {
|
|
4101
|
+
dir: resolveKubbDir((0, node_path.resolve)(node_process.default.cwd(), ".kubb")),
|
|
4102
|
+
name: [
|
|
4103
|
+
"kubb",
|
|
4104
|
+
name,
|
|
4105
|
+
Date.now()
|
|
4106
|
+
].filter(Boolean).join("-")
|
|
4107
|
+
};
|
|
4108
|
+
}
|
|
4109
|
+
/**
|
|
4142
4110
|
* Builds the normalized {@link Report} for one config from its {@link GenerationResult}. Splits the
|
|
4143
4111
|
* diagnostics into problems and per-plugin timings (slowest first) and derives the plugin and issue
|
|
4144
4112
|
* counts, so every reporter renders the same data.
|
|
@@ -4259,67 +4227,6 @@ function createCliReporter({ render = consoleRenderer } = {}) {
|
|
|
4259
4227
|
* logger view.
|
|
4260
4228
|
*/
|
|
4261
4229
|
const cliReporter = createCliReporter();
|
|
4262
|
-
// src/storages/kubbStorage.ts
|
|
4263
|
-
function ensurePrivateDir(dir) {
|
|
4264
|
-
(0, node_fs.mkdirSync)(dir, {
|
|
4265
|
-
recursive: true,
|
|
4266
|
-
mode: 448
|
|
4267
|
-
});
|
|
4268
|
-
(0, node_fs.chmodSync)(dir, 448);
|
|
4269
|
-
return dir;
|
|
4270
|
-
}
|
|
4271
|
-
/**
|
|
4272
|
-
* Folder Kubb keeps its own files in, created with mode 0700. `base` resolves inside `KUBB_HOME`
|
|
4273
|
-
* (default `~/.kubb`). When that folder is not writable, it falls back to a folder in the OS temp directory.
|
|
4274
|
-
*
|
|
4275
|
-
* @example
|
|
4276
|
-
* `resolveKubbDir('cache') // '/home/me/.kubb/cache'`
|
|
4277
|
-
*/
|
|
4278
|
-
function resolveKubbDir(base = "") {
|
|
4279
|
-
const dir = (0, node_path.resolve)(node_process.default.env.KUBB_HOME ?? (0, node_path.join)((0, node_os.homedir)(), ".kubb"), base);
|
|
4280
|
-
try {
|
|
4281
|
-
return ensurePrivateDir(dir);
|
|
4282
|
-
} catch {
|
|
4283
|
-
return ensurePrivateDir((0, node_path.join)((0, node_os.tmpdir)(), "kubb", (0, node_crypto.hash)("sha256", dir).slice(0, 16)));
|
|
4284
|
-
}
|
|
4285
|
-
}
|
|
4286
|
-
/**
|
|
4287
|
-
* Key-value files rooted at {@link resolveKubbDir}. Each key is a file path inside that folder.
|
|
4288
|
-
* Strings are stored as is and other values as JSON. `getItem` parses JSON and falls back to the
|
|
4289
|
-
* raw string. The 0700 folder keeps files such as a stored token private.
|
|
4290
|
-
*
|
|
4291
|
-
* @example
|
|
4292
|
-
* ```ts
|
|
4293
|
-
* const storage = kubbStorage({ base: 'cache' })
|
|
4294
|
-
* await storage.setItem('machine-secret', secret)
|
|
4295
|
-
* ```
|
|
4296
|
-
*/
|
|
4297
|
-
function kubbStorage({ base } = {}) {
|
|
4298
|
-
const dir = resolveKubbDir(base);
|
|
4299
|
-
const pathOf = (key) => {
|
|
4300
|
-
const path = (0, node_path.resolve)(dir, key.replaceAll(":", "/"));
|
|
4301
|
-
if (path === dir || !isPathInside(path, dir)) throw new Error(`Invalid key: ${JSON.stringify(key)}. It should not leave the storage folder`);
|
|
4302
|
-
return path;
|
|
4303
|
-
};
|
|
4304
|
-
return {
|
|
4305
|
-
async getItem(key) {
|
|
4306
|
-
const path = pathOf(key);
|
|
4307
|
-
if (!await exists(path)) return null;
|
|
4308
|
-
const raw = await read(path);
|
|
4309
|
-
try {
|
|
4310
|
-
return JSON.parse(raw);
|
|
4311
|
-
} catch {
|
|
4312
|
-
return raw;
|
|
4313
|
-
}
|
|
4314
|
-
},
|
|
4315
|
-
async setItem(key, value) {
|
|
4316
|
-
await writeRaw(pathOf(key), typeof value === "string" ? value : JSON.stringify(value));
|
|
4317
|
-
},
|
|
4318
|
-
async removeItem(key) {
|
|
4319
|
-
await (0, node_fs_promises.rm)(pathOf(key), { force: true });
|
|
4320
|
-
}
|
|
4321
|
-
};
|
|
4322
|
-
}
|
|
4323
4230
|
// src/reporters/fileReporter.ts
|
|
4324
4231
|
/**
|
|
4325
4232
|
* Builds the `## Problems` section: each problem rendered in the miette block format, blocks
|
|
@@ -4358,14 +4265,10 @@ const fileReporter = createReporter({
|
|
|
4358
4265
|
...formatSummary(report, { showTimings: true })
|
|
4359
4266
|
], buildProblemSection(diagnostics)].filter((section) => section.length > 0);
|
|
4360
4267
|
const content = (0, node_util.stripVTControlCharacters)([header, ...sections.map((section) => section.join("\n"))].join("\n\n"));
|
|
4361
|
-
const
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
].filter(Boolean).join("-")}.log`;
|
|
4366
|
-
const dir = resolveKubbDir((0, node_path.resolve)(node_process.default.cwd(), ".kubb"));
|
|
4367
|
-
await kubbStorage({ base: dir }).setItem(baseName, `${content}\n`);
|
|
4368
|
-
console.error(`Debug log written to ${(0, node_path.relative)(node_process.default.cwd(), (0, node_path.join)(dir, baseName))}`);
|
|
4268
|
+
const { dir, name } = reportTarget(config);
|
|
4269
|
+
const path = (0, node_path.join)(dir, `${name}.log`);
|
|
4270
|
+
await writeRaw(path, `${content}\n`);
|
|
4271
|
+
console.error(`Debug log written to ${(0, node_path.relative)(node_process.default.cwd(), path)}`);
|
|
4369
4272
|
}
|
|
4370
4273
|
});
|
|
4371
4274
|
// src/reporters/jsonReporter.ts
|
|
@@ -4400,21 +4303,15 @@ const htmlReporter = createReporter({
|
|
|
4400
4303
|
name: "html",
|
|
4401
4304
|
needsPluginFiles: true,
|
|
4402
4305
|
async report(result) {
|
|
4403
|
-
const
|
|
4404
|
-
"kubb",
|
|
4405
|
-
result.config.name?.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, ""),
|
|
4406
|
-
Date.now()
|
|
4407
|
-
].filter(Boolean).join("-");
|
|
4408
|
-
const dir = resolveKubbDir((0, node_path.resolve)(process.cwd(), ".kubb"));
|
|
4409
|
-
const storage = kubbStorage({ base: dir });
|
|
4306
|
+
const { dir, name } = reportTarget(result.config);
|
|
4410
4307
|
const assets = new URL("./html/", require("url").pathToFileURL(__filename).href);
|
|
4411
4308
|
const [html, ui] = await Promise.all([read((0, node_url.fileURLToPath)(new URL("index.html", assets))), read((0, node_url.fileURLToPath)(new URL("ui.iife.js", assets)))]);
|
|
4412
4309
|
await Promise.all([
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4310
|
+
writeRaw((0, node_path.join)(dir, name, "index.html"), html),
|
|
4311
|
+
writeRaw((0, node_path.join)(dir, name, "ui.iife.js"), ui),
|
|
4312
|
+
writeRaw((0, node_path.join)(dir, name, "data.js"), serializeReport(result))
|
|
4416
4313
|
]);
|
|
4417
|
-
const reportPath = (0, node_path.join)(dir,
|
|
4314
|
+
const reportPath = (0, node_path.join)(dir, name, "index.html");
|
|
4418
4315
|
console.error(`HTML report written to ${(0, node_path.relative)(process.cwd(), reportPath)}`);
|
|
4419
4316
|
openInBrowser(reportPath);
|
|
4420
4317
|
}
|
|
@@ -4535,11 +4432,7 @@ const memoryStorage = createStorage(() => {
|
|
|
4535
4432
|
return base ? keys.filter((k) => k.startsWith(base)) : keys;
|
|
4536
4433
|
},
|
|
4537
4434
|
async empty(base) {
|
|
4538
|
-
if (!base)
|
|
4539
|
-
store.clear();
|
|
4540
|
-
return;
|
|
4541
|
-
}
|
|
4542
|
-
for (const key of store.keys()) if (key.startsWith(base)) store.delete(key);
|
|
4435
|
+
for (const key of store.keys()) if (!base || key.startsWith(base)) store.delete(key);
|
|
4543
4436
|
}
|
|
4544
4437
|
};
|
|
4545
4438
|
});
|
|
@@ -4693,6 +4586,7 @@ exports.definePlugin = definePlugin;
|
|
|
4693
4586
|
exports.fileReporter = fileReporter;
|
|
4694
4587
|
exports.fsStorage = fsStorage;
|
|
4695
4588
|
exports.getInputKind = getInputKind;
|
|
4589
|
+
exports.hasOutputPasses = hasOutputPasses;
|
|
4696
4590
|
exports.htmlReporter = htmlReporter;
|
|
4697
4591
|
exports.injectFile = injectFile;
|
|
4698
4592
|
exports.isExtensionManifest = isExtensionManifest;
|