@kubb/cli 5.15.0 → 5.15.2
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/{Telemetry-B3edcFoB.js → Telemetry-BLRICCFj.js} +2 -2
- package/dist/{Telemetry-B3edcFoB.js.map → Telemetry-BLRICCFj.js.map} +1 -1
- package/dist/{Telemetry-COWGqYmh.cjs → Telemetry-CSjCG8WO.cjs} +2 -2
- package/dist/{Telemetry-COWGqYmh.cjs.map → Telemetry-CSjCG8WO.cjs.map} +1 -1
- package/dist/{background-_dKcGjM7.js → background-BeEZZNGc.js} +2 -2
- package/dist/{background-_dKcGjM7.js.map → background-BeEZZNGc.js.map} +1 -1
- package/dist/{background-B24lIehn.cjs → background-BiyfuZFp.cjs} +2 -2
- package/dist/{background-B24lIehn.cjs.map → background-BiyfuZFp.cjs.map} +1 -1
- package/dist/{background-D-7OGjvg.js → background-QEuTfHev.js} +1 -1
- package/dist/{configFile-CoEpHdXG.cjs → configFile-CVfWdtKh.cjs} +4 -40
- package/dist/configFile-CVfWdtKh.cjs.map +1 -0
- package/dist/{configFile-C0DIXNMD.js → configFile-IHj8fRIw.js} +3 -39
- package/dist/configFile-IHj8fRIw.js.map +1 -0
- package/dist/{spinner-BZaln7O8.js → fs-Cf1FSRh9.js} +20 -41
- package/dist/fs-Cf1FSRh9.js.map +1 -0
- package/dist/index.cjs +14 -14
- package/dist/index.js +14 -14
- package/dist/{installWithSpinner-DpnpxHq5.js → installWithSpinner-BAlTSQlE.js} +3 -3
- package/dist/{installWithSpinner-DpnpxHq5.js.map → installWithSpinner-BAlTSQlE.js.map} +1 -1
- package/dist/{installWithSpinner-ONGfIVUJ.cjs → installWithSpinner-X9J7yxiR.cjs} +3 -3
- package/dist/{installWithSpinner-ONGfIVUJ.cjs.map → installWithSpinner-X9J7yxiR.cjs.map} +1 -1
- package/dist/intro-DRl-pwVs.js +72 -0
- package/dist/intro-DRl-pwVs.js.map +1 -0
- package/dist/intro-DuyzJ3Rb.cjs +102 -0
- package/dist/intro-DuyzJ3Rb.cjs.map +1 -0
- package/dist/{intro-9PB8sE8z.js → log-B-1vLxF1.js} +2 -66
- package/dist/log-B-1vLxF1.js.map +1 -0
- package/dist/{intro-YPaf1Imr.cjs → log-wv1OxLiq.cjs} +1 -95
- package/dist/log-wv1OxLiq.cjs.map +1 -0
- package/dist/{mascot-JSA0j3Q_.cjs → mascot-CC-D4ON2.cjs} +2 -2
- package/dist/{mascot-JSA0j3Q_.cjs.map → mascot-CC-D4ON2.cjs.map} +1 -1
- package/dist/{mascot--q1xjKw1.js → mascot-CmUUHLlx.js} +2 -2
- package/dist/{mascot--q1xjKw1.js.map → mascot-CmUUHLlx.js.map} +1 -1
- package/dist/{mcp-CYPOFKnP.cjs → mcp-Don4UqAB.cjs} +2 -2
- package/dist/{mcp-CYPOFKnP.cjs.map → mcp-Don4UqAB.cjs.map} +1 -1
- package/dist/{mcp-CxeZR5vb.js → mcp-Spp8N-xs.js} +2 -2
- package/dist/{mcp-CxeZR5vb.js.map → mcp-Spp8N-xs.js.map} +1 -1
- package/dist/package-Bf2T71nz.js +5 -0
- package/dist/package-Bf2T71nz.js.map +1 -0
- package/dist/{package-aX0q9SZr.cjs → package-CI_luotn.cjs} +2 -2
- package/dist/package-CI_luotn.cjs.map +1 -0
- package/dist/{registry-B3eYk4LN.js → registry-Cy48PGdh.js} +3 -2
- package/dist/registry-Cy48PGdh.js.map +1 -0
- package/dist/{registry-YE1pFWL-.cjs → registry-Q77p5TZp.cjs} +3 -2
- package/dist/registry-Q77p5TZp.cjs.map +1 -0
- package/dist/{reporters-BM430HdQ.js → reporters-D6w4huLl.js} +222 -11
- package/dist/reporters-D6w4huLl.js.map +1 -0
- package/dist/{reporters-2cgjvXwR.cjs → reporters-Dby6Kgdj.cjs} +255 -10
- package/dist/reporters-Dby6Kgdj.cjs.map +1 -0
- package/dist/reporters-GdWr95qd.js +1 -0
- package/dist/{run-C0KI-NE3.js → run-BEwA7UDN.js} +4 -4
- package/dist/{run-C0KI-NE3.js.map → run-BEwA7UDN.js.map} +1 -1
- package/dist/{run-RN_31Q4u.js → run-BGUSyeuP.js} +44 -38
- package/dist/run-BGUSyeuP.js.map +1 -0
- package/dist/{run-DFXhBS64.js → run-BY4KZsE3.js} +2 -2
- package/dist/{run-DFXhBS64.js.map → run-BY4KZsE3.js.map} +1 -1
- package/dist/{run-CbX6tpqB.js → run-B_XCebc9.js} +10 -10
- package/dist/{run-CbX6tpqB.js.map → run-B_XCebc9.js.map} +1 -1
- package/dist/{run-B4zvF9WY.cjs → run-CFw6-hm1.cjs} +48 -42
- package/dist/run-CFw6-hm1.cjs.map +1 -0
- package/dist/{run-DCqmf5W1.cjs → run-CGdXlXy-.cjs} +4 -4
- package/dist/{run-DCqmf5W1.cjs.map → run-CGdXlXy-.cjs.map} +1 -1
- package/dist/{run-CCLPt4hr.js → run-CYynQJRk.js} +1 -1
- package/dist/{run-CrM4jsix.cjs → run-CfumUZCl.cjs} +7 -6
- package/dist/{run-CrM4jsix.cjs.map → run-CfumUZCl.cjs.map} +1 -1
- package/dist/{run-D-nn9-Wq.js → run-Cgy4_JPy.js} +14 -18
- package/dist/run-Cgy4_JPy.js.map +1 -0
- package/dist/{run-1H9TGT8v.js → run-Ch7Uuu-u.js} +4 -3
- package/dist/{run-1H9TGT8v.js.map → run-Ch7Uuu-u.js.map} +1 -1
- package/dist/{run-BYP_t9dR.cjs → run-DCggecSY.cjs} +19 -24
- package/dist/run-DCggecSY.cjs.map +1 -0
- package/dist/{run-Bb19PlwV.cjs → run-DFIaAIjC.cjs} +13 -12
- package/dist/{run-Bb19PlwV.cjs.map → run-DFIaAIjC.cjs.map} +1 -1
- package/dist/{run-BrM7-NSV.js → run-DHfFHNfG.js} +13 -17
- package/dist/run-DHfFHNfG.js.map +1 -0
- package/dist/{run-CvFakE3B.cjs → run-DT4hTOR2.cjs} +16 -21
- package/dist/run-DT4hTOR2.cjs.map +1 -0
- package/dist/{run-DgGZOC_x.cjs → run-DfCka9wW.cjs} +47 -61
- package/dist/run-DfCka9wW.cjs.map +1 -0
- package/dist/{run-KqdudiWQ.js → run-DiCSiwh8.js} +10 -9
- package/dist/{run-KqdudiWQ.js.map → run-DiCSiwh8.js.map} +1 -1
- package/dist/{run-BoO7H8RA.cjs → run-FGwhN0Pi.cjs} +20 -20
- package/dist/{run-BoO7H8RA.cjs.map → run-FGwhN0Pi.cjs.map} +1 -1
- package/dist/{run-D5Z6nfzK.cjs → run-KePEAia2.cjs} +2 -2
- package/dist/{run-D5Z6nfzK.cjs.map → run-KePEAia2.cjs.map} +1 -1
- package/dist/{run-CCsdLz3X.js → run-OHr93Akz.js} +40 -53
- package/dist/run-OHr93Akz.js.map +1 -0
- package/dist/shared-DcDHRtZx.js +58 -0
- package/dist/shared-DcDHRtZx.js.map +1 -0
- package/dist/shared-KKRMm1xX.cjs +87 -0
- package/dist/shared-KKRMm1xX.cjs.map +1 -0
- package/dist/{snapshot-D7Ytw8S0.cjs → snapshot-ByWxzJIh.cjs} +7 -7
- package/dist/{snapshot-D7Ytw8S0.cjs.map → snapshot-ByWxzJIh.cjs.map} +1 -1
- package/dist/{snapshot-n7dJGCWv.js → snapshot-UAiT_UQa.js} +6 -6
- package/dist/{snapshot-n7dJGCWv.js.map → snapshot-UAiT_UQa.js.map} +1 -1
- package/dist/spinner-DxsAllRI.js +48 -0
- package/dist/spinner-DxsAllRI.js.map +1 -0
- package/dist/{spinner-CfB0sIPy.cjs → spinner-RfMb7fd6.cjs} +50 -21
- package/dist/spinner-RfMb7fd6.cjs.map +1 -0
- package/dist/{status-DxSkp1cH.js → status-CEZ3m06O.js} +3 -3
- package/dist/{status-DxSkp1cH.js.map → status-CEZ3m06O.js.map} +1 -1
- package/dist/{status-Bc0_4T41.cjs → status-iE6UADco.cjs} +3 -3
- package/dist/{status-Bc0_4T41.cjs.map → status-iE6UADco.cjs.map} +1 -1
- package/dist/{studio-BpYwgFb0.cjs → studio-BL3zpp5R.cjs} +12 -12
- package/dist/{studio-BpYwgFb0.cjs.map → studio-BL3zpp5R.cjs.map} +1 -1
- package/dist/{studio-mw6HaPkr.js → studio-D9WQb5vH.js} +12 -12
- package/dist/{studio-mw6HaPkr.js.map → studio-D9WQb5vH.js.map} +1 -1
- package/dist/studioWorker.js +2 -2
- package/dist/{summary-Clvl5Hxs.cjs → summary-B2Apv5KO.cjs} +17 -2
- package/dist/summary-B2Apv5KO.cjs.map +1 -0
- package/dist/{summary-CbmQKA8l.js → summary-BQWHL_Ca.js} +12 -3
- package/dist/summary-BQWHL_Ca.js.map +1 -0
- package/dist/{text-Ep3AulAS.cjs → text-DMiX2dcG.cjs} +10 -1
- package/dist/text-DMiX2dcG.cjs.map +1 -0
- package/dist/{text-BmiI4s6N.js → text-EoYn04SX.js} +5 -2
- package/dist/text-EoYn04SX.js.map +1 -0
- package/dist/{utils-CbJ6hS_t.js → utils-CeMUE4P0.js} +90 -70
- package/dist/utils-CeMUE4P0.js.map +1 -0
- package/dist/{utils-CO89mxRU.cjs → utils-uSJAZuvP.cjs} +101 -69
- package/dist/utils-uSJAZuvP.cjs.map +1 -0
- package/dist/{validate-CMSeDpGT.cjs → validate-B9Ctya2v.cjs} +3 -3
- package/dist/{validate-CMSeDpGT.cjs.map → validate-B9Ctya2v.cjs.map} +1 -1
- package/dist/{validate-8ZcWXfMt.js → validate-BGvFsCDL.js} +3 -3
- package/dist/{validate-8ZcWXfMt.js.map → validate-BGvFsCDL.js.map} +1 -1
- package/package.json +8 -7
- package/dist/configFile-C0DIXNMD.js.map +0 -1
- package/dist/configFile-CoEpHdXG.cjs.map +0 -1
- package/dist/intro-9PB8sE8z.js.map +0 -1
- package/dist/intro-YPaf1Imr.cjs.map +0 -1
- package/dist/package-D3Yss9Bb.js +0 -5
- package/dist/package-D3Yss9Bb.js.map +0 -1
- package/dist/package-aX0q9SZr.cjs.map +0 -1
- package/dist/registry-B3eYk4LN.js.map +0 -1
- package/dist/registry-YE1pFWL-.cjs.map +0 -1
- package/dist/reporters-2cgjvXwR.cjs.map +0 -1
- package/dist/reporters-BM430HdQ.js.map +0 -1
- package/dist/run-B4zvF9WY.cjs.map +0 -1
- package/dist/run-BYP_t9dR.cjs.map +0 -1
- package/dist/run-BrM7-NSV.js.map +0 -1
- package/dist/run-CCsdLz3X.js.map +0 -1
- package/dist/run-CvFakE3B.cjs.map +0 -1
- package/dist/run-D-nn9-Wq.js.map +0 -1
- package/dist/run-DgGZOC_x.cjs.map +0 -1
- package/dist/run-RN_31Q4u.js.map +0 -1
- package/dist/shared-C0EtrdUm.cjs +0 -123
- package/dist/shared-C0EtrdUm.cjs.map +0 -1
- package/dist/shared-Ct9stKpp.js +0 -94
- package/dist/shared-Ct9stKpp.js.map +0 -1
- package/dist/spinner-BZaln7O8.js.map +0 -1
- package/dist/spinner-CfB0sIPy.cjs.map +0 -1
- package/dist/summary-CbmQKA8l.js.map +0 -1
- package/dist/summary-Clvl5Hxs.cjs.map +0 -1
- package/dist/text-BmiI4s6N.js.map +0 -1
- package/dist/text-Ep3AulAS.cjs.map +0 -1
- package/dist/utils-BdibacYq.js +0 -244
- package/dist/utils-BdibacYq.js.map +0 -1
- package/dist/utils-CO89mxRU.cjs.map +0 -1
- package/dist/utils-CbJ6hS_t.js.map +0 -1
- package/dist/utils-CcARPB45.cjs +0 -286
- package/dist/utils-CcARPB45.cjs.map +0 -1
|
@@ -1,47 +1,65 @@
|
|
|
1
1
|
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
|
+
import { n as detectPackageManager, p as pascalCase } from "./utils-CeMUE4P0.js";
|
|
2
3
|
import { t as getErrorMessage } from "./errors-wzqmMpMo.js";
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { n as
|
|
7
|
-
import { t as pluralize } from "./text-BmiI4s6N.js";
|
|
4
|
+
import { a as logWarn, i as logStep, n as logError, t as logBlock } from "./log-B-1vLxF1.js";
|
|
5
|
+
import { n as logIntro, t as isInteractiveRun } from "./intro-DRl-pwVs.js";
|
|
6
|
+
import { n as dryRunId, o as yesArg } from "./shared-DcDHRtZx.js";
|
|
7
|
+
import { n as pluralize } from "./text-EoYn04SX.js";
|
|
8
8
|
import { t as findConfigFile } from "./config-CQTxXvIG.js";
|
|
9
|
-
import { t as
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { t as installWithSpinner } from "./installWithSpinner-
|
|
9
|
+
import { n as withSpinner, t as createSpinner } from "./spinner-DxsAllRI.js";
|
|
10
|
+
import { t as createSummary } from "./summary-BQWHL_Ca.js";
|
|
11
|
+
import { a as installSpec, c as toRegistryId, i as incompatibility, l as toShortId, o as isOutdated, r as fetchRegistryIndex, s as registryUrl, t as bumpOf } from "./registry-Cy48PGdh.js";
|
|
12
|
+
import { t as installWithSpinner } from "./installWithSpinner-BAlTSQlE.js";
|
|
13
13
|
import { t as formatTable } from "./table-CR7iZJGo.js";
|
|
14
14
|
import { styleText } from "node:util";
|
|
15
15
|
import { defineWithTypes } from "gunshi";
|
|
16
16
|
import process from "node:process";
|
|
17
17
|
import path from "node:path";
|
|
18
18
|
import * as clack from "@clack/prompts";
|
|
19
|
-
import { Hookable, readInstalledPackages } from "@kubb/core";
|
|
19
|
+
import { Hookable, logLevel, readInstalledPackages } from "@kubb/core";
|
|
20
20
|
// src/runners/update/run.ts
|
|
21
21
|
/**
|
|
22
|
-
* Generates every config in this process, the way `kubb generate` does, and returns the
|
|
23
|
-
* it changed. Runs after the install, so the config loads the new versions.
|
|
24
|
-
* config fails to load or a build fails.
|
|
22
|
+
* Generates every config in this process, the way `kubb generate` does, and returns the counts of
|
|
23
|
+
* output files it changed. Runs after the install, so the config loads the new versions.
|
|
24
|
+
* `undefined` when the config fails to load or a build fails.
|
|
25
25
|
*/
|
|
26
26
|
async function regenerate({ cwd, configPath }) {
|
|
27
27
|
const spinner = createSpinner();
|
|
28
28
|
spinner.start("Generating with the new versions");
|
|
29
29
|
try {
|
|
30
|
-
const [{ getConfigs }, { generate }] = await Promise.all([
|
|
30
|
+
const [{ getConfigs }, { generate }, { default: setupReporters }] = await Promise.all([
|
|
31
|
+
import("./config-BL3HnFhb.js"),
|
|
32
|
+
import("./run-B_XCebc9.js"),
|
|
33
|
+
import("./reporters-GdWr95qd.js")
|
|
34
|
+
]);
|
|
31
35
|
const { configs } = await getConfigs({ configPath });
|
|
32
|
-
const dirs = configs.map((config) => path.resolve(config.root ?? cwd, config.output.path));
|
|
33
|
-
const before = new Map((await Promise.all(dirs.map(readOutputFiles))).flatMap((files) => [...files]));
|
|
34
36
|
const hooks = new Hookable();
|
|
37
|
+
const changes = {
|
|
38
|
+
added: 0,
|
|
39
|
+
modified: 0,
|
|
40
|
+
deleted: 0,
|
|
41
|
+
linesAdded: 0,
|
|
42
|
+
linesRemoved: 0
|
|
43
|
+
};
|
|
44
|
+
setupReporters(hooks, {
|
|
45
|
+
logLevel: logLevel.info,
|
|
46
|
+
reporters: [{
|
|
47
|
+
name: "update",
|
|
48
|
+
report: ({ fileChanges }) => {
|
|
49
|
+
for (const key of Object.keys(changes)) changes[key] += fileChanges?.[key] ?? 0;
|
|
50
|
+
}
|
|
51
|
+
}],
|
|
52
|
+
fileChanges: true
|
|
53
|
+
});
|
|
35
54
|
for (const config of configs) if (!await generate({
|
|
36
55
|
config,
|
|
37
56
|
hooks
|
|
38
57
|
})) throw new Error("Generation failed");
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
spinner.stop(diff.files.length ? `Generated: ${pluralize(diff.files.length, "file")} changed` : "Generated: no files changed");
|
|
58
|
+
const changed = changes.added + changes.modified + changes.deleted;
|
|
59
|
+
spinner.stop(changed ? `Generated: ${pluralize(changed, "file")} changed` : "Generated: no files changed");
|
|
42
60
|
return {
|
|
43
|
-
|
|
44
|
-
output:
|
|
61
|
+
changes,
|
|
62
|
+
output: configs.map((config) => path.relative(cwd, path.resolve(config.root ?? cwd, config.output.path)) || ".").join(", ")
|
|
45
63
|
};
|
|
46
64
|
} catch (error) {
|
|
47
65
|
spinner.error(`Generation failed: ${getErrorMessage(error)}`);
|
|
@@ -57,13 +75,7 @@ async function run({ ids, dryRun, yes }) {
|
|
|
57
75
|
const cwd = process.cwd();
|
|
58
76
|
const hrStart = process.hrtime();
|
|
59
77
|
const installedPackages = [];
|
|
60
|
-
const summary = (
|
|
61
|
-
title,
|
|
62
|
-
status,
|
|
63
|
-
hrStart,
|
|
64
|
-
block: true,
|
|
65
|
-
lines
|
|
66
|
-
});
|
|
78
|
+
const summary = createSummary(hrStart);
|
|
67
79
|
logIntro({ title: isInteractiveRun({
|
|
68
80
|
yes,
|
|
69
81
|
dryRun
|
|
@@ -156,14 +168,14 @@ async function run({ ids, dryRun, yes }) {
|
|
|
156
168
|
}
|
|
157
169
|
const selected = proposals.filter((entry) => chosen.includes(entry.id));
|
|
158
170
|
const skipped = proposals.filter((entry) => !selected.includes(entry)).map((entry) => {
|
|
159
|
-
const kind =
|
|
171
|
+
const kind = pascalCase(entry.manifest.kind);
|
|
160
172
|
return ` ${styleText("dim", "Skipped")} ${kind} ${entry.artifact.package} ${entry.artifact.version} ${styleText("dim", `run kubb update ${toShortId(entry.id)} later`)}`;
|
|
161
173
|
});
|
|
162
174
|
if (!selected.length) {
|
|
163
175
|
summary("No updates installed", "canceled", [" No updates selected.", ...skipped]);
|
|
164
176
|
return;
|
|
165
177
|
}
|
|
166
|
-
const packageManager = detectPackageManager(cwd);
|
|
178
|
+
const packageManager = await detectPackageManager(cwd);
|
|
167
179
|
const names = selected.map(({ artifact }) => artifact.package).join(", ");
|
|
168
180
|
await installWithSpinner({
|
|
169
181
|
packages: selected.map(({ artifact }) => installSpec(artifact)),
|
|
@@ -182,16 +194,10 @@ async function run({ ids, dryRun, yes }) {
|
|
|
182
194
|
configPath
|
|
183
195
|
}) : void 0;
|
|
184
196
|
const generationFailed = Boolean(configPath && !changed);
|
|
185
|
-
const fileCounts = {
|
|
186
|
-
A: 0,
|
|
187
|
-
M: 0,
|
|
188
|
-
D: 0
|
|
189
|
-
};
|
|
190
|
-
for (const file of changed?.files ?? []) fileCounts[file.status]++;
|
|
191
197
|
summary(generationFailed ? "Extensions updated; generation failed" : "Update complete", generationFailed ? "warning" : "success", [
|
|
192
198
|
` Packages ${selected.length} installed with ${packageManager.name}${skipped.length ? ` · ${skipped.length} skipped` : ""}`,
|
|
193
199
|
...skipped,
|
|
194
|
-
...changed ? [` Files ${
|
|
200
|
+
...changed ? [` Files ${changed.changes.added} added · ${changed.changes.modified} modified · ${changed.changes.deleted} deleted`] : [],
|
|
195
201
|
...!configPath ? [" Regeneration not run"] : [],
|
|
196
202
|
...generationFailed ? ["", "Fix the generation error, then run kubb generate."] : []
|
|
197
203
|
]);
|
|
@@ -225,4 +231,4 @@ const command = defineWithTypes()({
|
|
|
225
231
|
});
|
|
226
232
|
export { command, run };
|
|
227
233
|
|
|
228
|
-
//# sourceMappingURL=run-
|
|
234
|
+
//# sourceMappingURL=run-BGUSyeuP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-BGUSyeuP.js","names":["logLevelMap"],"sources":["../src/runners/update/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { defineWithTypes } from 'gunshi'\nimport { findConfigFile } from '@internals/shared'\nimport { getErrorMessage, pascalCase } from '@internals/utils'\nimport { type GenerationResult, Hookable, type KubbHooks, logLevel as logLevelMap, readInstalledPackages, type RegistryEntry, type Reporter } from '@kubb/core'\nimport { pluralize } from '../../ui/text.ts'\nimport { dryRunId, type DryRunExtensions, yesArg } from '../../commands/shared.ts'\nimport { isInteractiveRun, logIntro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep, logWarn } from '../../ui/log.ts'\nimport { createSpinner, withSpinner } from '../../ui/spinner.ts'\nimport { createSummary } from '../../ui/summary.ts'\nimport { formatTable } from '../../ui/table.ts'\nimport { bumpOf, fetchRegistryIndex, incompatibility, installSpec, isOutdated, registryUrl, toRegistryId, toShortId } from '../../utils/registry.ts'\nimport { detectPackageManager } from '../init/utils.ts'\nimport { installWithSpinner } from '../installWithSpinner.ts'\n\nexport type UpdateOptions = {\n /**\n * Registry ids to update. Empty updates every installed extension the registry lists.\n */\n ids: Array<string>\n /**\n * List the updates without installing anything.\n */\n dryRun: boolean\n yes: boolean\n}\n\ntype FileChanges = NonNullable<GenerationResult['fileChanges']>\n\n/**\n * Generates every config in this process, the way `kubb generate` does, and returns the counts of\n * output files it changed. Runs after the install, so the config loads the new versions.\n * `undefined` when the config fails to load or a build fails.\n */\nasync function regenerate({ cwd, configPath }: { cwd: string; configPath: string }): Promise<{ changes: FileChanges; output: string } | undefined> {\n const spinner = createSpinner()\n spinner.start('Generating with the new versions')\n try {\n // Imported here, so the config loader and the generate path never slow down `kubb --help`.\n const [{ getConfigs }, { generate }, { default: setupReporters }] = await Promise.all([\n import('../../config.ts'),\n import('../generate/run.ts'),\n import('../../loggers/reporters.ts'),\n ])\n const { configs } = await getConfigs({ configPath })\n const hooks = new Hookable<KubbHooks>()\n const changes: FileChanges = { added: 0, modified: 0, deleted: 0, linesAdded: 0, linesRemoved: 0 }\n const collect: Reporter = {\n name: 'update',\n report: ({ fileChanges }) => {\n for (const key of Object.keys(changes) as Array<keyof FileChanges>) changes[key] += fileChanges?.[key] ?? 0\n },\n }\n setupReporters(hooks, { logLevel: logLevelMap.info, reporters: [collect], fileChanges: true })\n for (const config of configs) {\n if (!(await generate({ config, hooks }))) throw new Error('Generation failed')\n }\n const changed = changes.added + changes.modified + changes.deleted\n spinner.stop(changed ? `Generated: ${pluralize(changed, 'file')} changed` : 'Generated: no files changed')\n return { changes, output: configs.map((config) => path.relative(cwd, path.resolve(config.root ?? cwd, config.output.path)) || '.').join(', ') }\n } catch (error) {\n spinner.error(`Generation failed: ${getErrorMessage(error)}`)\n return undefined\n }\n}\n\n/**\n * Moves installed extensions to the version the registry pins. Shows each version change with its\n * bump, asks which to install with majors left out, installs them, and regenerates to show which\n * files changed. With `dryRun`, only lists the updates and installs nothing.\n */\nexport async function run({ ids, dryRun, yes }: UpdateOptions): Promise<void> {\n const cwd = process.cwd()\n const hrStart = process.hrtime()\n const installedPackages: Array<string> = []\n const summary = createSummary(hrStart)\n logIntro({ title: isInteractiveRun({ yes, dryRun }) ? undefined : styleText('bgCyan', styleText('black', ' Kubb Update ')) })\n\n try {\n const wanted = new Set(ids.map(toRegistryId))\n const [entries, installed] = await withSpinner({\n message: 'Checking the registry',\n promise: Promise.all([fetchRegistryIndex({ registry: registryUrl() }), readInstalledPackages({ root: cwd })]),\n })\n const versions = new Map(installed.map((item) => [item.package, item.version]))\n\n const tracked = entries.filter((entry) => versions.has(entry.artifact.package) && (!wanted.size || wanted.has(entry.id)))\n for (const id of wanted) {\n if (tracked.some((entry) => entry.id === id)) continue\n logWarn(`${id} is not installed, or not in the registry.`)\n // A caller that named it, such as Studio, must not read the run as a successful update.\n process.exitCode = 1\n }\n\n const current = ({ artifact }: RegistryEntry) => versions.get(artifact.package)\n const isMajor = (entry: RegistryEntry) => bumpOf({ installed: current(entry), latest: entry.artifact.version }) === 'major'\n const outdated = tracked.filter((entry) => isOutdated({ installed: current(entry), latest: entry.artifact.version }))\n const proposals = outdated.filter((entry) => {\n const problem = incompatibility(entry.manifest)\n if (problem) {\n logWarn(`Skipped ${entry.id}: ${problem}`)\n // Same as a missing id: Studio would report an update that installed nothing.\n if (wanted.has(entry.id)) process.exitCode = 1\n }\n return !problem\n })\n\n if (!proposals.length) {\n const title = outdated.length ? 'No compatible updates available' : 'Already up to date'\n summary(tracked.length ? title : 'No installed extensions to update', outdated.length ? 'warning' : 'success', [\n ` ${tracked.length - outdated.length} of ${tracked.length} up to date`,\n ...(ids.length ? ['', `No updates for ${ids.join(', ')}.`] : []),\n ])\n return\n }\n\n if (tracked.length) {\n const header = ['Extension', 'Current', 'Latest', '']\n const rows = tracked.map((entry) => {\n if (!outdated.includes(entry)) return [entry.artifact.package, current(entry) ?? '-', 'up to date', '']\n const bump = bumpOf({ installed: current(entry), latest: entry.artifact.version }) ?? ''\n return [entry.artifact.package, current(entry) ?? 'not installed', entry.artifact.version, bump === 'major' ? 'major · breaking' : bump]\n })\n const lines = formatTable([header, ...rows])\n logStep(`Checked ${pluralize(tracked.length, 'extension')} against the registry`)\n logBlock([\n styleText('dim', lines[0]!),\n ...lines.slice(1).map((line, index) => {\n if (!outdated.includes(tracked[index]!)) return styleText('dim', line)\n return line.endsWith('major · breaking') ? styleText('yellow', line) : line\n }),\n ])\n }\n\n if (dryRun) {\n summary('Updates available', 'planned', [`Dry run: nothing was installed. Run kubb update to install ${proposals.length === 1 ? 'it' : 'them'}.`])\n return\n }\n\n // A major can break the generated code, so it is only picked for you when you named it.\n const defaults = proposals.filter((entry) => wanted.has(entry.id) || !isMajor(entry))\n const chosen = yes\n ? defaults.map((entry) => entry.id)\n : await clack.multiselect({\n message: 'Select the updates to install',\n options: proposals.map((entry) => ({\n value: entry.id,\n label: entry.artifact.package,\n hint: `${current(entry) ?? 'not installed'} → ${entry.artifact.version}`,\n })),\n initialValues: defaults.map((entry) => entry.id),\n required: false,\n })\n if (clack.isCancel(chosen)) {\n summary('Update canceled', 'canceled', [' No changes made'])\n return\n }\n const selected = proposals.filter((entry) => chosen.includes(entry.id))\n\n const skipped = proposals\n .filter((entry) => !selected.includes(entry))\n .map((entry) => {\n const kind = pascalCase(entry.manifest.kind)\n return ` ${styleText('dim', 'Skipped')} ${kind} ${entry.artifact.package} ${entry.artifact.version} ${styleText('dim', `run kubb update ${toShortId(entry.id)} later`)}`\n })\n if (!selected.length) {\n summary('No updates installed', 'canceled', [' No updates selected.', ...skipped])\n return\n }\n\n const packageManager = await detectPackageManager(cwd)\n const names = selected.map(({ artifact }) => artifact.package).join(', ')\n await installWithSpinner({\n packages: selected.map(({ artifact }) => installSpec(artifact)),\n names,\n packageManager,\n cwd,\n })\n installedPackages.push(...selected.map((entry) => entry.artifact.package))\n\n // Regenerating rewrites output files, so it is asked for. `--yes` only accepts the install.\n const foundConfig = findConfigFile(cwd)\n const regenerateNow =\n foundConfig && !yes && (await clack.confirm({ message: 'Regenerate now? This rewrites the generated files.', initialValue: true })) === true\n const configPath = regenerateNow ? foundConfig : undefined\n const changed = configPath ? await regenerate({ cwd, configPath }) : undefined\n\n const generationFailed = Boolean(configPath && !changed)\n summary(generationFailed ? 'Extensions updated; generation failed' : 'Update complete', generationFailed ? 'warning' : 'success', [\n ` Packages ${selected.length} installed with ${packageManager.name}${skipped.length ? ` · ${skipped.length} skipped` : ''}`,\n ...skipped,\n ...(changed ? [` Files ${changed.changes.added} added · ${changed.changes.modified} modified · ${changed.changes.deleted} deleted`] : []),\n ...(!configPath ? [' Regeneration not run'] : []),\n ...(generationFailed ? ['', 'Fix the generation error, then run kubb generate.'] : []),\n ])\n } catch (error) {\n logError(getErrorMessage(error))\n summary('Update failed', 'failed', installedPackages.length ? [` Packages ${installedPackages.join(', ')} installed`] : [' No changes made'])\n process.exitCode = 1\n }\n}\n\nexport const command = defineWithTypes<{ extensions: DryRunExtensions }>()({\n name: 'update',\n description: 'Update installed extensions, regenerate, and summarize file changes.',\n examples: ['kubb update', 'kubb update --dry-run', 'kubb update plugin-zod plugin-ts --yes'].join('\\n'),\n args: {\n ids: {\n type: 'positional',\n description: 'Registry ids to update, all installed extensions when omitted',\n multiple: true,\n },\n ...yesArg,\n },\n run: ({ values, extensions }) => run({ ids: values.ids ?? [], dryRun: extensions[dryRunId].enabled, yes: values.yes }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,eAAe,WAAW,EAAE,KAAK,cAAkH;CACjJ,MAAM,UAAU,cAAc;CAC9B,QAAQ,MAAM,kCAAkC;CAChD,IAAI;EAEF,MAAM,CAAC,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,oBAAoB,MAAM,QAAQ,IAAI;GACpF,OAAO;GACP,OAAO;GACP,OAAO;EACT,CAAC;EACD,MAAM,EAAE,YAAY,MAAM,WAAW,EAAE,WAAW,CA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;GAAK;EAAW,CAAC,IAAI,KAAA;EAErE,MAAM,mBAAmB,QAAQ,cAAc,CAAC,OAAO;EACvD,QAAQ,mBAAmB,0CAA0C,mBAAmB,mBAAmB,YAAY,WAAW;GAChI,eAAe,SAAS,OAAO,kBAAkB,eAAe,OAAO,QAAQ,SAAS,MAAM,QAAQ,OAAO,YAAY;GACzH,GAAG;GACH,GAAI,UAAU,CAAC,eAAe,QAAQ,QAAQ,MAAM,WAAW,QAAQ,QAAQ,SAAS,cAAc,QAAQ,QAAQ,QAAQ,SAAS,IAAI,CAAC;GAC5I,GAAI,CAAC,aAAa,CAAC,wBAAwB,IAAI,CAAC;GAChD,GAAI,mBAAmB,CAAC,IAAI,mDAAmD,IAAI,CAAC;EACtF,CAAC;CACH,SAAS,OAAO;EACd,SAAS,gBAAgB,KAAK,CAAC;EAC/B,QAAQ,iBAAiB,UAAU,kBAAkB,SAAS,CAAC,eAAe,kBAAkB,KAAK,IAAI,EAAE,WAAW,IAAI,CAAC,mBAAmB,CAAC;EAC/I,QAAQ,WAAW;CACrB;AACF;AAEA,MAAa,UAAU,gBAAkD,CAAC,CAAC;CACzE,MAAM;CACN,aAAa;CACb,UAAU;EAAC;EAAe;EAAyB;CAAwC,CAAC,CAAC,KAAK,IAAI;CACtG,MAAM;EACJ,KAAK;GACH,MAAM;GACN,aAAa;GACb,UAAU;EACZ;EACA,GAAG;CACL;CACA,MAAM,EAAE,QAAQ,iBAAiB,IAAI;EAAE,KAAK,OAAO,OAAO,CAAC;EAAG,QAAQ,WAAW,SAAS,CAAC;EAAS,KAAK,OAAO;CAAI,CAAC;AACvH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
2
|
import { n as toError } from "./errors-wzqmMpMo.js";
|
|
3
|
-
import { n as trackRun } from "./Telemetry-
|
|
3
|
+
import { n as trackRun } from "./Telemetry-BLRICCFj.js";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
// src/runners/mcp/run.ts
|
|
@@ -28,4 +28,4 @@ async function run() {
|
|
|
28
28
|
}
|
|
29
29
|
export { run };
|
|
30
30
|
|
|
31
|
-
//# sourceMappingURL=run-
|
|
31
|
+
//# sourceMappingURL=run-BY4KZsE3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-
|
|
1
|
+
{"version":3,"file":"run-BY4KZsE3.js","names":[],"sources":["../src/runners/mcp/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { toError } from '@internals/utils'\nimport type * as McpModule from '@kubb/mcp'\nimport { trackRun } from '../../Telemetry.ts'\n\n/**\n * Starts the `@kubb/mcp` server over stdio and reports the outcome to telemetry.\n */\nexport async function run(): Promise<void> {\n const { run: startMcpServer } = (await import('@kubb/mcp')) as typeof McpModule\n\n const report = trackRun({ command: 'mcp', hrStart: process.hrtime() })\n\n try {\n // The MCP stdio transport owns stdout: anything else written there corrupts the JSON-RPC stream.\n console.error(styleText('cyan', '⏳ Starting MCP server...'))\n console.warn(styleText('yellow', 'This feature is still under development, use with caution'))\n const server = startMcpServer()\n // Report once the client introduces itself, so the event names the client (e.g. `claude-code`, `cursor-vscode`).\n server.on('initialize', ({ clientInfo }) => void report({ status: 'success', mcpClient: clientInfo.name }), { once: true })\n } catch (error) {\n await report({ status: 'failed' })\n console.error(toError(error).message)\n process.exitCode = 1\n }\n}\n"],"mappings":";;;;;;;;;AASA,eAAsB,MAAqB;CACzC,MAAM,EAAE,KAAK,mBAAoB,MAAM,OAAO;CAE9C,MAAM,SAAS,SAAS;EAAE,SAAS;EAAO,SAAS,QAAQ,OAAO;CAAE,CAAC;CAErE,IAAI;EAEF,QAAQ,MAAM,UAAU,QAAQ,0BAA0B,CAAC;EAC3D,QAAQ,KAAK,UAAU,UAAU,2DAA2D,CAAC;EAG7F,eAAK,CAAC,CAAC,GAAG,eAAe,EAAE,iBAAiB,KAAK,OAAO;GAAE,QAAQ;GAAW,WAAW,WAAW;EAAK,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC;CAC5H,SAAS,OAAO;EACd,MAAM,OAAO,EAAE,QAAQ,SAAS,CAAC;EACjC,QAAQ,MAAM,QAAQ,KAAK,CAAC,CAAC,OAAO;EACpC,QAAQ,WAAW;CACrB;AACF"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
2
|
import { n as getElapsedMs, t as formatMs } from "./time-C-wU7VhC.js";
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { n as
|
|
7
|
-
import { a as logTip,
|
|
8
|
-
import { n as logBanner } from "./mascot
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { a as startWatcher, i as listenForKeys, n as setupReporters, o as trackBuild, r as diffBuilds, t as selectReporters } from "./reporters-D6w4huLl.js";
|
|
4
|
+
import { t as version } from "./package-Bf2T71nz.js";
|
|
5
|
+
import { n as trackRun } from "./Telemetry-BLRICCFj.js";
|
|
6
|
+
import { a as logWarn, i as logStep, n as logError, r as logInfo, s as createPlainWriter } from "./log-B-1vLxF1.js";
|
|
7
|
+
import { a as logTip, i as logSpacer, n as logIntro, r as logOutro } from "./intro-DRl-pwVs.js";
|
|
8
|
+
import { n as logBanner } from "./mascot-CmUUHLlx.js";
|
|
9
|
+
import { n as pluralize } from "./text-EoYn04SX.js";
|
|
10
|
+
import { t as createSpinner } from "./spinner-DxsAllRI.js";
|
|
11
11
|
import { t as getConfigs } from "./config-Uk3rbZfb.js";
|
|
12
|
-
import { o as isOutdated } from "./registry-
|
|
12
|
+
import { o as isOutdated } from "./registry-Cy48PGdh.js";
|
|
13
13
|
import { styleText } from "node:util";
|
|
14
14
|
import process from "node:process";
|
|
15
15
|
import path from "node:path";
|
|
@@ -223,4 +223,4 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
223
223
|
}
|
|
224
224
|
export { generate, run };
|
|
225
225
|
|
|
226
|
-
//# sourceMappingURL=run-
|
|
226
|
+
//# sourceMappingURL=run-B_XCebc9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-CbX6tpqB.js","names":["logLevel","logLevelMap"],"sources":["../src/runners/generate/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport { formatMs, formatters, getElapsedMs, linters } from '@internals/utils'\nimport {\n Hookable,\n type CLIOptions,\n cliReporter,\n type Config,\n createKubb,\n Diagnostics,\n fileReporter,\n getInputKind,\n htmlReporter,\n jsonReporter,\n type KubbHooks,\n logLevel as logLevelMap,\n memoryStorage,\n type ReporterName,\n} from '@kubb/core'\nimport { version } from '../../../package.json'\nimport { trackRun } from '../../Telemetry.ts'\nimport { pluralize } from '../../ui/text.ts'\nimport setupReporters, { selectReporters } from '../../loggers/reporters.ts'\nimport { createPlainWriter } from '../../loggers/plainWriter.ts'\nimport { logIntro, logOutro, logSpacer, logTip } from '../../ui/intro.ts'\nimport { logError, logInfo, logStep, logWarn } from '../../ui/log.ts'\nimport { logBanner } from '../../ui/mascot.ts'\nimport { createSpinner } from '../../ui/spinner.ts'\nimport { getConfigs } from '../../config.ts'\nimport { isOutdated } from '../../utils/registry.ts'\nimport { type BuildDiff, type BuildSnapshot, diffBuilds, listenForKeys, startWatcher, trackBuild } from './utils.ts'\n\n/** NPM registry endpoint used to check for @kubb/cli updates. */\nconst KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/** Upper bound in milliseconds for the npm update check, so a slow registry never stalls a run. */\nconst UPDATE_CHECK_TIMEOUT_MS = 3_000\n\n/** The formatter names from `Config['output'].format`, without `'auto'` (detection, not a tool) and `false` (skip). */\ntype FormatterName = Exclude<NonNullable<Config['output']['format']>, 'auto' | false>\ntype LinterName = Exclude<NonNullable<Config['output']['lint']>, 'auto' | false>\n\n// Pinned here, not in `@internals/utils` (which must not import `@kubb/core`): a tool added to the union without a descriptor fails to compile.\nformatters satisfies Record<FormatterName, unknown>\nlinters satisfies Record<LinterName, unknown>\n\ntype GenerateProps = {\n input?: string\n config: Config\n hooks: Hookable<KubbHooks>\n /**\n * When `true`, generates in memory instead of writing to disk, skips formatting, linting, and\n * post-generate commands, and prints what would change on disk.\n */\n dryRun?: boolean\n}\n\nexport async function generate(options: GenerateProps): Promise<boolean> {\n const { input, hooks, dryRun = false } = options\n\n const report = trackRun({ command: 'generate', hrStart: process.hrtime() })\n\n const config: Config = {\n ...options.config,\n input: input ?? options.config.input,\n // Dry-run never touches disk, regardless of the config's own storage driver.\n storage: dryRun ? memoryStorage() : options.config.storage,\n // Also keeps core's `hasOutputPasses` false, so dry-run skips the output manifest write too.\n output: dryRun ? { ...options.config.output, format: false, lint: false, postGenerate: [] } : options.config.output,\n }\n\n // Core formats, lints and runs `output.postGenerate` after an error-free build, and reports\n // their failures as coded diagnostics that reach the summary, the json report and the exit code.\n const kubb = createKubb(config, { hooks })\n const result = await kubb.generate()\n\n // Not awaited: the request finishes in the background, capped by its timeout, so it never delays the summary.\n void report({\n // A setup that threw leaves no driver, so read the configured plugins instead.\n plugins: kubb.config.plugins.flatMap((p) =>\n p && typeof p === 'object' ? [{ name: p.meta?.name ?? p.name ?? '', options: (p.options ?? {}) as Record<string, unknown> }] : [],\n ),\n filesCreated: result.files.length,\n status: result.success ? 'success' : 'failed',\n })\n\n return result.success\n}\n\ntype GenerateCommandOptions = {\n input?: string\n configPath?: string\n logLevel: string\n watch: boolean\n reporters?: Array<ReporterName>\n dryRun?: boolean\n}\n\n/** The latest published version, `undefined` when the registry does not answer in time or `signal` aborts. Never rejects. */\nasync function fetchLatestVersion(signal: AbortSignal): Promise<string | undefined> {\n try {\n const res = await fetch(KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.any([signal, AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS)]) })\n const data = (await res.json()) as { version: string }\n return data.version\n } catch {\n // Ignore network errors\n return undefined\n }\n}\n\nasync function checkForUpdate({ hooks, latestVersion }: { hooks: Hookable<KubbHooks>; latestVersion: string | undefined }): Promise<void> {\n if (latestVersion && isOutdated({ installed: version, latest: latestVersion })) {\n await Diagnostics.emit(hooks, Diagnostics.update({ currentVersion: version, latestVersion }))\n }\n}\n\n/** Prints `Rebuilt in 1.2s · +1 schema -2 operations`, without the names part when the spec kept the same names. */\nfunction logRebuild({ diff: { schemas, operations }, durationMs }: { diff: BuildDiff; durationMs: number }): void {\n const specChange = [\n schemas.added && styleText('green', `+${pluralize(schemas.added, 'schema')}`),\n schemas.removed && styleText('red', `-${pluralize(schemas.removed, 'schema')}`),\n operations.added && styleText('green', `+${pluralize(operations.added, 'operation')}`),\n operations.removed && styleText('red', `-${pluralize(operations.removed, 'operation')}`),\n ]\n .filter(Boolean)\n .join(' ')\n logStep([`Rebuilt in ${formatMs(durationMs)}`, specChange].filter(Boolean).join(styleText('dim', ' · ')))\n}\n\n/**\n * Runs the full Kubb generation lifecycle for the given CLI options.\n * Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),\n * calls `generate` for each config entry, and prints an update notice when the registry answered in time.\n */\nexport async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }: GenerateCommandOptions): Promise<void> {\n // Started first and never awaited: the notice prints at the end only when the registry has answered by then.\n const updateCheck = new AbortController()\n let latestVersion: string | undefined\n void fetchLatestVersion(updateCheck.signal).then((value) => {\n latestVersion = value\n })\n const logLevel = logLevelMap[logLevelKey as keyof typeof logLevelMap] ?? logLevelMap.info\n const hooks = new Hookable<KubbHooks>()\n\n // CLI `--reporter` selects which reporters to trigger by name, defaulting to `cli`. `defineConfig`\n // registers the built-in reporters on the config; a config exported without it falls back to them below.\n const requestedNames: Array<ReporterName> = cliReporters?.length ? cliReporters : ['cli']\n\n // The `json` reporter owns stdout, so the command writes nothing of its own around it.\n const json = requestedNames.includes('json')\n const quiet = logLevel <= logLevelMap.silent || json\n\n // Errors raised outside a build have no report entry. In `json` mode they go to a stderr logger,\n // so they are never silent and stdout stays one JSON document.\n const errorHooks = json ? new Hookable<KubbHooks>() : hooks\n if (json) setupReporters(errorHooks, { logLevel, reporters: [cliReporter], writer: createPlainWriter(console.error) })\n\n // The config loads while the banner plays; the output still prints in order once the banner is done.\n const banner = quiet ? undefined : logBanner(version)\n const loading = getConfigs({\n configPath,\n input,\n watch,\n logLevel: logLevelKey as CLIOptions['logLevel'],\n })\n // Handled below; this keeps a rejection during the banner from counting as unhandled.\n loading.catch(() => undefined)\n await banner\n\n if (!quiet) {\n logIntro({ title: 'Configuration' })\n }\n\n // Load the config first so `config.reporters` can pick the reporters. A failure here has no\n // reporter installed yet, so fall back to the default `cli` reporter to surface it.\n const configSpinner = createSpinner()\n let configs: Array<Config>\n let resolvedConfigPath: string\n try {\n if (!quiet) configSpinner.start('Loading config')\n\n const loaded = await loading\n configs = loaded.configs\n resolvedConfigPath = loaded.configPath\n\n if (!quiet) configSpinner.stop(`Loaded ${styleText('dim', path.relative(process.cwd(), resolvedConfigPath))}`)\n } catch (error) {\n if (!quiet) configSpinner.error('Config failed loading')\n\n if (!json) setupReporters(hooks, { logLevel, reporters: [cliReporter] })\n // A diagnostic thrown while the config file runs, such as invalid extension options, sits in the cause chain.\n await Diagnostics.emit(errorHooks, error)\n\n if (!quiet) logOutro(styleText('red', '✗ Configuration failed'))\n process.exit(1)\n }\n\n // Without a reporter nothing is printed, not even an error, so a config written without\n // `defineConfig` gets the same built-ins it would have registered.\n const available = configs[0]?.reporters?.length ? configs[0].reporters : [cliReporter, jsonReporter, fileReporter, htmlReporter]\n const reporters = selectReporters(available, requestedNames)\n setupReporters(hooks, { logLevel, reporters, dryRun })\n\n await hooks.callHook('kubb:lifecycle:start', { version })\n\n if (!quiet) logOutro(`${pluralize(configs.length, 'config')} ready`)\n\n try {\n let anyFailed = false\n // One tracker, one key listener and one build queue serve every watched config, so several configs never mix diffs or answer `r` twice.\n const tracker = watch ? trackBuild(hooks) : undefined\n const rebuilds: Array<() => Promise<void>> = []\n let armKeys: (() => void) | undefined\n // Configs share the hooks emitter, so every build, from any watcher or the `r` key, waits for the one before it.\n let queue = Promise.resolve()\n for (const config of configs) {\n const effectiveInput = input ?? config.input\n const inputKind = typeof effectiveInput === 'string' ? getInputKind(effectiveInput) : undefined\n const watchPath = inputKind === 'file' ? (effectiveInput as string) : undefined\n if (watchPath && tracker) {\n const label = styleText('yellow', `Watching ${path.relative(process.cwd(), watchPath)}`)\n let previous: BuildSnapshot | undefined\n // Don't removeAll() between builds, that would also drop logger and lifecycle\n // listeners. Plugin listeners are already disposed by safeBuild's dispose()\n // in its finally block, so re-running generate() on the same hooks emitter is safe.\n const build = async () => {\n const hrStart = process.hrtime()\n const succeeded = await generate({ input, config, hooks, dryRun })\n const snapshot = tracker.take()\n if (previous) logRebuild({ diff: diffBuilds(previous, snapshot), durationMs: getElapsedMs(hrStart) })\n previous = snapshot\n\n logStep(armKeys ? `${label} ${styleText('dim', 'r rebuild · q quit')}` : label)\n armKeys?.()\n if (succeeded) {\n logSpacer()\n logTip()\n }\n }\n // A trigger that lands while this config's build is queued joins it; one that lands during the build queues one more. Never rejects.\n let pending = false\n const rebuild = (): Promise<void> => {\n if (pending) return queue\n pending = true\n queue = queue\n .then(() => {\n pending = false\n return build()\n })\n .catch((error) => void Diagnostics.emit(errorHooks, error))\n return queue\n }\n rebuilds.push(rebuild)\n if (!quiet) {\n armKeys ??= listenForKeys({\n rebuild: () => rebuilds.forEach((trigger) => void trigger()),\n quit: (code) => void Promise.resolve(hooks.callHook('kubb:lifecycle:end')).finally(() => process.exit(code)),\n })\n }\n\n // The watcher ignores its startup state, so run the first build here; a failing one keeps watching so the user can fix the input.\n await rebuild()\n\n await startWatcher([watchPath], rebuild, { info: logInfo, error: logError })\n } else {\n if (tracker && !quiet) logWarn('Watch mode only follows a local `input` file, so this config is generated once.')\n try {\n const succeeded = await generate({ input, config, hooks, dryRun })\n if (!succeeded) anyFailed = true\n } catch (configError) {\n await Diagnostics.emit(errorHooks, configError)\n anyFailed = true\n }\n }\n }\n\n // A request still in flight would keep the process alive until its timeout.\n updateCheck.abort()\n await checkForUpdate({ hooks, latestVersion })\n\n await hooks.callHook('kubb:lifecycle:end')\n\n // Watch mode prints a tip after each successful build. Regular generate commands need to\n // print one explicitly after the lifecycle group has closed so it stays outside the group.\n if (!quiet && !watch && !anyFailed) {\n logTip()\n }\n\n // `exitCode`, not `exit()`, so a telemetry request still in flight can finish within its timeout.\n if (anyFailed) {\n process.exitCode = 1\n }\n } catch (error) {\n await Diagnostics.emit(errorHooks, error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkCA,MAAM,uBAAuB;;AAG7B,MAAM,0BAA0B;AAqBhC,eAAsB,SAAS,SAA0C;CACvE,MAAM,EAAE,OAAO,OAAO,SAAS,UAAU;CAEzC,MAAM,SAAS,SAAS;EAAE,SAAS;EAAY,SAAS,QAAQ,OAAO;CAAE,CAAC;CAE1E,MAAM,SAAiB;EACrB,GAAG,QAAQ;EACX,OAAO,SAAS,QAAQ,OAAO;EAE/B,SAAS,SAAS,cAAc,IAAI,QAAQ,OAAO;EAEnD,QAAQ,SAAS;GAAE,GAAG,QAAQ,OAAO;GAAQ,QAAQ;GAAO,MAAM;GAAO,cAAc,CAAC;EAAE,IAAI,QAAQ,OAAO;CAC/G;CAIA,MAAM,OAAO,WAAW,QAAQ,EAAE,MAAM,CAAC;CACzC,MAAM,SAAS,MAAM,KAAK,SAAS;CAGnC,OAAY;EAEV,SAAS,KAAK,OAAO,QAAQ,SAAS,MACpC,KAAK,OAAO,MAAM,WAAW,CAAC;GAAE,MAAM,EAAE,MAAM,QAAQ,EAAE,QAAQ;GAAI,SAAU,EAAE,WAAW,CAAC;EAA8B,CAAC,IAAI,CAAC,CAClI;EACA,cAAc,OAAO,MAAM;EAC3B,QAAQ,OAAO,UAAU,YAAY;CACvC,CAAC;CAED,OAAO,O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B,eAAe,SAAS,SAAS,YAAY,KAAK,QAAQ,CAAC;KAC3D,OAAO,SAAS,KAAK,QAAQ,QAAQ,MAAM,SAAS,oBAAoB,CAAC,CAAC,CAAC,cAAc,QAAQ,KAAK,IAAI,CAAC;IAC7G,CAAC;IAIH,MAAM,QAAQ;IAEd,MAAM,aAAa,CAAC,SAAS,GAAG,SAAS;KAAE,MAAM;KAAS,OAAO;IAAS,CAAC;GAC7E,OAAO;IACL,IAAI,WAAW,CAAC,OAAO,QAAQ,iFAAiF;IAChH,IAAI;KAEF,IAAI,CAAC,MADmB,SAAS;MAAE;MAAO;MAAQ;MAAO;KAAO,CAAC,GACjD,YAAY;IAC9B,SAAS,aAAa;KACpB,MAAM,YAAY,KAAK,YAAY,WAAW;KAC9C,YAAY;IACd;GACF;EACF;EAGA,YAAY,MAAM;EAClB,MAAM,eAAe;GAAE;GAAO;EAAc,CAAC;EAE7C,MAAM,MAAM,SAAS,oBAAoB;EAIzC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WACvB,OAAO;EAIT,IAAI,WACF,QAAQ,WAAW;CAEvB,SAAS,OAAO;EACd,MAAM,YAAY,KAAK,YAAY,KAAK;EACxC,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"run-B_XCebc9.js","names":["logLevel","logLevelMap"],"sources":["../src/runners/generate/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport { formatMs, formatters, getElapsedMs, linters } from '@internals/utils'\nimport {\n Hookable,\n type CLIOptions,\n cliReporter,\n type Config,\n createKubb,\n Diagnostics,\n fileReporter,\n getInputKind,\n htmlReporter,\n jsonReporter,\n type KubbHooks,\n logLevel as logLevelMap,\n memoryStorage,\n type ReporterName,\n} from '@kubb/core'\nimport { version } from '../../../package.json'\nimport { trackRun } from '../../Telemetry.ts'\nimport { pluralize } from '../../ui/text.ts'\nimport setupReporters, { selectReporters } from '../../loggers/reporters.ts'\nimport { createPlainWriter } from '../../loggers/plainWriter.ts'\nimport { logIntro, logOutro, logSpacer, logTip } from '../../ui/intro.ts'\nimport { logError, logInfo, logStep, logWarn } from '../../ui/log.ts'\nimport { logBanner } from '../../ui/mascot.ts'\nimport { createSpinner } from '../../ui/spinner.ts'\nimport { getConfigs } from '../../config.ts'\nimport { isOutdated } from '../../utils/registry.ts'\nimport { type BuildDiff, type BuildSnapshot, diffBuilds, listenForKeys, startWatcher, trackBuild } from './utils.ts'\n\n/** NPM registry endpoint used to check for @kubb/cli updates. */\nconst KUBB_NPM_PACKAGE_URL = 'https://registry.npmjs.org/@kubb/cli/latest' as const\n\n/** Upper bound in milliseconds for the npm update check, so a slow registry never stalls a run. */\nconst UPDATE_CHECK_TIMEOUT_MS = 3_000\n\n/** The formatter names from `Config['output'].format`, without `'auto'` (detection, not a tool) and `false` (skip). */\ntype FormatterName = Exclude<NonNullable<Config['output']['format']>, 'auto' | false>\ntype LinterName = Exclude<NonNullable<Config['output']['lint']>, 'auto' | false>\n\n// Pinned here, not in `@internals/utils` (which must not import `@kubb/core`): a tool added to the union without a descriptor fails to compile.\nformatters satisfies Record<FormatterName, unknown>\nlinters satisfies Record<LinterName, unknown>\n\ntype GenerateProps = {\n input?: string\n config: Config\n hooks: Hookable<KubbHooks>\n /**\n * When `true`, generates in memory instead of writing to disk, skips formatting, linting, and\n * post-generate commands, and prints what would change on disk.\n */\n dryRun?: boolean\n}\n\nexport async function generate(options: GenerateProps): Promise<boolean> {\n const { input, hooks, dryRun = false } = options\n\n const report = trackRun({ command: 'generate', hrStart: process.hrtime() })\n\n const config: Config = {\n ...options.config,\n input: input ?? options.config.input,\n // Dry-run never touches disk, regardless of the config's own storage driver.\n storage: dryRun ? memoryStorage() : options.config.storage,\n // Also keeps core's `hasOutputPasses` false, so dry-run skips the output manifest write too.\n output: dryRun ? { ...options.config.output, format: false, lint: false, postGenerate: [] } : options.config.output,\n }\n\n // Core formats, lints and runs `output.postGenerate` after an error-free build, and reports\n // their failures as coded diagnostics that reach the summary, the json report and the exit code.\n const kubb = createKubb(config, { hooks })\n const result = await kubb.generate()\n\n // Not awaited: the request finishes in the background, capped by its timeout, so it never delays the summary.\n void report({\n // A setup that threw leaves no driver, so read the configured plugins instead.\n plugins: kubb.config.plugins.flatMap((p) =>\n p && typeof p === 'object' ? [{ name: p.meta?.name ?? p.name ?? '', options: (p.options ?? {}) as Record<string, unknown> }] : [],\n ),\n filesCreated: result.files.length,\n status: result.success ? 'success' : 'failed',\n })\n\n return result.success\n}\n\ntype GenerateCommandOptions = {\n input?: string\n configPath?: string\n logLevel: string\n watch: boolean\n reporters?: Array<ReporterName>\n dryRun?: boolean\n}\n\n/** The latest published version, `undefined` when the registry does not answer in time or `signal` aborts. Never rejects. */\nasync function fetchLatestVersion(signal: AbortSignal): Promise<string | undefined> {\n try {\n const res = await fetch(KUBB_NPM_PACKAGE_URL, { signal: AbortSignal.any([signal, AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS)]) })\n const data = (await res.json()) as { version: string }\n return data.version\n } catch {\n // Ignore network errors\n return undefined\n }\n}\n\nasync function checkForUpdate({ hooks, latestVersion }: { hooks: Hookable<KubbHooks>; latestVersion: string | undefined }): Promise<void> {\n if (latestVersion && isOutdated({ installed: version, latest: latestVersion })) {\n await Diagnostics.emit(hooks, Diagnostics.update({ currentVersion: version, latestVersion }))\n }\n}\n\n/** Prints `Rebuilt in 1.2s · +1 schema -2 operations`, without the names part when the spec kept the same names. */\nfunction logRebuild({ diff: { schemas, operations }, durationMs }: { diff: BuildDiff; durationMs: number }): void {\n const specChange = [\n schemas.added && styleText('green', `+${pluralize(schemas.added, 'schema')}`),\n schemas.removed && styleText('red', `-${pluralize(schemas.removed, 'schema')}`),\n operations.added && styleText('green', `+${pluralize(operations.added, 'operation')}`),\n operations.removed && styleText('red', `-${pluralize(operations.removed, 'operation')}`),\n ]\n .filter(Boolean)\n .join(' ')\n logStep([`Rebuilt in ${formatMs(durationMs)}`, specChange].filter(Boolean).join(styleText('dim', ' · ')))\n}\n\n/**\n * Runs the full Kubb generation lifecycle for the given CLI options.\n * Loads configs, sets up the reporters (CLI `--reporter` picks which of `config.reporters` to trigger),\n * calls `generate` for each config entry, and prints an update notice when the registry answered in time.\n */\nexport async function run({ input, configPath, logLevel: logLevelKey, watch, reporters: cliReporters, dryRun }: GenerateCommandOptions): Promise<void> {\n // Started first and never awaited: the notice prints at the end only when the registry has answered by then.\n const updateCheck = new AbortController()\n let latestVersion: string | undefined\n void fetchLatestVersion(updateCheck.signal).then((value) => {\n latestVersion = value\n })\n const logLevel = logLevelMap[logLevelKey as keyof typeof logLevelMap] ?? logLevelMap.info\n const hooks = new Hookable<KubbHooks>()\n\n // CLI `--reporter` selects which reporters to trigger by name, defaulting to `cli`. `defineConfig`\n // registers the built-in reporters on the config; a config exported without it falls back to them below.\n const requestedNames: Array<ReporterName> = cliReporters?.length ? cliReporters : ['cli']\n\n // The `json` reporter owns stdout, so the command writes nothing of its own around it.\n const json = requestedNames.includes('json')\n const quiet = logLevel <= logLevelMap.silent || json\n\n // Errors raised outside a build have no report entry. In `json` mode they go to a stderr logger,\n // so they are never silent and stdout stays one JSON document.\n const errorHooks = json ? new Hookable<KubbHooks>() : hooks\n if (json) setupReporters(errorHooks, { logLevel, reporters: [cliReporter], writer: createPlainWriter(console.error) })\n\n // The config loads while the banner plays; the output still prints in order once the banner is done.\n const banner = quiet ? undefined : logBanner(version)\n const loading = getConfigs({\n configPath,\n input,\n watch,\n logLevel: logLevelKey as CLIOptions['logLevel'],\n })\n // Handled below; this keeps a rejection during the banner from counting as unhandled.\n loading.catch(() => undefined)\n await banner\n\n if (!quiet) {\n logIntro({ title: 'Configuration' })\n }\n\n // Load the config first so `config.reporters` can pick the reporters. A failure here has no\n // reporter installed yet, so fall back to the default `cli` reporter to surface it.\n const configSpinner = createSpinner()\n let configs: Array<Config>\n let resolvedConfigPath: string\n try {\n if (!quiet) configSpinner.start('Loading config')\n\n const loaded = await loading\n configs = loaded.configs\n resolvedConfigPath = loaded.configPath\n\n if (!quiet) configSpinner.stop(`Loaded ${styleText('dim', path.relative(process.cwd(), resolvedConfigPath))}`)\n } catch (error) {\n if (!quiet) configSpinner.error('Config failed loading')\n\n if (!json) setupReporters(hooks, { logLevel, reporters: [cliReporter] })\n // A diagnostic thrown while the config file runs, such as invalid extension options, sits in the cause chain.\n await Diagnostics.emit(errorHooks, error)\n\n if (!quiet) logOutro(styleText('red', '✗ Configuration failed'))\n process.exit(1)\n }\n\n // Without a reporter nothing is printed, not even an error, so a config written without\n // `defineConfig` gets the same built-ins it would have registered.\n const available = configs[0]?.reporters?.length ? configs[0].reporters : [cliReporter, jsonReporter, fileReporter, htmlReporter]\n const reporters = selectReporters(available, requestedNames)\n setupReporters(hooks, { logLevel, reporters, dryRun })\n\n await hooks.callHook('kubb:lifecycle:start', { version })\n\n if (!quiet) logOutro(`${pluralize(configs.length, 'config')} ready`)\n\n try {\n let anyFailed = false\n // One tracker, one key listener and one build queue serve every watched config, so several configs never mix diffs or answer `r` twice.\n const tracker = watch ? trackBuild(hooks) : undefined\n const rebuilds: Array<() => Promise<void>> = []\n let armKeys: (() => void) | undefined\n // Configs share the hooks emitter, so every build, from any watcher or the `r` key, waits for the one before it.\n let queue = Promise.resolve()\n for (const config of configs) {\n const effectiveInput = input ?? config.input\n const inputKind = typeof effectiveInput === 'string' ? getInputKind(effectiveInput) : undefined\n const watchPath = inputKind === 'file' ? (effectiveInput as string) : undefined\n if (watchPath && tracker) {\n const label = styleText('yellow', `Watching ${path.relative(process.cwd(), watchPath)}`)\n let previous: BuildSnapshot | undefined\n // Don't removeAll() between builds, that would also drop logger and lifecycle\n // listeners. Plugin listeners are already disposed by safeBuild's dispose()\n // in its finally block, so re-running generate() on the same hooks emitter is safe.\n const build = async () => {\n const hrStart = process.hrtime()\n const succeeded = await generate({ input, config, hooks, dryRun })\n const snapshot = tracker.take()\n if (previous) logRebuild({ diff: diffBuilds(previous, snapshot), durationMs: getElapsedMs(hrStart) })\n previous = snapshot\n\n logStep(armKeys ? `${label} ${styleText('dim', 'r rebuild · q quit')}` : label)\n armKeys?.()\n if (succeeded) {\n logSpacer()\n logTip()\n }\n }\n // A trigger that lands while this config's build is queued joins it; one that lands during the build queues one more. Never rejects.\n let pending = false\n const rebuild = (): Promise<void> => {\n if (pending) return queue\n pending = true\n queue = queue\n .then(() => {\n pending = false\n return build()\n })\n .catch((error) => void Diagnostics.emit(errorHooks, error))\n return queue\n }\n rebuilds.push(rebuild)\n if (!quiet) {\n armKeys ??= listenForKeys({\n rebuild: () => rebuilds.forEach((trigger) => void trigger()),\n quit: (code) => void Promise.resolve(hooks.callHook('kubb:lifecycle:end')).finally(() => process.exit(code)),\n })\n }\n\n // The watcher ignores its startup state, so run the first build here; a failing one keeps watching so the user can fix the input.\n await rebuild()\n\n await startWatcher([watchPath], rebuild, { info: logInfo, error: logError })\n } else {\n if (tracker && !quiet) logWarn('Watch mode only follows a local `input` file, so this config is generated once.')\n try {\n const succeeded = await generate({ input, config, hooks, dryRun })\n if (!succeeded) anyFailed = true\n } catch (configError) {\n await Diagnostics.emit(errorHooks, configError)\n anyFailed = true\n }\n }\n }\n\n // A request still in flight would keep the process alive until its timeout.\n updateCheck.abort()\n await checkForUpdate({ hooks, latestVersion })\n\n await hooks.callHook('kubb:lifecycle:end')\n\n // Watch mode prints a tip after each successful build. Regular generate commands need to\n // print one explicitly after the lifecycle group has closed so it stays outside the group.\n if (!quiet && !watch && !anyFailed) {\n logTip()\n }\n\n // `exitCode`, not `exit()`, so a telemetry request still in flight can finish within its timeout.\n if (anyFailed) {\n process.exitCode = 1\n }\n } catch (error) {\n await Diagnostics.emit(errorHooks, error)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkCA,MAAM,uBAAuB;;AAG7B,MAAM,0BAA0B;AAqBhC,eAAsB,SAAS,SAA0C;CACvE,MAAM,EAAE,OAAO,OAAO,SAAS,UAAU;CAEzC,MAAM,SAAS,SAAS;EAA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EAIzC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,WACvB,OAAO;EAIT,IAAI,WACF,QAAQ,WAAW;CAEvB,SAAS,OAAO;EACd,MAAM,YAAY,KAAK,YAAY,KAAK;EACxC,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C3-Zg-KD.cjs");
|
|
2
|
+
const require_utils = require("./utils-uSJAZuvP.cjs");
|
|
2
3
|
const require_errors = require("./errors-BponpdjN.cjs");
|
|
3
|
-
const require_spinner = require("./spinner-
|
|
4
|
-
const
|
|
5
|
-
const require_intro = require("./intro-
|
|
6
|
-
const require_shared = require("./shared-
|
|
4
|
+
const require_spinner = require("./spinner-RfMb7fd6.cjs");
|
|
5
|
+
const require_log = require("./log-wv1OxLiq.cjs");
|
|
6
|
+
const require_intro = require("./intro-DuyzJ3Rb.cjs");
|
|
7
|
+
const require_shared = require("./shared-KKRMm1xX.cjs");
|
|
7
8
|
const require_config = require("./config-CRrmj88c.cjs");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const require_installWithSpinner = require("./installWithSpinner-
|
|
12
|
-
const require_text = require("./text-Ep3AulAS.cjs");
|
|
9
|
+
const require_text = require("./text-DMiX2dcG.cjs");
|
|
10
|
+
const require_summary = require("./summary-B2Apv5KO.cjs");
|
|
11
|
+
const require_registry = require("./registry-Q77p5TZp.cjs");
|
|
12
|
+
const require_installWithSpinner = require("./installWithSpinner-X9J7yxiR.cjs");
|
|
13
13
|
const require_table = require("./table-BlRe9YTZ.cjs");
|
|
14
14
|
let node_util = require("node:util");
|
|
15
15
|
let gunshi = require("gunshi");
|
|
@@ -23,29 +23,47 @@ let _kubb_core = require("@kubb/core");
|
|
|
23
23
|
let _gunshi_plugin_dryrun = require("@gunshi/plugin-dryrun");
|
|
24
24
|
// src/runners/update/run.ts
|
|
25
25
|
/**
|
|
26
|
-
* Generates every config in this process, the way `kubb generate` does, and returns the
|
|
27
|
-
* it changed. Runs after the install, so the config loads the new versions.
|
|
28
|
-
* config fails to load or a build fails.
|
|
26
|
+
* Generates every config in this process, the way `kubb generate` does, and returns the counts of
|
|
27
|
+
* output files it changed. Runs after the install, so the config loads the new versions.
|
|
28
|
+
* `undefined` when the config fails to load or a build fails.
|
|
29
29
|
*/
|
|
30
30
|
async function regenerate({ cwd, configPath }) {
|
|
31
31
|
const spinner = require_spinner.createSpinner();
|
|
32
32
|
spinner.start("Generating with the new versions");
|
|
33
33
|
try {
|
|
34
|
-
const [{ getConfigs }, { generate }] = await Promise.all([
|
|
34
|
+
const [{ getConfigs }, { generate }, { default: setupReporters }] = await Promise.all([
|
|
35
|
+
Promise.resolve().then(() => require("./config-BWj9jBVj.cjs")).then((n) => n.config_exports),
|
|
36
|
+
Promise.resolve().then(() => require("./run-FGwhN0Pi.cjs")),
|
|
37
|
+
Promise.resolve().then(() => require("./reporters-Dby6Kgdj.cjs")).then((n) => n.reporters_exports)
|
|
38
|
+
]);
|
|
35
39
|
const { configs } = await getConfigs({ configPath });
|
|
36
|
-
const dirs = configs.map((config) => node_path.default.resolve(config.root ?? cwd, config.output.path));
|
|
37
|
-
const before = new Map((await Promise.all(dirs.map(require_utils.readOutputFiles))).flatMap((files) => [...files]));
|
|
38
40
|
const hooks = new _kubb_core.Hookable();
|
|
41
|
+
const changes = {
|
|
42
|
+
added: 0,
|
|
43
|
+
modified: 0,
|
|
44
|
+
deleted: 0,
|
|
45
|
+
linesAdded: 0,
|
|
46
|
+
linesRemoved: 0
|
|
47
|
+
};
|
|
48
|
+
setupReporters(hooks, {
|
|
49
|
+
logLevel: _kubb_core.logLevel.info,
|
|
50
|
+
reporters: [{
|
|
51
|
+
name: "update",
|
|
52
|
+
report: ({ fileChanges }) => {
|
|
53
|
+
for (const key of Object.keys(changes)) changes[key] += fileChanges?.[key] ?? 0;
|
|
54
|
+
}
|
|
55
|
+
}],
|
|
56
|
+
fileChanges: true
|
|
57
|
+
});
|
|
39
58
|
for (const config of configs) if (!await generate({
|
|
40
59
|
config,
|
|
41
60
|
hooks
|
|
42
61
|
})) throw new Error("Generation failed");
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
spinner.stop(diff.files.length ? `Generated: ${require_text.pluralize(diff.files.length, "file")} changed` : "Generated: no files changed");
|
|
62
|
+
const changed = changes.added + changes.modified + changes.deleted;
|
|
63
|
+
spinner.stop(changed ? `Generated: ${require_text.pluralize(changed, "file")} changed` : "Generated: no files changed");
|
|
46
64
|
return {
|
|
47
|
-
|
|
48
|
-
output:
|
|
65
|
+
changes,
|
|
66
|
+
output: configs.map((config) => node_path.default.relative(cwd, node_path.default.resolve(config.root ?? cwd, config.output.path)) || ".").join(", ")
|
|
49
67
|
};
|
|
50
68
|
} catch (error) {
|
|
51
69
|
spinner.error(`Generation failed: ${require_errors.getErrorMessage(error)}`);
|
|
@@ -61,13 +79,7 @@ async function run({ ids, dryRun, yes }) {
|
|
|
61
79
|
const cwd = node_process.default.cwd();
|
|
62
80
|
const hrStart = node_process.default.hrtime();
|
|
63
81
|
const installedPackages = [];
|
|
64
|
-
const summary =
|
|
65
|
-
title,
|
|
66
|
-
status,
|
|
67
|
-
hrStart,
|
|
68
|
-
block: true,
|
|
69
|
-
lines
|
|
70
|
-
});
|
|
82
|
+
const summary = require_summary.createSummary(hrStart);
|
|
71
83
|
require_intro.logIntro({ title: require_intro.isInteractiveRun({
|
|
72
84
|
yes,
|
|
73
85
|
dryRun
|
|
@@ -82,7 +94,7 @@ async function run({ ids, dryRun, yes }) {
|
|
|
82
94
|
const tracked = entries.filter((entry) => versions.has(entry.artifact.package) && (!wanted.size || wanted.has(entry.id)));
|
|
83
95
|
for (const id of wanted) {
|
|
84
96
|
if (tracked.some((entry) => entry.id === id)) continue;
|
|
85
|
-
|
|
97
|
+
require_log.logWarn(`${id} is not installed, or not in the registry.`);
|
|
86
98
|
node_process.default.exitCode = 1;
|
|
87
99
|
}
|
|
88
100
|
const current = ({ artifact }) => versions.get(artifact.package);
|
|
@@ -97,7 +109,7 @@ async function run({ ids, dryRun, yes }) {
|
|
|
97
109
|
const proposals = outdated.filter((entry) => {
|
|
98
110
|
const problem = require_registry.incompatibility(entry.manifest);
|
|
99
111
|
if (problem) {
|
|
100
|
-
|
|
112
|
+
require_log.logWarn(`Skipped ${entry.id}: ${problem}`);
|
|
101
113
|
if (wanted.has(entry.id)) node_process.default.exitCode = 1;
|
|
102
114
|
}
|
|
103
115
|
return !problem;
|
|
@@ -133,8 +145,8 @@ async function run({ ids, dryRun, yes }) {
|
|
|
133
145
|
];
|
|
134
146
|
});
|
|
135
147
|
const lines = require_table.formatTable([header, ...rows]);
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
require_log.logStep(`Checked ${require_text.pluralize(tracked.length, "extension")} against the registry`);
|
|
149
|
+
require_log.logBlock([(0, node_util.styleText)("dim", lines[0]), ...lines.slice(1).map((line, index) => {
|
|
138
150
|
if (!outdated.includes(tracked[index])) return (0, node_util.styleText)("dim", line);
|
|
139
151
|
return line.endsWith("major · breaking") ? (0, node_util.styleText)("yellow", line) : line;
|
|
140
152
|
})]);
|
|
@@ -160,14 +172,14 @@ async function run({ ids, dryRun, yes }) {
|
|
|
160
172
|
}
|
|
161
173
|
const selected = proposals.filter((entry) => chosen.includes(entry.id));
|
|
162
174
|
const skipped = proposals.filter((entry) => !selected.includes(entry)).map((entry) => {
|
|
163
|
-
const kind =
|
|
175
|
+
const kind = require_utils.pascalCase(entry.manifest.kind);
|
|
164
176
|
return ` ${(0, node_util.styleText)("dim", "Skipped")} ${kind} ${entry.artifact.package} ${entry.artifact.version} ${(0, node_util.styleText)("dim", `run kubb update ${require_registry.toShortId(entry.id)} later`)}`;
|
|
165
177
|
});
|
|
166
178
|
if (!selected.length) {
|
|
167
179
|
summary("No updates installed", "canceled", [" No updates selected.", ...skipped]);
|
|
168
180
|
return;
|
|
169
181
|
}
|
|
170
|
-
const packageManager = require_utils
|
|
182
|
+
const packageManager = await require_utils.detectPackageManager(cwd);
|
|
171
183
|
const names = selected.map(({ artifact }) => artifact.package).join(", ");
|
|
172
184
|
await require_installWithSpinner.installWithSpinner({
|
|
173
185
|
packages: selected.map(({ artifact }) => require_registry.installSpec(artifact)),
|
|
@@ -186,21 +198,15 @@ async function run({ ids, dryRun, yes }) {
|
|
|
186
198
|
configPath
|
|
187
199
|
}) : void 0;
|
|
188
200
|
const generationFailed = Boolean(configPath && !changed);
|
|
189
|
-
const fileCounts = {
|
|
190
|
-
A: 0,
|
|
191
|
-
M: 0,
|
|
192
|
-
D: 0
|
|
193
|
-
};
|
|
194
|
-
for (const file of changed?.files ?? []) fileCounts[file.status]++;
|
|
195
201
|
summary(generationFailed ? "Extensions updated; generation failed" : "Update complete", generationFailed ? "warning" : "success", [
|
|
196
202
|
` Packages ${selected.length} installed with ${packageManager.name}${skipped.length ? ` · ${skipped.length} skipped` : ""}`,
|
|
197
203
|
...skipped,
|
|
198
|
-
...changed ? [` Files ${
|
|
204
|
+
...changed ? [` Files ${changed.changes.added} added · ${changed.changes.modified} modified · ${changed.changes.deleted} deleted`] : [],
|
|
199
205
|
...!configPath ? [" Regeneration not run"] : [],
|
|
200
206
|
...generationFailed ? ["", "Fix the generation error, then run kubb generate."] : []
|
|
201
207
|
]);
|
|
202
208
|
} catch (error) {
|
|
203
|
-
|
|
209
|
+
require_log.logError(require_errors.getErrorMessage(error));
|
|
204
210
|
summary("Update failed", "failed", installedPackages.length ? [` Packages ${installedPackages.join(", ")} installed`] : [" No changes made"]);
|
|
205
211
|
node_process.default.exitCode = 1;
|
|
206
212
|
}
|
|
@@ -230,4 +236,4 @@ const command = (0, gunshi.defineWithTypes)()({
|
|
|
230
236
|
exports.command = command;
|
|
231
237
|
exports.run = run;
|
|
232
238
|
|
|
233
|
-
//# sourceMappingURL=run-
|
|
239
|
+
//# sourceMappingURL=run-CFw6-hm1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-CFw6-hm1.cjs","names":["createSpinner","Hookable","logLevelMap","pluralize","path","getErrorMessage","process","createSummary","isInteractiveRun","styleText","toRegistryId","withSpinner","fetchRegistryIndex","registryUrl","readInstalledPackages","bumpOf","isOutdated","incompatibility","formatTable","clack","pascalCase","toShortId","detectPackageManager","installWithSpinner","installSpec","findConfigFile","defineWithTypes","yesArg","dryRunId"],"sources":["../src/runners/update/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { defineWithTypes } from 'gunshi'\nimport { findConfigFile } from '@internals/shared'\nimport { getErrorMessage, pascalCase } from '@internals/utils'\nimport { type GenerationResult, Hookable, type KubbHooks, logLevel as logLevelMap, readInstalledPackages, type RegistryEntry, type Reporter } from '@kubb/core'\nimport { pluralize } from '../../ui/text.ts'\nimport { dryRunId, type DryRunExtensions, yesArg } from '../../commands/shared.ts'\nimport { isInteractiveRun, logIntro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep, logWarn } from '../../ui/log.ts'\nimport { createSpinner, withSpinner } from '../../ui/spinner.ts'\nimport { createSummary } from '../../ui/summary.ts'\nimport { formatTable } from '../../ui/table.ts'\nimport { bumpOf, fetchRegistryIndex, incompatibility, installSpec, isOutdated, registryUrl, toRegistryId, toShortId } from '../../utils/registry.ts'\nimport { detectPackageManager } from '../init/utils.ts'\nimport { installWithSpinner } from '../installWithSpinner.ts'\n\nexport type UpdateOptions = {\n /**\n * Registry ids to update. Empty updates every installed extension the registry lists.\n */\n ids: Array<string>\n /**\n * List the updates without installing anything.\n */\n dryRun: boolean\n yes: boolean\n}\n\ntype FileChanges = NonNullable<GenerationResult['fileChanges']>\n\n/**\n * Generates every config in this process, the way `kubb generate` does, and returns the counts of\n * output files it changed. Runs after the install, so the config loads the new versions.\n * `undefined` when the config fails to load or a build fails.\n */\nasync function regenerate({ cwd, configPath }: { cwd: string; configPath: string }): Promise<{ changes: FileChanges; output: string } | undefined> {\n const spinner = createSpinner()\n spinner.start('Generating with the new versions')\n try {\n // Imported here, so the config loader and the generate path never slow down `kubb --help`.\n const [{ getConfigs }, { generate }, { default: setupReporters }] = await Promise.all([\n import('../../config.ts'),\n import('../generate/run.ts'),\n import('../../loggers/reporters.ts'),\n ])\n const { configs } = await getConfigs({ configPath })\n const hooks = new Hookable<KubbHooks>()\n const changes: FileChanges = { added: 0, modified: 0, deleted: 0, linesAdded: 0, linesRemoved: 0 }\n const collect: Reporter = {\n name: 'update',\n report: ({ fileChanges }) => {\n for (const key of Object.keys(changes) as Array<keyof FileChanges>) changes[key] += fileChanges?.[key] ?? 0\n },\n }\n setupReporters(hooks, { logLevel: logLevelMap.info, reporters: [collect], fileChanges: true })\n for (const config of configs) {\n if (!(await generate({ config, hooks }))) throw new Error('Generation failed')\n }\n const changed = changes.added + changes.modified + changes.deleted\n spinner.stop(changed ? `Generated: ${pluralize(changed, 'file')} changed` : 'Generated: no files changed')\n return { changes, output: configs.map((config) => path.relative(cwd, path.resolve(config.root ?? cwd, config.output.path)) || '.').join(', ') }\n } catch (error) {\n spinner.error(`Generation failed: ${getErrorMessage(error)}`)\n return undefined\n }\n}\n\n/**\n * Moves installed extensions to the version the registry pins. Shows each version change with its\n * bump, asks which to install with majors left out, installs them, and regenerates to show which\n * files changed. With `dryRun`, only lists the updates and installs nothing.\n */\nexport async function run({ ids, dryRun, yes }: UpdateOptions): Promise<void> {\n const cwd = process.cwd()\n const hrStart = process.hrtime()\n const installedPackages: Array<string> = []\n const summary = createSummary(hrStart)\n logIntro({ title: isInteractiveRun({ yes, dryRun }) ? undefined : styleText('bgCyan', styleText('black', ' Kubb Update ')) })\n\n try {\n const wanted = new Set(ids.map(toRegistryId))\n const [entries, installed] = await withSpinner({\n message: 'Checking the registry',\n promise: Promise.all([fetchRegistryIndex({ registry: registryUrl() }), readInstalledPackages({ root: cwd })]),\n })\n const versions = new Map(installed.map((item) => [item.package, item.version]))\n\n const tracked = entries.filter((entry) => versions.has(entry.artifact.package) && (!wanted.size || wanted.has(entry.id)))\n for (const id of wanted) {\n if (tracked.some((entry) => entry.id === id)) continue\n logWarn(`${id} is not installed, or not in the registry.`)\n // A caller that named it, such as Studio, must not read the run as a successful update.\n process.exitCode = 1\n }\n\n const current = ({ artifact }: RegistryEntry) => versions.get(artifact.package)\n const isMajor = (entry: RegistryEntry) => bumpOf({ installed: current(entry), latest: entry.artifact.version }) === 'major'\n const outdated = tracked.filter((entry) => isOutdated({ installed: current(entry), latest: entry.artifact.version }))\n const proposals = outdated.filter((entry) => {\n const problem = incompatibility(entry.manifest)\n if (problem) {\n logWarn(`Skipped ${entry.id}: ${problem}`)\n // Same as a missing id: Studio would report an update that installed nothing.\n if (wanted.has(entry.id)) process.exitCode = 1\n }\n return !problem\n })\n\n if (!proposals.length) {\n const title = outdated.length ? 'No compatible updates available' : 'Already up to date'\n summary(tracked.length ? title : 'No installed extensions to update', outdated.length ? 'warning' : 'success', [\n ` ${tracked.length - outdated.length} of ${tracked.length} up to date`,\n ...(ids.length ? ['', `No updates for ${ids.join(', ')}.`] : []),\n ])\n return\n }\n\n if (tracked.length) {\n const header = ['Extension', 'Current', 'Latest', '']\n const rows = tracked.map((entry) => {\n if (!outdated.includes(entry)) return [entry.artifact.package, current(entry) ?? '-', 'up to date', '']\n const bump = bumpOf({ installed: current(entry), latest: entry.artifact.version }) ?? ''\n return [entry.artifact.package, current(entry) ?? 'not installed', entry.artifact.version, bump === 'major' ? 'major · breaking' : bump]\n })\n const lines = formatTable([header, ...rows])\n logStep(`Checked ${pluralize(tracked.length, 'extension')} against the registry`)\n logBlock([\n styleText('dim', lines[0]!),\n ...lines.slice(1).map((line, index) => {\n if (!outdated.includes(tracked[index]!)) return styleText('dim', line)\n return line.endsWith('major · breaking') ? styleText('yellow', line) : line\n }),\n ])\n }\n\n if (dryRun) {\n summary('Updates available', 'planned', [`Dry run: nothing was installed. Run kubb update to install ${proposals.length === 1 ? 'it' : 'them'}.`])\n return\n }\n\n // A major can break the generated code, so it is only picked for you when you named it.\n const defaults = proposals.filter((entry) => wanted.has(entry.id) || !isMajor(entry))\n const chosen = yes\n ? defaults.map((entry) => entry.id)\n : await clack.multiselect({\n message: 'Select the updates to install',\n options: proposals.map((entry) => ({\n value: entry.id,\n label: entry.artifact.package,\n hint: `${current(entry) ?? 'not installed'} → ${entry.artifact.version}`,\n })),\n initialValues: defaults.map((entry) => entry.id),\n required: false,\n })\n if (clack.isCancel(chosen)) {\n summary('Update canceled', 'canceled', [' No changes made'])\n return\n }\n const selected = proposals.filter((entry) => chosen.includes(entry.id))\n\n const skipped = proposals\n .filter((entry) => !selected.includes(entry))\n .map((entry) => {\n const kind = pascalCase(entry.manifest.kind)\n return ` ${styleText('dim', 'Skipped')} ${kind} ${entry.artifact.package} ${entry.artifact.version} ${styleText('dim', `run kubb update ${toShortId(entry.id)} later`)}`\n })\n if (!selected.length) {\n summary('No updates installed', 'canceled', [' No updates selected.', ...skipped])\n return\n }\n\n const packageManager = await detectPackageManager(cwd)\n const names = selected.map(({ artifact }) => artifact.package).join(', ')\n await installWithSpinner({\n packages: selected.map(({ artifact }) => installSpec(artifact)),\n names,\n packageManager,\n cwd,\n })\n installedPackages.push(...selected.map((entry) => entry.artifact.package))\n\n // Regenerating rewrites output files, so it is asked for. `--yes` only accepts the install.\n const foundConfig = findConfigFile(cwd)\n const regenerateNow =\n foundConfig && !yes && (await clack.confirm({ message: 'Regenerate now? This rewrites the generated files.', initialValue: true })) === true\n const configPath = regenerateNow ? foundConfig : undefined\n const changed = configPath ? await regenerate({ cwd, configPath }) : undefined\n\n const generationFailed = Boolean(configPath && !changed)\n summary(generationFailed ? 'Extensions updated; generation failed' : 'Update complete', generationFailed ? 'warning' : 'success', [\n ` Packages ${selected.length} installed with ${packageManager.name}${skipped.length ? ` · ${skipped.length} skipped` : ''}`,\n ...skipped,\n ...(changed ? [` Files ${changed.changes.added} added · ${changed.changes.modified} modified · ${changed.changes.deleted} deleted`] : []),\n ...(!configPath ? [' Regeneration not run'] : []),\n ...(generationFailed ? ['', 'Fix the generation error, then run kubb generate.'] : []),\n ])\n } catch (error) {\n logError(getErrorMessage(error))\n summary('Update failed', 'failed', installedPackages.length ? [` Packages ${installedPackages.join(', ')} installed`] : [' No changes made'])\n process.exitCode = 1\n }\n}\n\nexport const command = defineWithTypes<{ extensions: DryRunExtensions }>()({\n name: 'update',\n description: 'Update installed extensions, regenerate, and summarize file changes.',\n examples: ['kubb update', 'kubb update --dry-run', 'kubb update plugin-zod plugin-ts --yes'].join('\\n'),\n args: {\n ids: {\n type: 'positional',\n description: 'Registry ids to update, all installed extensions when omitted',\n multiple: true,\n },\n ...yesArg,\n },\n run: ({ values, extensions }) => run({ ids: values.ids ?? [], dryRun: extensions[dryRunId].enabled, yes: values.yes }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,eAAe,WAAW,EAAE,KAAK,cAAkH;CACjJ,MAAM,UAAUA,gBAAAA,cAAc;CAC9B,QAAQ,MAAM,kCAAkC;CAChD,IAAI;EAEF,MAAM,CAAC,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,oBAAoB,MAAM,QAAQ,IAAI;GACpF,QAAA,QAAA,CAAA,CAAA,WAAA,QAAA,uBAAA,CAAA,CAAA,CAAA,MAAA,MAAA,EAAA,cAAA;GACA,QAAA,QAAA,CAAA,CAAA,WAAA,QAAA,oBAAA,CAAA;GACA,QAAA,QAAA,CAAA,CAAA,WAAA,QAAA,0BAAA,CAAA,CAAA,CAAA,MAAA,MAAA,EAAA,iBAAA;EACF,CAAC;EACD,MAAM,EAAE,YAAY,MAAM,WAAW,EAAE,WAAW,CAAC;EACnD,MAAM,QAAQ,IAAIC,WAAAA,SAAoB;EACtC,MAAM,UAAuB;GAAE,OAAO;GAAG,UAAU;GAAG,SAAS;GAAG,YAAY;GAAG,cAAc;EAAE;EAOjG,eAAe,OAAO;GAAE,UAAUC,WAAAA,SAAY;GAAM,WAAW,CAAC;IAL9D,MAAM;IACN,SAAS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WC,sBAAAA,SAAS,CAAC;EAAS,KAAK,OAAO;CAAI,CAAC;AACvH,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-C3-Zg-KD.cjs");
|
|
2
2
|
const require_errors = require("./errors-BponpdjN.cjs");
|
|
3
|
-
const require_Telemetry = require("./Telemetry-
|
|
3
|
+
const require_Telemetry = require("./Telemetry-CSjCG8WO.cjs");
|
|
4
4
|
const require_config = require("./config-CRrmj88c.cjs");
|
|
5
5
|
const require_config$1 = require("./config-BWj9jBVj.cjs");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const require_text = require("./text-DMiX2dcG.cjs");
|
|
7
|
+
const require_summary = require("./summary-B2Apv5KO.cjs");
|
|
8
8
|
let node_util = require("node:util");
|
|
9
9
|
let node_process = require("node:process");
|
|
10
10
|
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
@@ -97,4 +97,4 @@ async function run({ input, configPath }) {
|
|
|
97
97
|
}
|
|
98
98
|
exports.run = run;
|
|
99
99
|
|
|
100
|
-
//# sourceMappingURL=run-
|
|
100
|
+
//# sourceMappingURL=run-CGdXlXy-.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-
|
|
1
|
+
{"version":3,"file":"run-CGdXlXy-.cjs","names":["process","trackRun","findConfigFile","getConfigs","getInputKind","resolve","checkoutGitInput","styleText","pluralize","toError"],"sources":["../src/runners/validate/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { resolve } from 'node:path'\nimport { styleText } from 'node:util'\nimport { findConfigFile } from '@internals/shared'\nimport { toError } from '@internals/utils'\nimport { type Config, checkoutGitInput, getInputKind } from '@kubb/core'\nimport { trackRun } from '../../Telemetry.ts'\nimport { getConfigs } from '../../config.ts'\nimport { pluralize } from '../../ui/text.ts'\nimport { logCommandSummary } from '../../ui/summary.ts'\n\ntype ValidateOptions = {\n /**\n * Path, URL, or git input (`git+<repo>#<ref>:<path>`) of the specification to validate.\n */\n input: string\n configPath?: string\n}\n\n/**\n * Validates `input` with the configured adapters, falling back to OpenAPI when no config exists.\n * Exits the process with code 1 on validation failure or missing dependency.\n */\nexport async function run({ input, configPath }: ValidateOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = trackRun({ command: 'validate', hrStart })\n let adapterName: string | undefined\n\n try {\n const configFile = configPath ?? findConfigFile()\n // A config found by search that does not load must not block validating a file; an explicit `--config` still fails.\n const loaded = configFile\n ? await getConfigs({ configPath: configFile, input }).catch((error) => {\n if (configPath) throw error\n })\n : undefined\n const fallback = async () => {\n adapterName = '@kubb/adapter-oas'\n const { adapterOas } = await import('@kubb/adapter-oas')\n return [{ adapter: adapterOas(), input }]\n }\n // An array config often repeats one adapter, so each adapter and input pair is validated once.\n const unique = new Map(\n (loaded?.configs ?? []).map((config) => {\n const resolved = getInputKind(input) === 'file' ? resolve(config.root || process.cwd(), input) : input\n return [`${config.adapter?.name}\\0${resolved}`, { adapter: config.adapter, input: resolved }] as const\n }),\n )\n const targets: Array<{ adapter: Config['adapter']; input: string }> = loaded ? [...unique.values()] : await fallback()\n if (!targets.length) throw new Error('The Kubb config contains no configurations to validate.')\n for (const target of targets) {\n adapterName = target.adapter?.name\n if (!target.adapter) throw new Error('No adapter is configured. Set adapter in your Kubb config to validate this specification.')\n const checkout = getInputKind(target.input) === 'git' ? await checkoutGitInput(target.input) : undefined\n try {\n await target.adapter.validate(checkout?.path ?? target.input, { throwOnError: true })\n } finally {\n await checkout?.dispose()\n }\n }\n const specifications = new Set(targets.map((target) => target.input)).size\n const adapterNames = [...new Set(targets.flatMap((target) => target.adapter?.name ?? []))]\n await report({ status: 'success' })\n\n logCommandSummary({\n title: 'Validation passed',\n status: 'success',\n hrStart,\n lines: [\n ` ${styleText('bold', `${pluralize(specifications, 'specification')} validated`)}`,\n ` ${styleText('dim', 'Input')} ${styleText('cyan', input)}`,\n ` ${styleText('dim', adapterNames.length === 1 ? 'Adapter' : 'Adapters')} ${adapterNames.join(', ')}`,\n ],\n })\n } catch (error) {\n await report({ status: 'failed' })\n const message = toError(error).message\n const missingAdapter = adapterName === '@kubb/adapter-oas' && /(?:Cannot find|Cannot resolve|not found)[\\s\\S]*@kubb\\/adapter-oas/.test(message)\n logCommandSummary({\n title: missingAdapter ? 'Could not validate' : 'Validation failed',\n status: 'failed',\n hrStart,\n lines: [\n ` ${styleText('dim', 'Input')} ${styleText('cyan', input)}`,\n ` ${styleText('dim', 'Adapter')} ${adapterName ?? 'not configured'}${missingAdapter ? ' · not installed' : ''}`,\n '',\n styleText('bold', missingAdapter ? 'Required package' : 'Validation error'),\n ` ${styleText('red', message)}`,\n ...(missingAdapter\n ? ['', 'Install it with:', styleText('cyan', ' npm install @kubb/adapter-oas'), styleText('cyan', ' pnpm add @kubb/adapter-oas')]\n : []),\n ],\n })\n\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,eAAsB,IAAI,EAAE,OAAO,cAA8C;CAC/E,MAAM,UAAUA,aAAAA,QAAQ,OAAO;CAC/B,MAAM,SAASC,kBAAAA,SAAS;EAAE,SAAS;EAAY;CAAQ,CAAC;CACxD,IAAI;CAEJ,IAAI;EACF,MAAM,aAAa,cAAcC,eAAAA,eAAe;EAEhD,MAAM,SAAS,aACX,MAAMC,iBAAAA,WAAW;GAAE,YAAY;GAAY;EAAM,CAAC,CAAC,CAAC,OAAO,UAAU;GACnE,IAAI,YAAY,MAAM;EACxB,CAAC,IACD,KAAA;EACJ,MAAM,WAAW,YAAY;GAC3B,cAAc;GACd,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,OAAO,CAAC;IAAE,SAAS,WAAW;IAAG;GAAM,CAAC;EAC1C;EAEA,MAAM,SAAS,IAAI,KAChB,QAAQ,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW;GACtC,MAAM,YAAA,GAAWC,WAAAA,aAAAA,CAAa,KAAK,MAAM,UAAA,GAASC,UAAAA,QAAAA,CAAQ,OAA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