@kubb/core 5.18.6 → 5.18.8
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 +180 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -11
- package/dist/index.d.ts +33 -11
- package/dist/index.js +193 -66
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -29,10 +29,10 @@ let node_async_hooks = require("node:async_hooks");
|
|
|
29
29
|
let node_process = require("node:process");
|
|
30
30
|
node_process = __toESM(node_process, 1);
|
|
31
31
|
let tinyexec = require("tinyexec");
|
|
32
|
+
let node_fs = require("node:fs");
|
|
32
33
|
let node_fs_promises = require("node:fs/promises");
|
|
33
34
|
let node_path = require("node:path");
|
|
34
35
|
node_path = __toESM(node_path, 1);
|
|
35
|
-
let node_fs = require("node:fs");
|
|
36
36
|
let node_util = require("node:util");
|
|
37
37
|
let _kubb_ast = require("@kubb/ast");
|
|
38
38
|
let node_dns = require("node:dns");
|
|
@@ -45,7 +45,7 @@ let node_readline = require("node:readline");
|
|
|
45
45
|
let node_url = require("node:url");
|
|
46
46
|
let node_module = require("node:module");
|
|
47
47
|
// package.json
|
|
48
|
-
var version = "5.18.
|
|
48
|
+
var version = "5.18.8";
|
|
49
49
|
// ../../internals/utils/src/casing.ts
|
|
50
50
|
/**
|
|
51
51
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -220,7 +220,25 @@ async function exists(path) {
|
|
|
220
220
|
*/
|
|
221
221
|
async function read(path) {
|
|
222
222
|
if (runtime.isBun) return Bun.file(path).text();
|
|
223
|
-
return (0,
|
|
223
|
+
return new Promise((resolvePromise, reject) => (0, node_fs.readFile)(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Reads the file at `path` as a UTF-8 string, or `null` when it does not exist or cannot be read.
|
|
227
|
+
* Uses `Bun.file().text()` when running under Bun, `fs.readFileSync` otherwise.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const stored = await readIfExists('./src/gen/Pet.ts') // null on a first run
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async function readIfExists(path) {
|
|
235
|
+
if (runtime.isBun) return Bun.file(path).text().catch(() => null);
|
|
236
|
+
if (!(0, node_fs.existsSync)(path)) return null;
|
|
237
|
+
try {
|
|
238
|
+
return (0, node_fs.readFileSync)(path, "utf8");
|
|
239
|
+
} catch (_error) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
224
242
|
}
|
|
225
243
|
/**
|
|
226
244
|
* Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact
|
|
@@ -255,7 +273,7 @@ async function write(path, data, options = {}) {
|
|
|
255
273
|
const content = `${trimmed}\n`;
|
|
256
274
|
const resolved = (0, node_path.resolve)(path);
|
|
257
275
|
if (matchesStored({
|
|
258
|
-
stored: (options.stored === void 0 ? await
|
|
276
|
+
stored: (options.stored === void 0 ? await readIfExists(resolved) : options.stored) ?? "",
|
|
259
277
|
source: trimmed
|
|
260
278
|
})) return null;
|
|
261
279
|
await writeRaw(resolved, content);
|
|
@@ -280,11 +298,11 @@ async function writeRaw(path, content) {
|
|
|
280
298
|
return;
|
|
281
299
|
}
|
|
282
300
|
try {
|
|
283
|
-
await (0,
|
|
301
|
+
await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
284
302
|
} catch (error) {
|
|
285
303
|
if (error.code !== "ENOENT") throw error;
|
|
286
304
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(resolved), { recursive: true });
|
|
287
|
-
await (0,
|
|
305
|
+
await new Promise((resolvePromise, reject) => (0, node_fs.writeFile)(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
288
306
|
}
|
|
289
307
|
}
|
|
290
308
|
/**
|
|
@@ -358,12 +376,33 @@ function isPathInside(path, parent) {
|
|
|
358
376
|
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
359
377
|
*/
|
|
360
378
|
function memo$1(store, key, compute) {
|
|
361
|
-
|
|
379
|
+
const cached = store.get(key);
|
|
380
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
362
381
|
const value = compute();
|
|
363
382
|
store.set(key, value);
|
|
364
383
|
return value;
|
|
365
384
|
}
|
|
366
385
|
__name(memo$1, "memo");
|
|
386
|
+
function createStore({ type }) {
|
|
387
|
+
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
388
|
+
const entry = /* @__PURE__ */ new Map();
|
|
389
|
+
if (type === "map") return entry;
|
|
390
|
+
const set = (key, value) => {
|
|
391
|
+
entry.clear();
|
|
392
|
+
entry.set(key, value);
|
|
393
|
+
};
|
|
394
|
+
const touch = (key) => {
|
|
395
|
+
if (!entry.has(key)) return false;
|
|
396
|
+
set(key, entry.get(key));
|
|
397
|
+
return true;
|
|
398
|
+
};
|
|
399
|
+
return {
|
|
400
|
+
has: touch,
|
|
401
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
402
|
+
set
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
memo$1.create = createStore;
|
|
367
406
|
/**
|
|
368
407
|
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
369
408
|
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
@@ -573,7 +612,7 @@ const diagnosticCatalog = {
|
|
|
573
612
|
code: "KUBB_INVALID_DOCUMENT",
|
|
574
613
|
title: "Invalid document",
|
|
575
614
|
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.",
|
|
576
|
-
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
|
|
615
|
+
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 or OpenAPI 3.0, 3.1, or 3.2 document, and check that a passed object is the spec itself rather than a wrapper around it."
|
|
577
616
|
},
|
|
578
617
|
invalidSpec: {
|
|
579
618
|
code: "KUBB_INVALID_SPEC",
|
|
@@ -698,8 +737,8 @@ const diagnosticCatalog = {
|
|
|
698
737
|
invalidPluginOptions: {
|
|
699
738
|
code: "KUBB_INVALID_PLUGIN_OPTIONS",
|
|
700
739
|
title: "Invalid plugin options",
|
|
701
|
-
cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
|
|
702
|
-
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or
|
|
740
|
+
cause: "A plugin was configured with options that cannot be honored, for example a single-file output (`output.mode: 'file'`, or an `output.path` with a file extension) paired with a `group` option.",
|
|
741
|
+
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option, give `output.path` a directory name, or set `output.mode: 'directory'`."
|
|
703
742
|
},
|
|
704
743
|
postGenerateFailed: {
|
|
705
744
|
code: "KUBB_POST_GENERATE_FAILED",
|
|
@@ -1742,11 +1781,16 @@ function inputToAdapterSource(config) {
|
|
|
1742
1781
|
}
|
|
1743
1782
|
// src/resolveOptions.ts
|
|
1744
1783
|
const patterns = /* @__PURE__ */ new Map();
|
|
1784
|
+
const methodPatterns = /* @__PURE__ */ new Map();
|
|
1745
1785
|
const nodeCaches = /* @__PURE__ */ new WeakMap();
|
|
1746
1786
|
function testPattern(value, pattern) {
|
|
1747
1787
|
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1748
1788
|
return value.match(pattern) !== null;
|
|
1749
1789
|
}
|
|
1790
|
+
function testMethod(method, pattern) {
|
|
1791
|
+
if (typeof pattern === "string") return memo$1(methodPatterns, pattern, () => new RegExp(pattern, "i")).test(method);
|
|
1792
|
+
return method.match(pattern.ignoreCase ? pattern : new RegExp(pattern.source, `${pattern.flags}i`)) !== null;
|
|
1793
|
+
}
|
|
1750
1794
|
function matchesOperation(node, filter) {
|
|
1751
1795
|
if (filter.type === "extension") {
|
|
1752
1796
|
const { extensions } = node;
|
|
@@ -1756,7 +1800,7 @@ function matchesOperation(node, filter) {
|
|
|
1756
1800
|
if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
|
|
1757
1801
|
if (type === "operationId") return testPattern(node.operationId, pattern);
|
|
1758
1802
|
if (type === "path") return node.path !== void 0 && testPattern(node.path, pattern);
|
|
1759
|
-
if (type === "method") return node.method !== void 0 &&
|
|
1803
|
+
if (type === "method") return node.method !== void 0 && testMethod(node.method, pattern);
|
|
1760
1804
|
if (type === "contentType") return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false;
|
|
1761
1805
|
return false;
|
|
1762
1806
|
}
|
|
@@ -1805,6 +1849,7 @@ function isNamespace(value) {
|
|
|
1805
1849
|
* reachable and a `file` override is never dropped.
|
|
1806
1850
|
*/
|
|
1807
1851
|
const resolverOptions = Symbol.for("@kubb/core/resolver/options");
|
|
1852
|
+
const createNameNode = () => ({ next: /* @__PURE__ */ new Map() });
|
|
1808
1853
|
/**
|
|
1809
1854
|
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
1810
1855
|
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
@@ -1870,6 +1915,10 @@ var Resolver = class Resolver {
|
|
|
1870
1915
|
#options;
|
|
1871
1916
|
#memo = /* @__PURE__ */ new Map();
|
|
1872
1917
|
#usedNames = /* @__PURE__ */ new Set();
|
|
1918
|
+
#stringNames = /* @__PURE__ */ new Map();
|
|
1919
|
+
#arrayNames = createNameNode();
|
|
1920
|
+
#outputDirs = /* @__PURE__ */ new WeakMap();
|
|
1921
|
+
#importPaths = /* @__PURE__ */ new WeakMap();
|
|
1873
1922
|
#tagParents = /* @__PURE__ */ new Map();
|
|
1874
1923
|
#baseName;
|
|
1875
1924
|
#filePath;
|
|
@@ -1936,16 +1985,30 @@ var Resolver = class Resolver {
|
|
|
1936
1985
|
* ```
|
|
1937
1986
|
*/
|
|
1938
1987
|
resolveName({ key, name, normalize = (name) => name }) {
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1988
|
+
if (typeof key === "string") return memo$1(this.#stringNames, key, () => this.#allocateName({
|
|
1989
|
+
name,
|
|
1990
|
+
normalize,
|
|
1991
|
+
suffix: 1
|
|
1992
|
+
}));
|
|
1993
|
+
const node = key.reduce((parent, segment) => memo$1(parent.next, segment, createNameNode), this.#arrayNames);
|
|
1994
|
+
node.name ??= this.#allocateName({
|
|
1995
|
+
name,
|
|
1996
|
+
normalize,
|
|
1997
|
+
suffix: 1
|
|
1998
|
+
});
|
|
1999
|
+
return node.name;
|
|
2000
|
+
}
|
|
2001
|
+
#allocateName({ name, normalize, suffix }) {
|
|
2002
|
+
const candidate = suffix === 1 ? name : `${name}${suffix}`;
|
|
2003
|
+
const normalized = normalize(candidate);
|
|
2004
|
+
const names = typeof normalized === "string" ? [normalized] : normalized;
|
|
2005
|
+
if (names.some((emittedName) => this.#usedNames.has(emittedName))) return this.#allocateName({
|
|
2006
|
+
name,
|
|
2007
|
+
normalize,
|
|
2008
|
+
suffix: suffix + 1
|
|
2009
|
+
});
|
|
2010
|
+
this.reserveNames(names);
|
|
2011
|
+
return candidate;
|
|
1949
2012
|
}
|
|
1950
2013
|
file(options) {
|
|
1951
2014
|
return this.#resolveFile(options);
|
|
@@ -1962,17 +2025,17 @@ var Resolver = class Resolver {
|
|
|
1962
2025
|
* reads the same ref set instead of re-scanning it per plugin.
|
|
1963
2026
|
*/
|
|
1964
2027
|
imports(options) {
|
|
1965
|
-
const { node, root, output,
|
|
2028
|
+
const { node, root, output, extname = ".ts", name, checks } = options;
|
|
1966
2029
|
const resolveName = name ?? ((schemaName) => this.name(schemaName));
|
|
2030
|
+
const paths = memo$1(memo$1(memo$1(this.#importPaths, output, () => /* @__PURE__ */ new Map()), root, () => /* @__PURE__ */ new Map()), extname, () => /* @__PURE__ */ new Map());
|
|
1967
2031
|
return _kubb_ast.ast.graph.getImportedNames(node, { checks }).map((schemaName) => _kubb_ast.ast.factory.createImport({
|
|
1968
2032
|
name: [resolveName(schemaName)],
|
|
1969
|
-
path: this.#resolveFilePath({
|
|
2033
|
+
path: memo$1(paths, schemaName, () => this.#resolveFilePath({
|
|
1970
2034
|
name: schemaName,
|
|
1971
2035
|
extname,
|
|
1972
2036
|
root,
|
|
1973
|
-
output
|
|
1974
|
-
|
|
1975
|
-
})
|
|
2037
|
+
output
|
|
2038
|
+
}))
|
|
1976
2039
|
}));
|
|
1977
2040
|
}
|
|
1978
2041
|
/**
|
|
@@ -2044,8 +2107,8 @@ var Resolver = class Resolver {
|
|
|
2044
2107
|
* are provided.
|
|
2045
2108
|
*/
|
|
2046
2109
|
#resolvePath({ baseName, tag, path: groupPath, root, output, group }) {
|
|
2047
|
-
|
|
2048
|
-
|
|
2110
|
+
const outputDir = memo$1(memo$1(this.#outputDirs, output, () => /* @__PURE__ */ new Map()), root, () => node_path.default.resolve(root, output.path));
|
|
2111
|
+
if (output.mode !== "directory") return outputDir;
|
|
2049
2112
|
const groupValue = group?.type === "path" ? groupPath : tag;
|
|
2050
2113
|
const result = group && groupValue ? node_path.default.resolve(outputDir, this.groupDir(group, groupValue), baseName) : node_path.default.resolve(outputDir, baseName);
|
|
2051
2114
|
assertInside({
|
|
@@ -2059,15 +2122,15 @@ var Resolver = class Resolver {
|
|
|
2059
2122
|
/**
|
|
2060
2123
|
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
2061
2124
|
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
2062
|
-
* spec-derived values from writing outside the
|
|
2125
|
+
* spec-derived values from writing outside the output directory.
|
|
2063
2126
|
*/
|
|
2064
2127
|
#resolveOverridePath(filePath, root) {
|
|
2065
2128
|
const resolved = node_path.default.resolve(root, filePath);
|
|
2066
2129
|
assertInside({
|
|
2067
2130
|
target: resolved,
|
|
2068
2131
|
parent: root,
|
|
2069
|
-
message: `Resolved path "${resolved}" is outside the
|
|
2070
|
-
help: "A resolver `file.path` must return a path inside the
|
|
2132
|
+
message: `Resolved path "${resolved}" is outside the output directory "${root}".`,
|
|
2133
|
+
help: "A resolver `file.path` must return a path inside the output directory (`config.output.path`)."
|
|
2071
2134
|
});
|
|
2072
2135
|
return resolved;
|
|
2073
2136
|
}
|
|
@@ -2210,7 +2273,7 @@ var Resolver = class Resolver {
|
|
|
2210
2273
|
function createResolver(options) {
|
|
2211
2274
|
return new Resolver(options);
|
|
2212
2275
|
}
|
|
2213
|
-
// \0@oxc-project+runtime@0.
|
|
2276
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/usingCtx.js
|
|
2214
2277
|
function _usingCtx() {
|
|
2215
2278
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
2216
2279
|
var n = Error();
|
|
@@ -2323,7 +2386,8 @@ function compareFiles(a, b) {
|
|
|
2323
2386
|
/**
|
|
2324
2387
|
* Writes `source` to `file.path` unless the storage already holds it, either verbatim or, per the
|
|
2325
2388
|
* manifest, as what the output passes make of it. Checking here rather than in a driver gives a
|
|
2326
|
-
* storage writing to S3 or a database the same guarantee `fsStorage` has. `false` when
|
|
2389
|
+
* storage writing to S3 or a database the same guarantee `fsStorage` has. `written` is `false` when
|
|
2390
|
+
* skipped, and `stored` is what the storage held before the write.
|
|
2327
2391
|
*/
|
|
2328
2392
|
async function writeChanged({ storage, manifest, file, source, signal, cleaned }) {
|
|
2329
2393
|
signal?.throwIfAborted();
|
|
@@ -2335,14 +2399,20 @@ async function writeChanged({ storage, manifest, file, source, signal, cleaned }
|
|
|
2335
2399
|
key: file.path,
|
|
2336
2400
|
source,
|
|
2337
2401
|
disk: stored
|
|
2338
|
-
}))) return
|
|
2402
|
+
}))) return {
|
|
2403
|
+
written: false,
|
|
2404
|
+
stored
|
|
2405
|
+
};
|
|
2339
2406
|
signal?.throwIfAborted();
|
|
2340
2407
|
await storage.writeItem(file.path, source, { stored });
|
|
2341
2408
|
manifest?.track({
|
|
2342
2409
|
key: file.path,
|
|
2343
2410
|
source
|
|
2344
2411
|
});
|
|
2345
|
-
return
|
|
2412
|
+
return {
|
|
2413
|
+
written: true,
|
|
2414
|
+
stored
|
|
2415
|
+
};
|
|
2346
2416
|
}
|
|
2347
2417
|
/** Reports finished files in input order: each finished file flushes the run of finished files ahead of it as one update. */
|
|
2348
2418
|
function createProgress(files, config, hooks) {
|
|
@@ -2502,7 +2572,7 @@ var FileManager = class {
|
|
|
2502
2572
|
* memory rather than holding every source, while still overlapping each file's write with the
|
|
2503
2573
|
* next file's parse. Files finish in whatever order they parse, so each finished file flushes the
|
|
2504
2574
|
* run of finished files ahead of it as one `kubb:files:processing:update`, keeping rows in input order.
|
|
2505
|
-
* Each parsed source goes out once on `kubb:file:processed`,
|
|
2575
|
+
* Each parsed source goes out once on `kubb:file:processed`, next to what the storage held before the write.
|
|
2506
2576
|
*
|
|
2507
2577
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
2508
2578
|
* writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
|
|
@@ -2520,17 +2590,19 @@ var FileManager = class {
|
|
|
2520
2590
|
signal?.throwIfAborted();
|
|
2521
2591
|
const source = await this.parse(file, { parsers });
|
|
2522
2592
|
if (source) {
|
|
2523
|
-
|
|
2593
|
+
const { written, stored } = await writeChanged({
|
|
2524
2594
|
storage,
|
|
2525
2595
|
manifest,
|
|
2526
2596
|
file,
|
|
2527
2597
|
source,
|
|
2528
2598
|
signal,
|
|
2529
2599
|
cleaned
|
|
2530
|
-
})
|
|
2600
|
+
});
|
|
2601
|
+
if (!written) unchanged.push(file.path);
|
|
2531
2602
|
await hooks?.callHook("kubb:file:processed", {
|
|
2532
2603
|
file,
|
|
2533
|
-
source
|
|
2604
|
+
source,
|
|
2605
|
+
stored
|
|
2534
2606
|
});
|
|
2535
2607
|
}
|
|
2536
2608
|
await progress?.(index);
|
|
@@ -2580,6 +2652,22 @@ function normalizePluginOptions(rawOptions, pluginName) {
|
|
|
2580
2652
|
group,
|
|
2581
2653
|
pluginName
|
|
2582
2654
|
});
|
|
2655
|
+
options.override = options.override?.map((entry) => {
|
|
2656
|
+
const { output } = entry.options;
|
|
2657
|
+
if (!output) return entry;
|
|
2658
|
+
const entryGroup = "group" in entry.options ? entry.options.group : group;
|
|
2659
|
+
return {
|
|
2660
|
+
...entry,
|
|
2661
|
+
options: {
|
|
2662
|
+
...entry.options,
|
|
2663
|
+
output: normalizeOutput({
|
|
2664
|
+
output,
|
|
2665
|
+
group: entryGroup,
|
|
2666
|
+
pluginName
|
|
2667
|
+
})
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
});
|
|
2583
2671
|
return options;
|
|
2584
2672
|
}
|
|
2585
2673
|
/**
|
|
@@ -3391,11 +3479,7 @@ const createStorage = (build) => (options) => build(options ?? {});
|
|
|
3391
3479
|
const fsStorage = createStorage(() => ({
|
|
3392
3480
|
name: "fs",
|
|
3393
3481
|
async readItem(key) {
|
|
3394
|
-
|
|
3395
|
-
return await read((0, node_path.resolve)(key));
|
|
3396
|
-
} catch (_error) {
|
|
3397
|
-
return null;
|
|
3398
|
-
}
|
|
3482
|
+
return readIfExists((0, node_path.resolve)(key));
|
|
3399
3483
|
},
|
|
3400
3484
|
async writeItem(key, value, options) {
|
|
3401
3485
|
await write((0, node_path.resolve)(key), value, {
|
|
@@ -3810,7 +3894,7 @@ function hasOutputPasses({ output, storage }) {
|
|
|
3810
3894
|
* const { files, diagnostics } = await kubb.safeBuild()
|
|
3811
3895
|
* ```
|
|
3812
3896
|
*/
|
|
3813
|
-
var Kubb = class {
|
|
3897
|
+
var Kubb = class Kubb {
|
|
3814
3898
|
hooks;
|
|
3815
3899
|
config;
|
|
3816
3900
|
#driver = null;
|
|
@@ -3821,6 +3905,34 @@ var Kubb = class {
|
|
|
3821
3905
|
this.hooks = options.hooks ?? new Hookable();
|
|
3822
3906
|
this.#signal = options.signal;
|
|
3823
3907
|
}
|
|
3908
|
+
/**
|
|
3909
|
+
* Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
|
|
3910
|
+
* memory holds one config at a time. A config that fails does not stop the others. Only an aborted `signal` rejects.
|
|
3911
|
+
*/
|
|
3912
|
+
static async *generate(configs, { hooks = new Hookable(), signal } = {}) {
|
|
3913
|
+
for (const config of configs) {
|
|
3914
|
+
const kubb = new Kubb(config, {
|
|
3915
|
+
hooks,
|
|
3916
|
+
signal
|
|
3917
|
+
});
|
|
3918
|
+
try {
|
|
3919
|
+
yield {
|
|
3920
|
+
...await kubb.generate(),
|
|
3921
|
+
kubb
|
|
3922
|
+
};
|
|
3923
|
+
} catch (error) {
|
|
3924
|
+
if (signal?.aborted) throw error;
|
|
3925
|
+
yield {
|
|
3926
|
+
success: false,
|
|
3927
|
+
files: [],
|
|
3928
|
+
diagnostics: [Diagnostics.from(error)],
|
|
3929
|
+
input: null,
|
|
3930
|
+
kubb,
|
|
3931
|
+
error
|
|
3932
|
+
};
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3824
3936
|
get storage() {
|
|
3825
3937
|
return this.config.storage;
|
|
3826
3938
|
}
|
|
@@ -3891,7 +4003,8 @@ var Kubb = class {
|
|
|
3891
4003
|
diagnostics,
|
|
3892
4004
|
files: driver.fileManager.files,
|
|
3893
4005
|
driver,
|
|
3894
|
-
storage
|
|
4006
|
+
storage,
|
|
4007
|
+
input: driver.inputNode
|
|
3895
4008
|
};
|
|
3896
4009
|
} catch (_) {
|
|
3897
4010
|
_usingCtx$1.e = _;
|
|
@@ -3927,15 +4040,16 @@ var Kubb = class {
|
|
|
3927
4040
|
if (signal?.aborted) throw caughtError;
|
|
3928
4041
|
output = {
|
|
3929
4042
|
files: [],
|
|
3930
|
-
diagnostics: [Diagnostics.from(caughtError)]
|
|
4043
|
+
diagnostics: [Diagnostics.from(caughtError)],
|
|
4044
|
+
input: null
|
|
3931
4045
|
};
|
|
3932
4046
|
}
|
|
3933
|
-
const { files, diagnostics } = output;
|
|
4047
|
+
const { files, diagnostics, input } = output;
|
|
3934
4048
|
const storage = this.storage;
|
|
3935
4049
|
signal?.throwIfAborted();
|
|
3936
4050
|
for (const diagnostic of diagnostics) if (Diagnostics.isProblem(diagnostic)) await Diagnostics.emit(hooks, diagnostic);
|
|
3937
4051
|
if (Diagnostics.hasError(diagnostics)) {
|
|
3938
|
-
await
|
|
4052
|
+
await this.#end({
|
|
3939
4053
|
config,
|
|
3940
4054
|
storage,
|
|
3941
4055
|
diagnostics,
|
|
@@ -3946,7 +4060,8 @@ var Kubb = class {
|
|
|
3946
4060
|
return {
|
|
3947
4061
|
success: false,
|
|
3948
4062
|
files,
|
|
3949
|
-
diagnostics
|
|
4063
|
+
diagnostics,
|
|
4064
|
+
input
|
|
3950
4065
|
};
|
|
3951
4066
|
}
|
|
3952
4067
|
const processOutput = options.processOutput ?? runOutputPasses;
|
|
@@ -3959,7 +4074,7 @@ var Kubb = class {
|
|
|
3959
4074
|
const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
|
|
3960
4075
|
const failed = Diagnostics.hasError(outputDiagnostics);
|
|
3961
4076
|
if (!failed) await this.#manifest?.commit();
|
|
3962
|
-
await
|
|
4077
|
+
await this.#end({
|
|
3963
4078
|
config,
|
|
3964
4079
|
storage,
|
|
3965
4080
|
diagnostics: finalDiagnostics,
|
|
@@ -3970,11 +4085,23 @@ var Kubb = class {
|
|
|
3970
4085
|
return {
|
|
3971
4086
|
success: !failed,
|
|
3972
4087
|
files,
|
|
3973
|
-
diagnostics: finalDiagnostics
|
|
4088
|
+
diagnostics: finalDiagnostics,
|
|
4089
|
+
input
|
|
3974
4090
|
};
|
|
3975
4091
|
}
|
|
4092
|
+
/** Ends a run: `kubb:generation:end`, then the totals on `kubb:generation:summary`. */
|
|
4093
|
+
async #end(ctx) {
|
|
4094
|
+
await this.hooks.callHook("kubb:generation:end", ctx);
|
|
4095
|
+
await this.hooks.callHook("kubb:generation:summary", {
|
|
4096
|
+
duration: Math.round(getElapsedMs(ctx.hrStart)),
|
|
4097
|
+
fileCount: ctx.filesCreated,
|
|
4098
|
+
failedPlugins: Diagnostics.failedPlugins(ctx.diagnostics).length,
|
|
4099
|
+
status: ctx.status
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
3976
4102
|
dispose() {
|
|
3977
4103
|
this.#driver?.dispose();
|
|
4104
|
+
this.#driver = null;
|
|
3978
4105
|
}
|
|
3979
4106
|
[Symbol.dispose]() {
|
|
3980
4107
|
this.dispose();
|
|
@@ -4583,6 +4710,7 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4583
4710
|
}
|
|
4584
4711
|
exports.Diagnostics = Diagnostics;
|
|
4585
4712
|
exports.Hookable = Hookable;
|
|
4713
|
+
exports.Kubb = Kubb;
|
|
4586
4714
|
exports.KubbDriver = KubbDriver;
|
|
4587
4715
|
exports.Resolver = Resolver;
|
|
4588
4716
|
exports.addGenerator = addGenerator;
|