@kubb/core 5.18.5 → 5.18.7
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 +104 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -20
- package/dist/index.d.ts +48 -20
- package/dist/index.js +116 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3,11 +3,11 @@ 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 { access, glob, mkdir, mkdtemp, readFile, readdir, rename, rm, rm as rm$1, writeFile } from "node:fs/promises";
|
|
6
|
+
import { access, glob, mkdir as mkdir$1, mkdtemp as mkdtemp$1, readFile, readdir, rename, rm, rm as rm$1, writeFile } from "node:fs/promises";
|
|
7
7
|
import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
8
|
import { chmodSync, existsSync, existsSync as existsSync$1, mkdirSync } from "node:fs";
|
|
9
9
|
import { stripVTControlCharacters, styleText } from "node:util";
|
|
10
|
-
import { ast
|
|
10
|
+
import { ast } from "@kubb/ast";
|
|
11
11
|
import dns from "node:dns";
|
|
12
12
|
import net from "node:net";
|
|
13
13
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -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.7";
|
|
25
25
|
// ../../internals/utils/src/casing.ts
|
|
26
26
|
/**
|
|
27
27
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -259,7 +259,7 @@ async function writeRaw(path, content) {
|
|
|
259
259
|
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
260
260
|
} catch (error) {
|
|
261
261
|
if (error.code !== "ENOENT") throw error;
|
|
262
|
-
await mkdir(dirname(resolved), { recursive: true });
|
|
262
|
+
await mkdir$1(dirname(resolved), { recursive: true });
|
|
263
263
|
await writeFile(resolved, content, { encoding: "utf-8" });
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -549,7 +549,7 @@ const diagnosticCatalog = {
|
|
|
549
549
|
code: "KUBB_INVALID_DOCUMENT",
|
|
550
550
|
title: "Invalid document",
|
|
551
551
|
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
|
|
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 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
553
|
},
|
|
554
554
|
invalidSpec: {
|
|
555
555
|
code: "KUBB_INVALID_SPEC",
|
|
@@ -674,8 +674,8 @@ const diagnosticCatalog = {
|
|
|
674
674
|
invalidPluginOptions: {
|
|
675
675
|
code: "KUBB_INVALID_PLUGIN_OPTIONS",
|
|
676
676
|
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
|
|
677
|
+
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.",
|
|
678
|
+
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
679
|
},
|
|
680
680
|
postGenerateFailed: {
|
|
681
681
|
code: "KUBB_POST_GENERATE_FAILED",
|
|
@@ -1573,8 +1573,8 @@ async function checkoutGitInput(input, signal, { publicOnly = false, authorizati
|
|
|
1573
1573
|
authorization
|
|
1574
1574
|
}) : {};
|
|
1575
1575
|
const fetchConfig = publicOnly ? await resolvePublicFetchConfig(repo, signal) : [];
|
|
1576
|
-
const dir = await mkdtemp(join(tmpdir(), "kubb-git-"));
|
|
1577
|
-
const dispose = () => rm(dir, {
|
|
1576
|
+
const dir = await mkdtemp$1(join(tmpdir(), "kubb-git-"));
|
|
1577
|
+
const dispose = () => rm$1(dir, {
|
|
1578
1578
|
recursive: true,
|
|
1579
1579
|
force: true
|
|
1580
1580
|
});
|
|
@@ -1718,11 +1718,16 @@ function inputToAdapterSource(config) {
|
|
|
1718
1718
|
}
|
|
1719
1719
|
// src/resolveOptions.ts
|
|
1720
1720
|
const patterns = /* @__PURE__ */ new Map();
|
|
1721
|
+
const methodPatterns = /* @__PURE__ */ new Map();
|
|
1721
1722
|
const nodeCaches = /* @__PURE__ */ new WeakMap();
|
|
1722
1723
|
function testPattern(value, pattern) {
|
|
1723
1724
|
if (typeof pattern === "string") return memo$1(patterns, pattern, () => new RegExp(pattern)).test(value);
|
|
1724
1725
|
return value.match(pattern) !== null;
|
|
1725
1726
|
}
|
|
1727
|
+
function testMethod(method, pattern) {
|
|
1728
|
+
if (typeof pattern === "string") return memo$1(methodPatterns, pattern, () => new RegExp(pattern, "i")).test(method);
|
|
1729
|
+
return method.match(pattern.ignoreCase ? pattern : new RegExp(pattern.source, `${pattern.flags}i`)) !== null;
|
|
1730
|
+
}
|
|
1726
1731
|
function matchesOperation(node, filter) {
|
|
1727
1732
|
if (filter.type === "extension") {
|
|
1728
1733
|
const { extensions } = node;
|
|
@@ -1732,7 +1737,7 @@ function matchesOperation(node, filter) {
|
|
|
1732
1737
|
if (type === "tag") return node.tags.some((tag) => testPattern(tag, pattern));
|
|
1733
1738
|
if (type === "operationId") return testPattern(node.operationId, pattern);
|
|
1734
1739
|
if (type === "path") return node.path !== void 0 && testPattern(node.path, pattern);
|
|
1735
|
-
if (type === "method") return node.method !== void 0 &&
|
|
1740
|
+
if (type === "method") return node.method !== void 0 && testMethod(node.method, pattern);
|
|
1736
1741
|
if (type === "contentType") return node.requestBody?.content?.some((c) => testPattern(c.contentType, pattern)) ?? false;
|
|
1737
1742
|
return false;
|
|
1738
1743
|
}
|
|
@@ -1741,7 +1746,7 @@ function matchesSchema(node, filter) {
|
|
|
1741
1746
|
return null;
|
|
1742
1747
|
}
|
|
1743
1748
|
function computeOptions(node, { options, exclude = [], include, override = [] }) {
|
|
1744
|
-
if (node.kind === ast.
|
|
1749
|
+
if (node.kind === ast.node.kinds.operation) {
|
|
1745
1750
|
if (exclude.some((filter) => matchesOperation(node, filter))) return null;
|
|
1746
1751
|
if (include && !include.some((filter) => matchesOperation(node, filter))) return null;
|
|
1747
1752
|
return {
|
|
@@ -1749,7 +1754,7 @@ function computeOptions(node, { options, exclude = [], include, override = [] })
|
|
|
1749
1754
|
...override.find((filter) => matchesOperation(node, filter))?.options
|
|
1750
1755
|
};
|
|
1751
1756
|
}
|
|
1752
|
-
if (node.kind === ast.
|
|
1757
|
+
if (node.kind === ast.node.kinds.schema) {
|
|
1753
1758
|
if (exclude.some((filter) => matchesSchema(node, filter) === true)) return null;
|
|
1754
1759
|
if (include) {
|
|
1755
1760
|
const applicable = include.map((filter) => matchesSchema(node, filter)).filter((result) => result !== null);
|
|
@@ -1928,19 +1933,19 @@ var Resolver = class Resolver {
|
|
|
1928
1933
|
}
|
|
1929
1934
|
/**
|
|
1930
1935
|
* Builds one `ImportNode` per unique schema referenced in the tree, in first-occurrence
|
|
1931
|
-
* order. Each ref's target resolves through `
|
|
1936
|
+
* order. Each ref's target resolves through `ast.ref.getName`, so collision- or macro-renamed
|
|
1932
1937
|
* schemas (`targetName`) import the emitted name. Names and paths go through the top-level
|
|
1933
1938
|
* `name` and `file`, so import entries follow the plugin's conventions, and a per-call
|
|
1934
1939
|
* `name` override wins over both.
|
|
1935
1940
|
*
|
|
1936
|
-
* The subtree scan runs through `
|
|
1941
|
+
* The subtree scan runs through `ast.graph.getImportedNames`, which memoizes by node identity, so a
|
|
1937
1942
|
* schema shared across the ts, zod, and faker plugins is walked once and every plugin's resolver
|
|
1938
1943
|
* reads the same ref set instead of re-scanning it per plugin.
|
|
1939
1944
|
*/
|
|
1940
1945
|
imports(options) {
|
|
1941
1946
|
const { node, root, output, group, extname = ".ts", name, checks } = options;
|
|
1942
1947
|
const resolveName = name ?? ((schemaName) => this.name(schemaName));
|
|
1943
|
-
return
|
|
1948
|
+
return ast.graph.getImportedNames(node, { checks }).map((schemaName) => ast.factory.createImport({
|
|
1944
1949
|
name: [resolveName(schemaName)],
|
|
1945
1950
|
path: this.#resolveFilePath({
|
|
1946
1951
|
name: schemaName,
|
|
@@ -1994,11 +1999,17 @@ var Resolver = class Resolver {
|
|
|
1994
1999
|
}
|
|
1995
2000
|
}
|
|
1996
2001
|
/**
|
|
1997
|
-
* A custom `group.name` wins; otherwise `tag`
|
|
1998
|
-
* folders of its `parent` tags, and `path` groups use the first
|
|
1999
|
-
* when none remain, placing the file in the output root, kept safe by the caller's
|
|
2002
|
+
* The folder a group puts a file in, relative to the output directory. A custom `group.name` wins; otherwise `tag`
|
|
2003
|
+
* groups use the camelCased tag, nested in the folders of its `parent` tags, and `path` groups use the first
|
|
2004
|
+
* non-traversal segment (`''` when none remain, placing the file in the output root, kept safe by the caller's
|
|
2005
|
+
* boundary check).
|
|
2006
|
+
*
|
|
2007
|
+
* @example
|
|
2008
|
+
* ```ts
|
|
2009
|
+
* resolver.groupDir({ type: 'tag' }, 'pet store') // 'petStore'
|
|
2010
|
+
* ```
|
|
2000
2011
|
*/
|
|
2001
|
-
|
|
2012
|
+
groupDir(group, groupValue) {
|
|
2002
2013
|
if (group.name) return group.name({ group: groupValue });
|
|
2003
2014
|
if (group.type === "tag") {
|
|
2004
2015
|
const chain = [groupValue];
|
|
@@ -2017,7 +2028,7 @@ var Resolver = class Resolver {
|
|
|
2017
2028
|
if (output.mode !== "directory") return path.resolve(root, output.path);
|
|
2018
2029
|
const outputDir = path.resolve(root, output.path);
|
|
2019
2030
|
const groupValue = group?.type === "path" ? groupPath : tag;
|
|
2020
|
-
const result = group && groupValue ? path.resolve(outputDir, this
|
|
2031
|
+
const result = group && groupValue ? path.resolve(outputDir, this.groupDir(group, groupValue), baseName) : path.resolve(outputDir, baseName);
|
|
2021
2032
|
assertInside({
|
|
2022
2033
|
target: result,
|
|
2023
2034
|
parent: outputDir,
|
|
@@ -2029,15 +2040,15 @@ var Resolver = class Resolver {
|
|
|
2029
2040
|
/**
|
|
2030
2041
|
* Resolves a resolver-supplied full path (`file.path`) against `root`, bypassing `output.path`
|
|
2031
2042
|
* and `group`. The path may not escape `root`, which keeps a `file.path` that interpolates
|
|
2032
|
-
* spec-derived values from writing outside the
|
|
2043
|
+
* spec-derived values from writing outside the output directory.
|
|
2033
2044
|
*/
|
|
2034
2045
|
#resolveOverridePath(filePath, root) {
|
|
2035
2046
|
const resolved = path.resolve(root, filePath);
|
|
2036
2047
|
assertInside({
|
|
2037
2048
|
target: resolved,
|
|
2038
2049
|
parent: root,
|
|
2039
|
-
message: `Resolved path "${resolved}" is outside the
|
|
2040
|
-
help: "A resolver `file.path` must return a path inside the
|
|
2050
|
+
message: `Resolved path "${resolved}" is outside the output directory "${root}".`,
|
|
2051
|
+
help: "A resolver `file.path` must return a path inside the output directory (`config.output.path`)."
|
|
2041
2052
|
});
|
|
2042
2053
|
return resolved;
|
|
2043
2054
|
}
|
|
@@ -2180,7 +2191,7 @@ var Resolver = class Resolver {
|
|
|
2180
2191
|
function createResolver(options) {
|
|
2181
2192
|
return new Resolver(options);
|
|
2182
2193
|
}
|
|
2183
|
-
// \0@oxc-project+runtime@0.
|
|
2194
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/usingCtx.js
|
|
2184
2195
|
function _usingCtx() {
|
|
2185
2196
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
2186
2197
|
var n = Error();
|
|
@@ -2240,7 +2251,7 @@ function _usingCtx() {
|
|
|
2240
2251
|
};
|
|
2241
2252
|
}
|
|
2242
2253
|
function joinSources(file) {
|
|
2243
|
-
return file.sources.map((source) =>
|
|
2254
|
+
return file.sources.map((source) => ast.node.getText(source.nodes)).filter(Boolean).join("\n\n");
|
|
2244
2255
|
}
|
|
2245
2256
|
/** Runs a parser call and turns a crash into a `KUBB_PARSER_FAILED` diagnostic that names the parser. */
|
|
2246
2257
|
function runParser(parser, print) {
|
|
@@ -2550,6 +2561,22 @@ function normalizePluginOptions(rawOptions, pluginName) {
|
|
|
2550
2561
|
group,
|
|
2551
2562
|
pluginName
|
|
2552
2563
|
});
|
|
2564
|
+
options.override = options.override?.map((entry) => {
|
|
2565
|
+
const { output } = entry.options;
|
|
2566
|
+
if (!output) return entry;
|
|
2567
|
+
const entryGroup = "group" in entry.options ? entry.options.group : group;
|
|
2568
|
+
return {
|
|
2569
|
+
...entry,
|
|
2570
|
+
options: {
|
|
2571
|
+
...entry.options,
|
|
2572
|
+
output: normalizeOutput({
|
|
2573
|
+
output,
|
|
2574
|
+
group: entryGroup,
|
|
2575
|
+
pluginName
|
|
2576
|
+
})
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
});
|
|
2553
2580
|
return options;
|
|
2554
2581
|
}
|
|
2555
2582
|
/**
|
|
@@ -2572,7 +2599,7 @@ function assertPluginEntry(entry, index) {
|
|
|
2572
2599
|
* pointer into the input.
|
|
2573
2600
|
*/
|
|
2574
2601
|
function getCrashSite(node) {
|
|
2575
|
-
if (node.kind === ast.
|
|
2602
|
+
if (node.kind === ast.node.kinds.schema) return {
|
|
2576
2603
|
label: node.name ? `schema "${node.name}"` : "an inline schema",
|
|
2577
2604
|
location: node.pointer ? {
|
|
2578
2605
|
kind: "schema",
|
|
@@ -2672,7 +2699,7 @@ var KubbDriver = class {
|
|
|
2672
2699
|
* config are ignored here and surface later through `requirePlugin`.
|
|
2673
2700
|
*/
|
|
2674
2701
|
#sortPlugins(plugins) {
|
|
2675
|
-
const queue = [...plugins].sort((a, b) =>
|
|
2702
|
+
const queue = [...plugins].sort((a, b) => ast.macro.compareOrder(a.enforce, b.enforce));
|
|
2676
2703
|
const names = new Set(queue.map((plugin) => plugin.name));
|
|
2677
2704
|
const blockedBy = new Map(queue.map((plugin) => {
|
|
2678
2705
|
const dependencies = Array.isArray(plugin.dependencies) ? plugin.dependencies : Object.keys(plugin.dependencies ?? {});
|
|
@@ -2880,7 +2907,7 @@ var KubbDriver = class {
|
|
|
2880
2907
|
* (`kubb:plugins:end`) and the write see them.
|
|
2881
2908
|
*/
|
|
2882
2909
|
#inlineFiles(parsers) {
|
|
2883
|
-
const { files, virtualPaths, problems } = ast.
|
|
2910
|
+
const { files, virtualPaths, problems } = ast.file.inline(this.fileManager.files, { language: (file) => parsers.get(file.extname)?.inline });
|
|
2884
2911
|
if (virtualPaths.length === 0) return;
|
|
2885
2912
|
this.fileManager.add(...files);
|
|
2886
2913
|
this.fileManager.delete(...virtualPaths);
|
|
@@ -2967,7 +2994,7 @@ var KubbDriver = class {
|
|
|
2967
2994
|
include,
|
|
2968
2995
|
override
|
|
2969
2996
|
}) !== null);
|
|
2970
|
-
allowedSchemaNamesByPlugin.set(plugin.name,
|
|
2997
|
+
allowedSchemaNamesByPlugin.set(plugin.name, ast.graph.getUsedNames(includedOps, schemas));
|
|
2971
2998
|
}
|
|
2972
2999
|
const states = entries.map(({ plugin, context, hrStart }) => {
|
|
2973
3000
|
const generatorContext = {
|
|
@@ -2995,7 +3022,7 @@ var KubbDriver = class {
|
|
|
2995
3022
|
};
|
|
2996
3023
|
});
|
|
2997
3024
|
const resolveForPlugin = (state, node) => {
|
|
2998
|
-
const transformedNode = ast.
|
|
3025
|
+
const transformedNode = ast.macro.apply(node, state.plugin.macros ?? []);
|
|
2999
3026
|
if (state.optionsAreStatic) return {
|
|
3000
3027
|
transformedNode,
|
|
3001
3028
|
options: state.plugin.options
|
|
@@ -3374,7 +3401,7 @@ const fsStorage = createStorage(() => ({
|
|
|
3374
3401
|
});
|
|
3375
3402
|
},
|
|
3376
3403
|
async removeItem(key) {
|
|
3377
|
-
await rm
|
|
3404
|
+
await rm(resolve(key), { force: true });
|
|
3378
3405
|
},
|
|
3379
3406
|
async readKeys(base) {
|
|
3380
3407
|
return Array.fromAsync(listFiles(resolve(base ?? process.cwd()))).catch(() => []);
|
|
@@ -3387,14 +3414,14 @@ const fsStorage = createStorage(() => ({
|
|
|
3387
3414
|
try {
|
|
3388
3415
|
await rename(dir, join(parent, `${prefix}${process.pid}-${Date.now()}`));
|
|
3389
3416
|
} catch (_error) {
|
|
3390
|
-
await rm
|
|
3417
|
+
await rm(dir, {
|
|
3391
3418
|
recursive: true,
|
|
3392
3419
|
force: true
|
|
3393
3420
|
});
|
|
3394
3421
|
return;
|
|
3395
3422
|
}
|
|
3396
3423
|
const trash = (await readdir(parent)).filter((name) => name.startsWith(prefix));
|
|
3397
|
-
Promise.all(trash.map((name) => rm
|
|
3424
|
+
Promise.all(trash.map((name) => rm(join(parent, name), {
|
|
3398
3425
|
recursive: true,
|
|
3399
3426
|
force: true
|
|
3400
3427
|
}))).catch(() => {});
|
|
@@ -3412,7 +3439,7 @@ const fsStorage = createStorage(() => ({
|
|
|
3412
3439
|
*/
|
|
3413
3440
|
function resolveCacheDir(root) {
|
|
3414
3441
|
const nodeModules = join(root, "node_modules");
|
|
3415
|
-
if (existsSync
|
|
3442
|
+
if (existsSync(nodeModules)) return join(nodeModules, ".cache", "kubb");
|
|
3416
3443
|
return join(tmpdir(), "kubb", hash("sha256", root).slice(0, 16));
|
|
3417
3444
|
}
|
|
3418
3445
|
/**
|
|
@@ -3651,7 +3678,7 @@ async function runToolPass({ pass, setting, outputPath, hooks, cwd, signal }) {
|
|
|
3651
3678
|
}
|
|
3652
3679
|
if (setting === "auto") await hooks.callHook("kubb:info", { message: `Auto-detected ${pass.label}: ${styleText("dim", detected)}` });
|
|
3653
3680
|
const tool = pass.tools[detected];
|
|
3654
|
-
if (!tool || !existsSync(outputPath)) return null;
|
|
3681
|
+
if (!tool || !existsSync$1(outputPath)) return null;
|
|
3655
3682
|
const result = await runHook({
|
|
3656
3683
|
hooks,
|
|
3657
3684
|
command: tool.command,
|
|
@@ -3780,7 +3807,7 @@ function hasOutputPasses({ output, storage }) {
|
|
|
3780
3807
|
* const { files, diagnostics } = await kubb.safeBuild()
|
|
3781
3808
|
* ```
|
|
3782
3809
|
*/
|
|
3783
|
-
var Kubb = class {
|
|
3810
|
+
var Kubb = class Kubb {
|
|
3784
3811
|
hooks;
|
|
3785
3812
|
config;
|
|
3786
3813
|
#driver = null;
|
|
@@ -3791,6 +3818,34 @@ var Kubb = class {
|
|
|
3791
3818
|
this.hooks = options.hooks ?? new Hookable();
|
|
3792
3819
|
this.#signal = options.signal;
|
|
3793
3820
|
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Generates every config of a `defineConfig([...])` array in order and yields each result as its config finishes, so
|
|
3823
|
+
* memory holds one config at a time. A config that fails does not stop the others. Only an aborted `signal` rejects.
|
|
3824
|
+
*/
|
|
3825
|
+
static async *generate(configs, { hooks = new Hookable(), signal } = {}) {
|
|
3826
|
+
for (const config of configs) {
|
|
3827
|
+
const kubb = new Kubb(config, {
|
|
3828
|
+
hooks,
|
|
3829
|
+
signal
|
|
3830
|
+
});
|
|
3831
|
+
try {
|
|
3832
|
+
yield {
|
|
3833
|
+
...await kubb.generate(),
|
|
3834
|
+
kubb
|
|
3835
|
+
};
|
|
3836
|
+
} catch (error) {
|
|
3837
|
+
if (signal?.aborted) throw error;
|
|
3838
|
+
yield {
|
|
3839
|
+
success: false,
|
|
3840
|
+
files: [],
|
|
3841
|
+
diagnostics: [Diagnostics.from(error)],
|
|
3842
|
+
input: null,
|
|
3843
|
+
kubb,
|
|
3844
|
+
error
|
|
3845
|
+
};
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3794
3849
|
get storage() {
|
|
3795
3850
|
return this.config.storage;
|
|
3796
3851
|
}
|
|
@@ -3861,7 +3916,8 @@ var Kubb = class {
|
|
|
3861
3916
|
diagnostics,
|
|
3862
3917
|
files: driver.fileManager.files,
|
|
3863
3918
|
driver,
|
|
3864
|
-
storage
|
|
3919
|
+
storage,
|
|
3920
|
+
input: driver.inputNode
|
|
3865
3921
|
};
|
|
3866
3922
|
} catch (_) {
|
|
3867
3923
|
_usingCtx$1.e = _;
|
|
@@ -3897,15 +3953,16 @@ var Kubb = class {
|
|
|
3897
3953
|
if (signal?.aborted) throw caughtError;
|
|
3898
3954
|
output = {
|
|
3899
3955
|
files: [],
|
|
3900
|
-
diagnostics: [Diagnostics.from(caughtError)]
|
|
3956
|
+
diagnostics: [Diagnostics.from(caughtError)],
|
|
3957
|
+
input: null
|
|
3901
3958
|
};
|
|
3902
3959
|
}
|
|
3903
|
-
const { files, diagnostics } = output;
|
|
3960
|
+
const { files, diagnostics, input } = output;
|
|
3904
3961
|
const storage = this.storage;
|
|
3905
3962
|
signal?.throwIfAborted();
|
|
3906
3963
|
for (const diagnostic of diagnostics) if (Diagnostics.isProblem(diagnostic)) await Diagnostics.emit(hooks, diagnostic);
|
|
3907
3964
|
if (Diagnostics.hasError(diagnostics)) {
|
|
3908
|
-
await
|
|
3965
|
+
await this.#end({
|
|
3909
3966
|
config,
|
|
3910
3967
|
storage,
|
|
3911
3968
|
diagnostics,
|
|
@@ -3916,7 +3973,8 @@ var Kubb = class {
|
|
|
3916
3973
|
return {
|
|
3917
3974
|
success: false,
|
|
3918
3975
|
files,
|
|
3919
|
-
diagnostics
|
|
3976
|
+
diagnostics,
|
|
3977
|
+
input
|
|
3920
3978
|
};
|
|
3921
3979
|
}
|
|
3922
3980
|
const processOutput = options.processOutput ?? runOutputPasses;
|
|
@@ -3929,7 +3987,7 @@ var Kubb = class {
|
|
|
3929
3987
|
const finalDiagnostics = [...diagnostics, ...outputDiagnostics];
|
|
3930
3988
|
const failed = Diagnostics.hasError(outputDiagnostics);
|
|
3931
3989
|
if (!failed) await this.#manifest?.commit();
|
|
3932
|
-
await
|
|
3990
|
+
await this.#end({
|
|
3933
3991
|
config,
|
|
3934
3992
|
storage,
|
|
3935
3993
|
diagnostics: finalDiagnostics,
|
|
@@ -3940,11 +3998,23 @@ var Kubb = class {
|
|
|
3940
3998
|
return {
|
|
3941
3999
|
success: !failed,
|
|
3942
4000
|
files,
|
|
3943
|
-
diagnostics: finalDiagnostics
|
|
4001
|
+
diagnostics: finalDiagnostics,
|
|
4002
|
+
input
|
|
3944
4003
|
};
|
|
3945
4004
|
}
|
|
4005
|
+
/** Ends a run: `kubb:generation:end`, then the totals on `kubb:generation:summary`. */
|
|
4006
|
+
async #end(ctx) {
|
|
4007
|
+
await this.hooks.callHook("kubb:generation:end", ctx);
|
|
4008
|
+
await this.hooks.callHook("kubb:generation:summary", {
|
|
4009
|
+
duration: Math.round(getElapsedMs(ctx.hrStart)),
|
|
4010
|
+
fileCount: ctx.filesCreated,
|
|
4011
|
+
failedPlugins: Diagnostics.failedPlugins(ctx.diagnostics).length,
|
|
4012
|
+
status: ctx.status
|
|
4013
|
+
});
|
|
4014
|
+
}
|
|
3946
4015
|
dispose() {
|
|
3947
4016
|
this.#driver?.dispose();
|
|
4017
|
+
this.#driver = null;
|
|
3948
4018
|
}
|
|
3949
4019
|
[Symbol.dispose]() {
|
|
3950
4020
|
this.dispose();
|
|
@@ -4079,7 +4149,7 @@ function kubbStorage({ base } = {}) {
|
|
|
4079
4149
|
await writeRaw(pathOf(key), typeof value === "string" ? value : JSON.stringify(value));
|
|
4080
4150
|
},
|
|
4081
4151
|
async removeItem(key) {
|
|
4082
|
-
await rm
|
|
4152
|
+
await rm(pathOf(key), { force: true });
|
|
4083
4153
|
}
|
|
4084
4154
|
};
|
|
4085
4155
|
}
|
|
@@ -4536,7 +4606,7 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4536
4606
|
const packageJSON = await readJSON(path.join(root, "package.json")).catch(() => null);
|
|
4537
4607
|
const dependencies = [packageJSON?.dependencies, packageJSON?.devDependencies].flatMap((record) => typeof record === "object" && record !== null ? Object.keys(record) : []);
|
|
4538
4608
|
return Promise.all([.../* @__PURE__ */ new Set([...dependencies, ...packages])].filter(isPackageName).map(async (name) => {
|
|
4539
|
-
const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync(path.join(dir, "package.json")));
|
|
4609
|
+
const dir = requires.flatMap((require) => require.resolve.paths(name) ?? []).map((dir) => path.join(dir, name)).find((dir) => existsSync$1(path.join(dir, "package.json")));
|
|
4540
4610
|
if (!dir) return { package: name };
|
|
4541
4611
|
try {
|
|
4542
4612
|
const { version } = await readJSON(path.join(dir, "package.json"));
|
|
@@ -4551,6 +4621,6 @@ async function readInstalledPackages({ root, packages = [], resolveFrom = [] })
|
|
|
4551
4621
|
}
|
|
4552
4622
|
}));
|
|
4553
4623
|
}
|
|
4554
|
-
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 };
|
|
4624
|
+
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 };
|
|
4555
4625
|
|
|
4556
4626
|
//# sourceMappingURL=index.js.map
|