@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.js
CHANGED
|
@@ -3,9 +3,9 @@ import { isValid, satisfies } from "verkit";
|
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
import process$1 from "node:process";
|
|
5
5
|
import { x } from "tinyexec";
|
|
6
|
-
import {
|
|
6
|
+
import { chmodSync, existsSync, existsSync as existsSync$1, mkdirSync, readFile, readFileSync, writeFile } from "node:fs";
|
|
7
|
+
import { access, glob, mkdir as mkdir$1, mkdtemp as mkdtemp$1, readFile as readFile$1, readdir, rename, rm, rm as rm$1 } from "node:fs/promises";
|
|
7
8
|
import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
|
-
import { chmodSync, existsSync, existsSync as existsSync$1, mkdirSync } from "node:fs";
|
|
9
9
|
import { stripVTControlCharacters, styleText } from "node:util";
|
|
10
10
|
import { ast } from "@kubb/ast";
|
|
11
11
|
import dns from "node:dns";
|
|
@@ -21,7 +21,7 @@ var __name = (target, value) => __defProp(target, "name", {
|
|
|
21
21
|
configurable: true
|
|
22
22
|
});
|
|
23
23
|
// package.json
|
|
24
|
-
var version = "5.18.
|
|
24
|
+
var version = "5.18.8";
|
|
25
25
|
// ../../internals/utils/src/casing.ts
|
|
26
26
|
/**
|
|
27
27
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -196,7 +196,25 @@ async function exists(path) {
|
|
|
196
196
|
*/
|
|
197
197
|
async function read(path) {
|
|
198
198
|
if (runtime.isBun) return Bun.file(path).text();
|
|
199
|
-
return readFile(path, { encoding: "utf8" });
|
|
199
|
+
return new Promise((resolvePromise, reject) => readFile(path, { encoding: "utf8" }, (error, data) => error ? reject(error) : resolvePromise(data)));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Reads the file at `path` as a UTF-8 string, or `null` when it does not exist or cannot be read.
|
|
203
|
+
* Uses `Bun.file().text()` when running under Bun, `fs.readFileSync` otherwise.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const stored = await readIfExists('./src/gen/Pet.ts') // null on a first run
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
async function readIfExists(path) {
|
|
211
|
+
if (runtime.isBun) return Bun.file(path).text().catch(() => null);
|
|
212
|
+
if (!existsSync$1(path)) return null;
|
|
213
|
+
try {
|
|
214
|
+
return readFileSync(path, "utf8");
|
|
215
|
+
} catch (_error) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
200
218
|
}
|
|
201
219
|
/**
|
|
202
220
|
* Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact
|
|
@@ -231,7 +249,7 @@ async function write(path, data, options = {}) {
|
|
|
231
249
|
const content = `${trimmed}\n`;
|
|
232
250
|
const resolved = resolve(path);
|
|
233
251
|
if (matchesStored({
|
|
234
|
-
stored: (options.stored === void 0 ? await
|
|
252
|
+
stored: (options.stored === void 0 ? await readIfExists(resolved) : options.stored) ?? "",
|
|
235
253
|
source: trimmed
|
|
236
254
|
})) return null;
|
|
237
255
|
await writeRaw(resolved, content);
|
|
@@ -256,11 +274,11 @@ async function writeRaw(path, content) {
|
|
|
256
274
|
return;
|
|
257
275
|
}
|
|
258
276
|
try {
|
|
259
|
-
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
277
|
+
await new Promise((resolvePromise, reject) => writeFile(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
260
278
|
} catch (error) {
|
|
261
279
|
if (error.code !== "ENOENT") throw error;
|
|
262
|
-
await mkdir(dirname(resolved), { recursive: true });
|
|
263
|
-
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
280
|
+
await mkdir$1(dirname(resolved), { recursive: true });
|
|
281
|
+
await new Promise((resolvePromise, reject) => writeFile(resolved, content, { encoding: "utf-8" }, (error) => error ? reject(error) : resolvePromise()));
|
|
264
282
|
}
|
|
265
283
|
}
|
|
266
284
|
/**
|
|
@@ -334,12 +352,33 @@ function isPathInside(path, parent) {
|
|
|
334
352
|
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
335
353
|
*/
|
|
336
354
|
function memo$1(store, key, compute) {
|
|
337
|
-
|
|
355
|
+
const cached = store.get(key);
|
|
356
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
338
357
|
const value = compute();
|
|
339
358
|
store.set(key, value);
|
|
340
359
|
return value;
|
|
341
360
|
}
|
|
342
361
|
__name(memo$1, "memo");
|
|
362
|
+
function createStore({ type }) {
|
|
363
|
+
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
364
|
+
const entry = /* @__PURE__ */ new Map();
|
|
365
|
+
if (type === "map") return entry;
|
|
366
|
+
const set = (key, value) => {
|
|
367
|
+
entry.clear();
|
|
368
|
+
entry.set(key, value);
|
|
369
|
+
};
|
|
370
|
+
const touch = (key) => {
|
|
371
|
+
if (!entry.has(key)) return false;
|
|
372
|
+
set(key, entry.get(key));
|
|
373
|
+
return true;
|
|
374
|
+
};
|
|
375
|
+
return {
|
|
376
|
+
has: touch,
|
|
377
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
378
|
+
set
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
memo$1.create = createStore;
|
|
343
382
|
/**
|
|
344
383
|
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
345
384
|
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
@@ -549,7 +588,7 @@ const diagnosticCatalog = {
|
|
|
549
588
|
code: "KUBB_INVALID_DOCUMENT",
|
|
550
589
|
title: "Invalid document",
|
|
551
590
|
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.",
|
|
552
|
-
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
|
|
591
|
+
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."
|
|
553
592
|
},
|
|
554
593
|
invalidSpec: {
|
|
555
594
|
code: "KUBB_INVALID_SPEC",
|
|
@@ -674,8 +713,8 @@ const diagnosticCatalog = {
|
|
|
674
713
|
invalidPluginOptions: {
|
|
675
714
|
code: "KUBB_INVALID_PLUGIN_OPTIONS",
|
|
676
715
|
title: "Invalid plugin options",
|
|
677
|
-
cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.",
|
|
678
|
-
fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or
|
|
716
|
+
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.",
|
|
717
|
+
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'`."
|
|
679
718
|
},
|
|
680
719
|
postGenerateFailed: {
|
|
681
720
|
code: "KUBB_POST_GENERATE_FAILED",
|
|
@@ -1573,8 +1612,8 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
|
|
|
1573
1612
|
authorization
|
|
1574
1613
|
}) : {};
|
|
1575
1614
|
const fetchConfig = publicOnly ? await resolvePublicFetchConfig(repo, signal) : [];
|
|
1576
|
-
const dir = await mkdtemp(join(tmpdir(), "kubb-git-"));
|
|
1577
|
-
const dispose = () => rm(dir, {
|
|
1615
|
+
const dir = await mkdtemp$1(join(tmpdir(), "kubb-git-"));
|
|
1616
|
+
const dispose = () => rm$1(dir, {
|
|
1578
1617
|
recursive: true,
|
|
1579
1618
|
force: true
|
|
1580
1619
|
});
|
|
@@ -1718,11 +1757,16 @@ function inputToAdapterSource(config) {
|
|
|
1718
1757
|
}
|
|
1719
1758
|
// src/resolveOptions.ts
|
|
1720
1759
|
const patterns = /* @__PURE__ */ new Map();
|
|
1760
|
+
const methodPatterns = /* @__PURE__ */ new Map();
|
|
1721
1761
|
const nodeCaches = /* @__PURE__ */ new WeakMap();
|
|
1722
1762
|
function testPattern(value, pattern) {
|
|
1723
1763
|
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1724
1764
|
return value.match(pattern) !== null;
|
|
1725
1765
|
}
|
|
1766
|
+
function testMethod(method, pattern) {
|
|
1767
|
+
if (typeof pattern === "string") return memo$1(methodPatterns, pattern, () => new RegExp(pattern, "i")).test(method);
|
|
1768
|
+
return method.match(pattern.ignoreCase ? pattern : new RegExp(pattern.source, `${pattern.flags}i`)) !== null;
|
|
1769
|
+
}
|
|
1726
1770
|
function matchesOperation(node, filter) {
|
|
1727
1771
|
if (filter.type === "extension") {
|
|
1728
1772
|
const { extensions } = node;
|
|
@@ -1732,7 +1776,7 @@ function matchesOperation(node, filter) {
|
|
|
1732
1776
|
if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
|
|
1733
1777
|
if (type === "operationId") return testPattern(node.operationId, pattern);
|
|
1734
1778
|
if (type === "path") return node.path !== void 0 && testPattern(node.path, pattern);
|
|
1735
|
-
if (type === "method") return node.method !== void 0 &&
|
|
1779
|
+
if (type === "method") return node.method !== void 0 && testMethod(node.method, pattern);
|
|
1736
1780
|
if (type === "contentType") return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false;
|
|
1737
1781
|
return false;
|
|
1738
1782
|
}
|
|
@@ -1781,6 +1825,7 @@ function isNamespace(value) {
|
|
|
1781
1825
|
* reachable and a `file` override is never dropped.
|
|
1782
1826
|
*/
|
|
1783
1827
|
const resolverOptions = Symbol.for("@kubb/core/resolver/options");
|
|
1828
|
+
const createNameNode = () => ({ next: /* @__PURE__ */ new Map() });
|
|
1784
1829
|
/**
|
|
1785
1830
|
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
1786
1831
|
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
@@ -1846,6 +1891,10 @@ var Resolver = class Resolver {
|
|
|
1846
1891
|
#options;
|
|
1847
1892
|
#memo = /* @__PURE__ */ new Map();
|
|
1848
1893
|
#usedNames = /* @__PURE__ */ new Set();
|
|
1894
|
+
#stringNames = /* @__PURE__ */ new Map();
|
|
1895
|
+
#arrayNames = createNameNode();
|
|
1896
|
+
#outputDirs = /* @__PURE__ */ new WeakMap();
|
|
1897
|
+
#importPaths = /* @__PURE__ */ new WeakMap();
|
|
1849
1898
|
#tagParents = /* @__PURE__ */ new Map();
|
|
1850
1899
|
#baseName;
|
|
1851
1900
|
#filePath;
|
|
@@ -1912,16 +1961,30 @@ var Resolver = class Resolver {
|
|
|
1912
1961
|
* ```
|
|
1913
1962
|
*/
|
|
1914
1963
|
resolveName({ key, name, normalize = (name) => name }) {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1964
|
+
if (typeof key === "string") return memo$1(this.#stringNames, key, () => this.#allocateName({
|
|
1965
|
+
name,
|
|
1966
|
+
normalize,
|
|
1967
|
+
suffix: 1
|
|
1968
|
+
}));
|
|
1969
|
+
const node = key.reduce((parent, segment) => memo$1(parent.next, segment, createNameNode), this.#arrayNames);
|
|
1970
|
+
node.name ??= this.#allocateName({
|
|
1971
|
+
name,
|
|
1972
|
+
normalize,
|
|
1973
|
+
suffix: 1
|
|
1974
|
+
});
|
|
1975
|
+
return node.name;
|
|
1976
|
+
}
|
|
1977
|
+
#allocateName({ name, normalize, suffix }) {
|
|
1978
|
+
const candidate = suffix === 1 ? name : `${name}${suffix}`;
|
|
1979
|
+
const normalized = normalize(candidate);
|
|
1980
|
+
const names = typeof normalized === "string" ? [normalized] : normalized;
|
|
1981
|
+
if (names.some((emittedName) => this.#usedNames.has(emittedName))) return this.#allocateName({
|
|
1982
|
+
name,
|
|
1983
|
+
normalize,
|
|
1984
|
+
suffix: suffix + 1
|
|
1985
|
+
});
|
|
1986
|
+
this.reserveNames(names);
|
|
1987
|
+
return candidate;
|
|
1925
1988
|
}
|
|
1926
1989
|
file(options) {
|
|
1927
1990
|
return this.#resolveFile(options);
|
|
@@ -1938,17 +2001,17 @@ var Resolver = class Resolver {
|
|
|
1938
2001
|
* reads the same ref set instead of re-scanning it per plugin.
|
|
1939
2002
|
*/
|
|
1940
2003
|
imports(options) {
|
|
1941
|
-
const { node, root, output,
|
|
2004
|
+
const { node, root, output, extname = ".ts", name, checks } = options;
|
|
1942
2005
|
const resolveName = name ?? ((schemaName) => this.name(schemaName));
|
|
2006
|
+
const paths = memo$1(memo$1(memo$1(this.#importPaths, output, () => /* @__PURE__ */ new Map()), root, () => /* @__PURE__ */ new Map()), extname, () => /* @__PURE__ */ new Map());
|
|
1943
2007
|
return ast.graph.getImportedNames(node, { checks }).map((schemaName) => ast.factory.createImport({
|
|
1944
2008
|
name: [resolveName(schemaName)],
|
|
1945
|
-
path: this.#resolveFilePath({
|
|
2009
|
+
path: memo$1(paths, schemaName, () => this.#resolveFilePath({
|
|
1946
2010
|
name: schemaName,
|
|
1947
2011
|
extname,
|
|
1948
2012
|
root,
|
|
1949
|
-
output
|
|
1950
|
-
|
|
1951
|
-
})
|
|
2013
|
+
output
|
|
2014
|
+
}))
|
|
1952
2015
|
}));
|
|
1953
2016
|
}
|
|
1954
2017
|
/**
|
|
@@ -2020,8 +2083,8 @@ var Resolver = class Resolver {
|
|
|
2020
2083
|
* are provided.
|
|
2021
2084
|
*/
|
|
2022
2085
|
#resolvePath({ baseName, tag, path: groupPath, root, output, group }) {
|
|
2023
|
-
|
|
2024
|
-
|
|
2086
|
+
const outputDir = memo$1(memo$1(this.#outputDirs, output, () => /* @__PURE__ */ new Map()), root, () => path.resolve(root, output.path));
|
|
2087
|
+
if (output.mode !== "directory") return outputDir;
|
|
2025
2088
|
const groupValue = group?.type === "path" ? groupPath : tag;
|
|
2026
2089
|
const result = group && groupValue ? path.resolve(outputDir, this.groupDir(group, groupValue), baseName) : path.resolve(outputDir, baseName);
|
|
2027
2090
|
assertInside({
|
|
@@ -2035,15 +2098,15 @@ var Resolver = class Resolver {
|
|
|
2035
2098
|
/**
|
|
2036
2099
|
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
2037
2100
|
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
2038
|
-
* spec-derived values from writing outside the
|
|
2101
|
+
* spec-derived values from writing outside the output directory.
|
|
2039
2102
|
*/
|
|
2040
2103
|
#resolveOverridePath(filePath, root) {
|
|
2041
2104
|
const resolved = path.resolve(root, filePath);
|
|
2042
2105
|
assertInside({
|
|
2043
2106
|
target: resolved,
|
|
2044
2107
|
parent: root,
|
|
2045
|
-
message: `Resolved path "${resolved}" is outside the
|
|
2046
|
-
help: "A resolver `file.path` must return a path inside the
|
|
2108
|
+
message: `Resolved path "${resolved}" is outside the output directory "${root}".`,
|
|
2109
|
+
help: "A resolver `file.path` must return a path inside the output directory (`config.output.path`)."
|
|
2047
2110
|
});
|
|
2048
2111
|
return resolved;
|
|
2049
2112
|
}
|
|
@@ -2186,7 +2249,7 @@ var Resolver = class Resolver {
|
|
|
2186
2249
|
function createResolver(options) {
|
|
2187
2250
|
return new Resolver(options);
|
|
2188
2251
|
}
|
|
2189
|
-
// \0@oxc-project+runtime@0.
|
|
2252
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/usingCtx.js
|
|
2190
2253
|
function _usingCtx() {
|
|
2191
2254
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
2192
2255
|
var n = Error();
|
|
@@ -2263,7 +2326,7 @@ function runParser(parser, print) {
|
|
|
2263
2326
|
* Reads a `copy` file and prints it through the parser's `copy` hook, or verbatim with `banner`/`footer` when there is none.
|
|
2264
2327
|
*/
|
|
2265
2328
|
async function parseCopy(file, parser) {
|
|
2266
|
-
const content = await readFile(file.copy, "utf8").catch((err) => {
|
|
2329
|
+
const content = await readFile$1(file.copy, "utf8").catch((err) => {
|
|
2267
2330
|
throw new Diagnostics.Error({
|
|
2268
2331
|
code: Diagnostics.code.pluginFailed,
|
|
2269
2332
|
severity: "error",
|
|
@@ -2299,7 +2362,8 @@ function compareFiles(a, b) {
|
|
|
2299
2362
|
/**
|
|
2300
2363
|
* Writes `source` to `file.path` unless the storage already holds it, either verbatim or, per the
|
|
2301
2364
|
* manifest, as what the output passes make of it. Checking here rather than in a driver gives a
|
|
2302
|
-
* storage writing to S3 or a database the same guarantee `fsStorage` has. `false` when
|
|
2365
|
+
* storage writing to S3 or a database the same guarantee `fsStorage` has. `written` is `false` when
|
|
2366
|
+
* skipped, and `stored` is what the storage held before the write.
|
|
2303
2367
|
*/
|
|
2304
2368
|
async function writeChanged({ storage, manifest, file, source, signal, cleaned }) {
|
|
2305
2369
|
signal?.throwIfAborted();
|
|
@@ -2311,14 +2375,20 @@ async function writeChanged({ storage, manifest, file, source, signal, cleaned }
|
|
|
2311
2375
|
key: file.path,
|
|
2312
2376
|
source,
|
|
2313
2377
|
disk: stored
|
|
2314
|
-
}))) return
|
|
2378
|
+
}))) return {
|
|
2379
|
+
written: false,
|
|
2380
|
+
stored
|
|
2381
|
+
};
|
|
2315
2382
|
signal?.throwIfAborted();
|
|
2316
2383
|
await storage.writeItem(file.path, source, { stored });
|
|
2317
2384
|
manifest?.track({
|
|
2318
2385
|
key: file.path,
|
|
2319
2386
|
source
|
|
2320
2387
|
});
|
|
2321
|
-
return
|
|
2388
|
+
return {
|
|
2389
|
+
written: true,
|
|
2390
|
+
stored
|
|
2391
|
+
};
|
|
2322
2392
|
}
|
|
2323
2393
|
/** Reports finished files in input order: each finished file flushes the run of finished files ahead of it as one update. */
|
|
2324
2394
|
function createProgress(files, config, hooks) {
|
|
@@ -2478,7 +2548,7 @@ var FileManager = class {
|
|
|
2478
2548
|
* memory rather than holding every source, while still overlapping each file's write with the
|
|
2479
2549
|
* next file's parse. Files finish in whatever order they parse, so each finished file flushes the
|
|
2480
2550
|
* run of finished files ahead of it as one `kubb:files:processing:update`, keeping rows in input order.
|
|
2481
|
-
* Each parsed source goes out once on `kubb:file:processed`,
|
|
2551
|
+
* Each parsed source goes out once on `kubb:file:processed`, next to what the storage held before the write.
|
|
2482
2552
|
*
|
|
2483
2553
|
* A file the storage already holds is skipped, so a rebuild that generates identical output
|
|
2484
2554
|
* writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
|
|
@@ -2496,17 +2566,19 @@ var FileManager = class {
|
|
|
2496
2566
|
signal?.throwIfAborted();
|
|
2497
2567
|
const source = await this.parse(file, { parsers });
|
|
2498
2568
|
if (source) {
|
|
2499
|
-
|
|
2569
|
+
const { written, stored } = await writeChanged({
|
|
2500
2570
|
storage,
|
|
2501
2571
|
manifest,
|
|
2502
2572
|
file,
|
|
2503
2573
|
source,
|
|
2504
2574
|
signal,
|
|
2505
2575
|
cleaned
|
|
2506
|
-
})
|
|
2576
|
+
});
|
|
2577
|
+
if (!written) unchanged.push(file.path);
|
|
2507
2578
|
await hooks?.callHook("kubb:file:processed", {
|
|
2508
2579
|
file,
|
|
2509
|
-
source
|
|
2580
|
+
source,
|
|
2581
|
+
stored
|
|
2510
2582
|
});
|
|
2511
2583
|
}
|
|
2512
2584
|
await progress?.(index);
|
|
@@ -2556,6 +2628,22 @@ function normalizePluginOptions(rawOptions, pluginName) {
|
|
|
2556
2628
|
group,
|
|
2557
2629
|
pluginName
|
|
2558
2630
|
});
|
|
2631
|
+
options.override = options.override?.map((entry) => {
|
|
2632
|
+
const { output } = entry.options;
|
|
2633
|
+
if (!output) return entry;
|
|
2634
|
+
const entryGroup = "group" in entry.options ? entry.options.group : group;
|
|
2635
|
+
return {
|
|
2636
|
+
...entry,
|
|
2637
|
+
options: {
|
|
2638
|
+
...entry.options,
|
|
2639
|
+
output: normalizeOutput({
|
|
2640
|
+
output,
|
|
2641
|
+
group: entryGroup,
|
|
2642
|
+
pluginName
|
|
2643
|
+
})
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
});
|
|
2559
2647
|
return options;
|
|
2560
2648
|
}
|
|
2561
2649
|
/**
|
|
@@ -3367,11 +3455,7 @@ const createStorage = (build) => (options) => build(options ?? {});
|
|
|
3367
3455
|
const fsStorage = createStorage(() => ({
|
|
3368
3456
|
name: "fs",
|
|
3369
3457
|
async readItem(key) {
|
|
3370
|
-
|
|
3371
|
-
return await read(resolve(key));
|
|
3372
|
-
} catch (_error) {
|
|
3373
|
-
return null;
|
|
3374
|
-
}
|
|
3458
|
+
return readIfExists(resolve(key));
|
|
3375
3459
|
},
|
|
3376
3460
|
async writeItem(key, value, options) {
|
|
3377
3461
|
await write(resolve(key), value, {
|
|
@@ -3380,7 +3464,7 @@ const fsStorage = createStorage(() => ({
|
|
|
3380
3464
|
});
|
|
3381
3465
|
},
|
|
3382
3466
|
async removeItem(key) {
|
|
3383
|
-
await rm
|
|
3467
|
+
await rm(resolve(key), { force: true });
|
|
3384
3468
|
},
|
|
3385
3469
|
async readKeys(base) {
|
|
3386
3470
|
return Array.fromAsync(listFiles(resolve(base ?? process.cwd()))).catch(() => []);
|
|
@@ -3393,14 +3477,14 @@ const fsStorage = createStorage(() => ({
|
|
|
3393
3477
|
try {
|
|
3394
3478
|
await rename(dir, join(parent, `${prefix}${process.pid}-${Date.now()}`));
|
|
3395
3479
|
} catch (_error) {
|
|
3396
|
-
await rm
|
|
3480
|
+
await rm(dir, {
|
|
3397
3481
|
recursive: true,
|
|
3398
3482
|
force: true
|
|
3399
3483
|
});
|
|
3400
3484
|
return;
|
|
3401
3485
|
}
|
|
3402
3486
|
const trash = (await readdir(parent)).filter((name) => name.startsWith(prefix));
|
|
3403
|
-
Promise.all(trash.map((name) => rm
|
|
3487
|
+
Promise.all(trash.map((name) => rm(join(parent, name), {
|
|
3404
3488
|
recursive: true,
|
|
3405
3489
|
force: true
|
|
3406
3490
|
}))).catch(() => {});
|
|
@@ -3418,7 +3502,7 @@ const fsStorage = createStorage(() => ({
|
|
|
3418
3502
|
*/
|
|
3419
3503
|
function resolveCacheDir(root) {
|
|
3420
3504
|
const nodeModules = join(root, "node_modules");
|
|
3421
|
-
if (existsSync
|
|
3505
|
+
if (existsSync(nodeModules)) return join(nodeModules, ".cache", "kubb");
|
|
3422
3506
|
return join(tmpdir(), "kubb", hash("sha256", root).slice(0, 16));
|
|
3423
3507
|
}
|
|
3424
3508
|
/**
|
|
@@ -3657,7 +3741,7 @@ async function runToolPass({ pass, setting, outputPath, hooks, cwd, signal }) {
|
|
|
3657
3741
|
}
|
|
3658
3742
|
if (setting === "auto") await hooks.callHook("kubb:info", { message: `Auto-detected ${pass.label}: ${styleText("dim", detected)}` });
|
|
3659
3743
|
const tool = pass.tools[detected];
|
|
3660
|
-
if (!tool || !existsSync(outputPath)) return null;
|
|
3744
|
+
if (!tool || !existsSync$1(outputPath)) return null;
|
|
3661
3745
|
const result = await runHook({
|
|
3662
3746
|
hooks,
|
|
3663
3747
|
command: tool.command,
|
|
@@ -3786,7 +3870,7 @@ function hasOutputPasses({ output, storage }) {
|
|
|
3786
3870
|
* const { files, diagnostics } = await kubb.safeBuild()
|
|
3787
3871
|
* ```
|
|
3788
3872
|
*/
|
|
3789
|
-
var Kubb = class {
|
|
3873
|
+
var Kubb = class Kubb {
|
|
3790
3874
|
hooks;
|
|
3791
3875
|
config;
|
|
3792
3876
|
#driver = null;
|
|
@@ -3797,6 +3881,34 @@ var Kubb = class {
|
|
|
3797
3881
|
this.hooks = options.hooks ?? new Hookable();
|
|
3798
3882
|
this.#signal = options.signal;
|
|
3799
3883
|
}
|
|
3884
|
+
/**
|
|
3885
|
+
* Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
|
|
3886
|
+
* memory holds one config at a time. A config that fails does not stop the others. Only an aborted `signal` rejects.
|
|
3887
|
+
*/
|
|
3888
|
+
static async *generate(configs, { hooks = new Hookable(), signal } = {}) {
|
|
3889
|
+
for (const config of configs) {
|
|
3890
|
+
const kubb = new Kubb(config, {
|
|
3891
|
+
hooks,
|
|
3892
|
+
signal
|
|
3893
|
+
});
|
|
3894
|
+
try {
|
|
3895
|
+
yield {
|
|
3896
|
+
...await kubb.generate(),
|
|
3897
|
+
kubb
|
|
3898
|
+
};
|
|
3899
|
+
} catch (error) {
|
|
3900
|
+
if (signal?.aborted) throw error;
|
|
3901
|
+
yield {
|
|
3902
|
+
success: false,
|
|
3903
|
+
files: [],
|
|
3904
|
+
diagnostics: [Diagnostics.from(error)],
|
|
3905
|
+
input: null,
|
|
3906
|
+
kubb,
|
|
3907
|
+
error
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3800
3912
|
get storage() {
|
|
3801
3913
|
return this.config.storage;
|
|
3802
3914
|
}
|
|
@@ -3867,7 +3979,8 @@ var Kubb = class {
|
|
|
3867
3979
|
diagnostics,
|
|
3868
3980
|
files: driver.fileManager.files,
|
|
3869
3981
|
driver,
|
|
3870
|
-
storage
|
|
3982
|
+
storage,
|
|
3983
|
+
input: driver.inputNode
|
|
3871
3984
|
};
|
|
3872
3985
|
} catch (_) {
|
|
3873
3986
|
_usingCtx$1.e = _;
|
|
@@ -3903,15 +4016,16 @@ var Kubb = class {
|
|
|
3903
4016
|
if (signal?.aborted) throw caughtError;
|
|
3904
4017
|
output = {
|
|
3905
4018
|
files: [],
|
|
3906
|
-
diagnostics: [Diagnostics.from(caughtError)]
|
|
4019
|
+
diagnostics: [Diagnostics.from(caughtError)],
|
|
4020
|
+
input: null
|
|
3907
4021
|
};
|
|
3908
4022
|
}
|
|
3909
|
-
const { files, diagnostics } = output;
|
|
4023
|
+
const { files, diagnostics, input } = output;
|
|
3910
4024
|
const storage = this.storage;
|
|
3911
4025
|
signal?.throwIfAborted();
|
|
3912
4026
|
for (const diagnostic of diagnostics) if (Diagnostics.isProblem(diagnostic)) await Diagnostics.emit(hooks, diagnostic);
|
|
3913
4027
|
if (Diagnostics.hasError(diagnostics)) {
|
|
3914
|
-
await
|
|
4028
|
+
await this.#end({
|
|
3915
4029
|
config,
|
|
3916
4030
|
storage,
|
|
3917
4031
|
diagnostics,
|
|
@@ -3922,7 +4036,8 @@ var Kubb = class {
|
|
|
3922
4036
|
return {
|
|
3923
4037
|
success: false,
|
|
3924
4038
|
files,
|
|
3925
|
-
diagnostics
|
|
4039
|
+
diagnostics,
|
|
4040
|
+
input
|
|
3926
4041
|
};
|
|
3927
4042
|
}
|
|
3928
4043
|
const processOutput = options.processOutput ?? runOutputPasses;
|
|
@@ -3935,7 +4050,7 @@ var Kubb = class {
|
|
|
3935
4050
|
const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
|
|
3936
4051
|
const failed = Diagnostics.hasError(outputDiagnostics);
|
|
3937
4052
|
if (!failed) await this.#manifest?.commit();
|
|
3938
|
-
await
|
|
4053
|
+
await this.#end({
|
|
3939
4054
|
config,
|
|
3940
4055
|
storage,
|
|
3941
4056
|
diagnostics: finalDiagnostics,
|
|
@@ -3946,11 +4061,23 @@ var Kubb = class {
|
|
|
3946
4061
|
return {
|
|
3947
4062
|
success: !failed,
|
|
3948
4063
|
files,
|
|
3949
|
-
diagnostics: finalDiagnostics
|
|
4064
|
+
diagnostics: finalDiagnostics,
|
|
4065
|
+
input
|
|
3950
4066
|
};
|
|
3951
4067
|
}
|
|
4068
|
+
/** Ends a run: `kubb:generation:end`, then the totals on `kubb:generation:summary`. */
|
|
4069
|
+
async #end(ctx) {
|
|
4070
|
+
await this.hooks.callHook("kubb:generation:end", ctx);
|
|
4071
|
+
await this.hooks.callHook("kubb:generation:summary", {
|
|
4072
|
+
duration: Math.round(getElapsedMs(ctx.hrStart)),
|
|
4073
|
+
fileCount: ctx.filesCreated,
|
|
4074
|
+
failedPlugins: Diagnostics.failedPlugins(ctx.diagnostics).length,
|
|
4075
|
+
status: ctx.status
|
|
4076
|
+
});
|
|
4077
|
+
}
|
|
3952
4078
|
dispose() {
|
|
3953
4079
|
this.#driver?.dispose();
|
|
4080
|
+
this.#driver = null;
|
|
3954
4081
|
}
|
|
3955
4082
|
[Symbol.dispose]() {
|
|
3956
4083
|
this.dispose();
|
|
@@ -4085,7 +4212,7 @@ function kubbStorage({ base } = {}) {
|
|
|
4085
4212
|
await writeRaw(pathOf(key), typeof value === "string" ? value : JSON.stringify(value));
|
|
4086
4213
|
},
|
|
4087
4214
|
async removeItem(key) {
|
|
4088
|
-
await rm
|
|
4215
|
+
await rm(pathOf(key), { force: true });
|
|
4089
4216
|
}
|
|
4090
4217
|
};
|
|
4091
4218
|
}
|
|
@@ -4523,7 +4650,7 @@ function isRegistryEntry(value) {
|
|
|
4523
4650
|
}
|
|
4524
4651
|
// src/installedPackages.ts
|
|
4525
4652
|
/** Reads and parses a JSON file. Throws when it is missing or not JSON. */
|
|
4526
|
-
const readJSON = async (file) => JSON.parse(await readFile(file, "utf8"));
|
|
4653
|
+
const readJSON = async (file) => JSON.parse(await readFile$1(file, "utf8"));
|
|
4527
4654
|
/**
|
|
4528
4655
|
* The `dependencies` and `devDependencies` of the project at `root`, plus `packages`, with the
|
|
4529
4656
|
* installed version and the valid `kubb-extension.json` each one ships, when it does. A package
|
|
@@ -4542,7 +4669,7 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4542
4669
|
const packageJSON = await readJSON(path.join(root, "package.json")).catch(() => null);
|
|
4543
4670
|
const dependencies = [packageJSON?.dependencies, packageJSON?.devDependencies].flatMap((record) => typeof record === "object" && record !== null ? Object.keys(record) : []);
|
|
4544
4671
|
return Promise.all([.../* @__PURE__ */ new Set([...dependencies, ...packages])].filter(isPackageName).map(async (name) => {
|
|
4545
|
-
const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync(path.join(dir, "package.json")));
|
|
4672
|
+
const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync$1(path.join(dir, "package.json")));
|
|
4546
4673
|
if (!dir) return { package: name };
|
|
4547
4674
|
try {
|
|
4548
4675
|
const { version } = await readJSON(path.join(dir, "package.json"));
|
|
@@ -4557,6 +4684,6 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4557
4684
|
}
|
|
4558
4685
|
}));
|
|
4559
4686
|
}
|
|
4560
|
-
export { Diagnostics, Hookable, KubbDriver, Resolver, addGenerator, addMacro, assertPluginOption, cacheStorage, camelCase, checkCompatibility, checkoutGitInput, cliReporter, createAdapter, createCliReporter, createKubb, createOutputManifest, createRenderer, createReporter, createResolver, createStorage, defineExtension, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, hasOutputPasses, htmlReporter, injectFile, isExtensionManifest, isPackageName, isPublicAddress, isRegistryEntry, jsonReporter, kubbContext, kubbStorage, logLevel, manifestProblems, memo, memoryStorage, pascalCase, readInstalledPackages, requirePlugin, resolveCacheDir, resolveKubbDir, resolveMeta, runHook, runOutputPasses, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
|
|
4687
|
+
export { Diagnostics, Hookable, Kubb, KubbDriver, Resolver, addGenerator, addMacro, assertPluginOption, cacheStorage, camelCase, checkCompatibility, checkoutGitInput, cliReporter, createAdapter, createCliReporter, createKubb, createOutputManifest, createRenderer, createReporter, createResolver, createStorage, defineExtension, defineGenerator, defineParser, definePlugin, fileReporter, fsStorage, getInputKind, hasOutputPasses, htmlReporter, injectFile, isExtensionManifest, isPackageName, isPublicAddress, isRegistryEntry, jsonReporter, kubbContext, kubbStorage, logLevel, manifestProblems, memo, memoryStorage, pascalCase, readInstalledPackages, requirePlugin, resolveCacheDir, resolveKubbDir, resolveMeta, runHook, runOutputPasses, setMacros, setOptions, setResolver, tryUseKubb, useConfig, useKubb, useOptions };
|
|
4561
4688
|
|
|
4562
4689
|
//# sourceMappingURL=index.js.map
|