@kubb/core 5.1.0 → 5.2.1
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 +62 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.js +62 -68
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +8 -9
- package/dist/mocks.js +1 -1
- package/dist/{types-QndGMAwn.d.ts → types-D6fWCd9O.d.ts} +57 -36
- package/dist/{usingCtx-khw91yct.cjs → usingCtx-1W_18hcP.cjs} +28 -77
- package/dist/usingCtx-1W_18hcP.cjs.map +1 -0
- package/dist/{usingCtx-2r6N3STL.js → usingCtx-xMZZh-09.js} +29 -66
- package/dist/usingCtx-xMZZh-09.js.map +1 -0
- package/package.json +6 -2
- package/dist/usingCtx-2r6N3STL.js.map +0 -1
- package/dist/usingCtx-khw91yct.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_usingCtx = require("./usingCtx-
|
|
2
|
+
const require_usingCtx = require("./usingCtx-1W_18hcP.cjs");
|
|
3
3
|
let node_async_hooks = require("node:async_hooks");
|
|
4
4
|
let node_util = require("node:util");
|
|
5
|
-
let node_crypto = require("node:crypto");
|
|
6
5
|
let node_fs_promises = require("node:fs/promises");
|
|
7
6
|
let node_path = require("node:path");
|
|
8
7
|
node_path = require_usingCtx.__toESM(node_path, 1);
|
|
9
8
|
let _kubb_ast = require("@kubb/ast");
|
|
9
|
+
let node_crypto = require("node:crypto");
|
|
10
10
|
let node_fs = require("node:fs");
|
|
11
11
|
let node_os = require("node:os");
|
|
12
12
|
let node_process = require("node:process");
|
|
@@ -98,66 +98,11 @@ function formatMs(ms) {
|
|
|
98
98
|
return `${Math.round(ms)}ms`;
|
|
99
99
|
}
|
|
100
100
|
//#endregion
|
|
101
|
-
//#region ../../internals/utils/src/colors.ts
|
|
102
|
-
/**
|
|
103
|
-
* Parses a CSS hex color string (`#RGB`) into its RGB channels.
|
|
104
|
-
* Falls back to `255` for any channel that cannot be parsed.
|
|
105
|
-
*/
|
|
106
|
-
function parseHex(color) {
|
|
107
|
-
const int = Number.parseInt(color.replace("#", ""), 16);
|
|
108
|
-
return Number.isNaN(int) ? {
|
|
109
|
-
r: 255,
|
|
110
|
-
g: 255,
|
|
111
|
-
b: 255
|
|
112
|
-
} : {
|
|
113
|
-
r: int >> 16 & 255,
|
|
114
|
-
g: int >> 8 & 255,
|
|
115
|
-
b: int & 255
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Returns a function that wraps a string in a 24-bit ANSI true-color escape sequence
|
|
120
|
-
* for the given hex color.
|
|
121
|
-
*/
|
|
122
|
-
function hex(color) {
|
|
123
|
-
const { r, g, b } = parseHex(color);
|
|
124
|
-
return (text) => `\x1b[38;2;${r};${g};${b}m${text}\x1b[0m`;
|
|
125
|
-
}
|
|
126
|
-
hex("#F55A17"), hex("#F5A217"), hex("#F58517"), hex("#B45309"), hex("#FFFFFF"), hex("#adadc6"), hex("#FDA4AF");
|
|
127
|
-
/**
|
|
128
|
-
* ANSI color names used by {@link randomCliColor} for deterministic terminal coloring.
|
|
129
|
-
*/
|
|
130
|
-
const randomColors = [
|
|
131
|
-
"black",
|
|
132
|
-
"red",
|
|
133
|
-
"green",
|
|
134
|
-
"yellow",
|
|
135
|
-
"blue",
|
|
136
|
-
"white",
|
|
137
|
-
"magenta",
|
|
138
|
-
"cyan",
|
|
139
|
-
"gray"
|
|
140
|
-
];
|
|
141
|
-
/**
|
|
142
|
-
* Wraps `text` in a deterministic ANSI color derived from the text's SHA-256 hash.
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```ts
|
|
146
|
-
* randomCliColor('petstore') // '\x1b[33m' + 'petstore' + '\x1b[39m' (always the same color for 'petstore')
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
function randomCliColor(text) {
|
|
150
|
-
if (!text) return "";
|
|
151
|
-
const index = (0, node_crypto.hash)("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
|
|
152
|
-
const color = randomColors[index] ?? "white";
|
|
153
|
-
return (0, node_util.styleText)(color, text);
|
|
154
|
-
}
|
|
155
|
-
//#endregion
|
|
156
101
|
//#region src/Diagnostics.ts
|
|
157
102
|
/**
|
|
158
103
|
* Docs major version, derived from the package version so the link tracks the published major.
|
|
159
104
|
*/
|
|
160
|
-
const docsMajor = "5.1
|
|
105
|
+
const docsMajor = "5.2.1".split(".")[0] ?? "5";
|
|
161
106
|
/**
|
|
162
107
|
* Builds a type guard that narrows a {@link Diagnostic} to the variant for `kind`. A diagnostic
|
|
163
108
|
* with no `kind` is treated as a `problem`.
|
|
@@ -716,10 +661,33 @@ function isNamespace(value) {
|
|
|
716
661
|
*/
|
|
717
662
|
const resolverOptions = Symbol.for("@kubb/core/resolver/options");
|
|
718
663
|
/**
|
|
664
|
+
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
665
|
+
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
666
|
+
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
667
|
+
*
|
|
668
|
+
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
669
|
+
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
670
|
+
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
671
|
+
* absolute path, letting generated files escape the configured output directory.
|
|
672
|
+
*
|
|
673
|
+
* @example Nested path from a dotted name
|
|
674
|
+
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
675
|
+
*
|
|
676
|
+
* @example PascalCase the final segment
|
|
677
|
+
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
678
|
+
*
|
|
679
|
+
* @example Suffix applied to the final segment only
|
|
680
|
+
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
681
|
+
*/
|
|
682
|
+
function toFilePath(name, caseLast = require_usingCtx.camelCase) {
|
|
683
|
+
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
684
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : require_usingCtx.camelCase(part)).filter(Boolean).join("/");
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
719
687
|
* Built-in `file.baseName`: casts the identifier with `toFilePath` and appends the extension.
|
|
720
688
|
*/
|
|
721
689
|
function toBaseName({ name, extname }) {
|
|
722
|
-
return `${
|
|
690
|
+
return `${toFilePath(name)}${extname}`;
|
|
723
691
|
}
|
|
724
692
|
/**
|
|
725
693
|
* Base constraint for all plugin resolver objects.
|
|
@@ -1862,9 +1830,6 @@ var KubbDriver = class {
|
|
|
1862
1830
|
* Bumped when the stored shape changes, so an older cache is discarded instead of misread.
|
|
1863
1831
|
*/
|
|
1864
1832
|
const VERSION = 1;
|
|
1865
|
-
function hash(value) {
|
|
1866
|
-
return (0, node_crypto.createHash)("sha256").update(value).digest("hex");
|
|
1867
|
-
}
|
|
1868
1833
|
const MANIFEST_KEY = "output-manifest.json";
|
|
1869
1834
|
async function loadEntries({ cache }) {
|
|
1870
1835
|
try {
|
|
@@ -1894,10 +1859,10 @@ async function createOutputManifest({ storage, cache }) {
|
|
|
1894
1859
|
isUpToDate({ key, source, disk }) {
|
|
1895
1860
|
const entry = entries[key];
|
|
1896
1861
|
if (!entry) return false;
|
|
1897
|
-
return entry.source === hash(source) && entry.output === hash(disk);
|
|
1862
|
+
return entry.source === (0, node_crypto.hash)("sha256", source) && entry.output === (0, node_crypto.hash)("sha256", disk);
|
|
1898
1863
|
},
|
|
1899
1864
|
track({ key, source }) {
|
|
1900
|
-
tracked.set(key, hash(source));
|
|
1865
|
+
tracked.set(key, (0, node_crypto.hash)("sha256", source));
|
|
1901
1866
|
},
|
|
1902
1867
|
async commit() {
|
|
1903
1868
|
try {
|
|
@@ -1910,7 +1875,7 @@ async function createOutputManifest({ storage, cache }) {
|
|
|
1910
1875
|
if (stored === null) return;
|
|
1911
1876
|
next[key] = {
|
|
1912
1877
|
source,
|
|
1913
|
-
output: hash(stored)
|
|
1878
|
+
output: (0, node_crypto.hash)("sha256", stored)
|
|
1914
1879
|
};
|
|
1915
1880
|
}
|
|
1916
1881
|
});
|
|
@@ -2077,7 +2042,7 @@ const fsStorage = createStorage(() => {
|
|
|
2077
2042
|
function resolveCacheDir(root) {
|
|
2078
2043
|
const nodeModules = (0, node_path.join)(root, "node_modules");
|
|
2079
2044
|
if ((0, node_fs.existsSync)(nodeModules)) return (0, node_path.join)(nodeModules, ".cache", "kubb");
|
|
2080
|
-
return (0, node_path.join)((0, node_os.tmpdir)(), "kubb", (0, node_crypto.
|
|
2045
|
+
return (0, node_path.join)((0, node_os.tmpdir)(), "kubb", (0, node_crypto.hash)("sha256", root).slice(0, 16));
|
|
2081
2046
|
}
|
|
2082
2047
|
/**
|
|
2083
2048
|
* Filesystem storage for build caches rather than generated code. Keys are plain names resolved
|
|
@@ -2215,7 +2180,7 @@ var Kubb = class {
|
|
|
2215
2180
|
const out = await this.safeBuild();
|
|
2216
2181
|
if (Diagnostics.hasError(out.diagnostics)) {
|
|
2217
2182
|
const errors = out.diagnostics.filter(Diagnostics.isProblem).filter((diagnostic) => diagnostic.severity === "error").map((diagnostic) => diagnostic.cause ?? new Diagnostics.Error(diagnostic));
|
|
2218
|
-
throw new
|
|
2183
|
+
throw new AggregateError(errors, `Build failed with ${errors.length} ${errors.length === 1 ? "error" : "errors"}`);
|
|
2219
2184
|
}
|
|
2220
2185
|
return out;
|
|
2221
2186
|
}
|
|
@@ -2391,6 +2356,36 @@ function createReporter(reporter) {
|
|
|
2391
2356
|
};
|
|
2392
2357
|
}
|
|
2393
2358
|
//#endregion
|
|
2359
|
+
//#region src/reporters/colors.ts
|
|
2360
|
+
/**
|
|
2361
|
+
* ANSI color names used by {@link randomCliColor} for deterministic terminal coloring.
|
|
2362
|
+
*/
|
|
2363
|
+
const randomColors = [
|
|
2364
|
+
"black",
|
|
2365
|
+
"red",
|
|
2366
|
+
"green",
|
|
2367
|
+
"yellow",
|
|
2368
|
+
"blue",
|
|
2369
|
+
"white",
|
|
2370
|
+
"magenta",
|
|
2371
|
+
"cyan",
|
|
2372
|
+
"gray"
|
|
2373
|
+
];
|
|
2374
|
+
/**
|
|
2375
|
+
* Wraps `text` in a deterministic ANSI color derived from the text's SHA-256 hash.
|
|
2376
|
+
*
|
|
2377
|
+
* @example
|
|
2378
|
+
* ```ts
|
|
2379
|
+
* randomCliColor('petstore') // '\x1b[33m' + 'petstore' + '\x1b[39m' (always the same color for 'petstore')
|
|
2380
|
+
* ```
|
|
2381
|
+
*/
|
|
2382
|
+
function randomCliColor(text) {
|
|
2383
|
+
if (!text) return "";
|
|
2384
|
+
const index = (0, node_crypto.hash)("sha256", text, "buffer").readUInt32BE(0) % randomColors.length;
|
|
2385
|
+
const color = randomColors[index] ?? "white";
|
|
2386
|
+
return (0, node_util.styleText)(color, text);
|
|
2387
|
+
}
|
|
2388
|
+
//#endregion
|
|
2394
2389
|
//#region src/reporters/report.ts
|
|
2395
2390
|
/**
|
|
2396
2391
|
* Builds the normalized {@link Report} for one config from its {@link GenerationResult}. Splits the
|