@kubb/cli 5.0.0-beta.37 → 5.0.0-beta.39
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/{agent-B8oJFhcN.js → agent-CLspGfSn.js} +4 -4
- package/dist/{agent-B8oJFhcN.js.map → agent-CLspGfSn.js.map} +1 -1
- package/dist/{agent-DtuTV_Qk.cjs → agent-RdNQgRXD.cjs} +4 -4
- package/dist/{agent-DtuTV_Qk.cjs.map → agent-RdNQgRXD.cjs.map} +1 -1
- package/dist/{constants-CYxk4aNm.js → constants-84a47qA-.js} +2 -6
- package/dist/constants-84a47qA-.js.map +1 -0
- package/dist/{constants-CAKUpLcQ.cjs → constants-BtmponZ3.cjs} +1 -11
- package/dist/constants-BtmponZ3.cjs.map +1 -0
- package/dist/{generate-BvaMqrBk.cjs → generate-DK1pLJMi.cjs} +3 -4
- package/dist/generate-DK1pLJMi.cjs.map +1 -0
- package/dist/{generate-CzTjeiji.js → generate-Db0pJmbG.js} +3 -4
- package/dist/{generate-CzTjeiji.js.map → generate-Db0pJmbG.js.map} +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/{init-CaMeuE1-.js → init-DKMwmbmx.js} +2 -2
- package/dist/{init-CaMeuE1-.js.map → init-DKMwmbmx.js.map} +1 -1
- package/dist/{init-C59u3T68.cjs → init-D_MQBDVz.cjs} +2 -2
- package/dist/{init-C59u3T68.cjs.map → init-D_MQBDVz.cjs.map} +1 -1
- package/dist/{mcp-Ca3ZcpKB.js → mcp-DqNyN0cN.js} +3 -3
- package/dist/{mcp-Ca3ZcpKB.js.map → mcp-DqNyN0cN.js.map} +1 -1
- package/dist/{mcp-D4NMV9lk.cjs → mcp-DvEeDWlW.cjs} +3 -3
- package/dist/{mcp-D4NMV9lk.cjs.map → mcp-DvEeDWlW.cjs.map} +1 -1
- package/dist/package-C8u_WvqI.js +6 -0
- package/dist/package-C8u_WvqI.js.map +1 -0
- package/dist/{package-DQFf9DB2.cjs → package-CusjBrSS.cjs} +2 -2
- package/dist/package-CusjBrSS.cjs.map +1 -0
- package/dist/{run-DJxYClJV.js → run-BQ3Qj0xB.js} +4 -4
- package/dist/run-BQ3Qj0xB.js.map +1 -0
- package/dist/{run-BvXxelGR.js → run-BQzoaxjR.js} +3 -3
- package/dist/run-BQzoaxjR.js.map +1 -0
- package/dist/{run-Ca2h07rN.js → run-BabEDDqN.js} +130 -369
- package/dist/run-BabEDDqN.js.map +1 -0
- package/dist/{run-BFEK9md9.js → run-CGf0KEts.js} +3 -3
- package/dist/run-CGf0KEts.js.map +1 -0
- package/dist/{run-CK8Cvq6n.cjs → run-CJUmJcbC.cjs} +130 -369
- package/dist/run-CJUmJcbC.cjs.map +1 -0
- package/dist/{run-Bz9IFMWg.cjs → run-CkTpemme.cjs} +3 -3
- package/dist/run-CkTpemme.cjs.map +1 -0
- package/dist/{run-BQZyg7If.cjs → run-Cl4SrSob.cjs} +3 -3
- package/dist/run-Cl4SrSob.cjs.map +1 -0
- package/dist/{run-BFv6avA_.cjs → run-D-s2LdlW.cjs} +5 -5
- package/dist/run-D-s2LdlW.cjs.map +1 -0
- package/dist/{validate-B_wfDSHQ.cjs → validate-CkW_AKZp.cjs} +3 -3
- package/dist/{validate-B_wfDSHQ.cjs.map → validate-CkW_AKZp.cjs.map} +1 -1
- package/dist/{validate-BEEerg2-.js → validate-jRewvR0c.js} +3 -3
- package/dist/{validate-BEEerg2-.js.map → validate-jRewvR0c.js.map} +1 -1
- package/package.json +7 -7
- package/src/commands/generate.ts +2 -3
- package/src/constants.ts +0 -15
- package/src/index.ts +2 -2
- package/src/loggers/clackLogger.ts +4 -6
- package/src/loggers/githubActionsLogger.ts +3 -3
- package/src/loggers/plainLogger.ts +2 -3
- package/src/loggers/utils.ts +29 -28
- package/src/runners/agent/run.ts +2 -2
- package/src/runners/generate/run.ts +21 -17
- package/src/runners/generate/utils.ts +2 -2
- package/src/runners/mcp/run.ts +2 -2
- package/src/runners/validate/run.ts +2 -2
- package/dist/constants-CAKUpLcQ.cjs.map +0 -1
- package/dist/constants-CYxk4aNm.js.map +0 -1
- package/dist/generate-BvaMqrBk.cjs.map +0 -1
- package/dist/package-DQFf9DB2.cjs.map +0 -1
- package/dist/package-DUwUSFeL.js +0 -6
- package/dist/package-DUwUSFeL.js.map +0 -1
- package/dist/run-BFEK9md9.js.map +0 -1
- package/dist/run-BFv6avA_.cjs.map +0 -1
- package/dist/run-BQZyg7If.cjs.map +0 -1
- package/dist/run-BvXxelGR.js.map +0 -1
- package/dist/run-Bz9IFMWg.cjs.map +0 -1
- package/dist/run-CK8Cvq6n.cjs.map +0 -1
- package/dist/run-Ca2h07rN.js.map +0 -1
- package/dist/run-DJxYClJV.js.map +0 -1
- package/dist/telemetry-B80oJfxR.cjs +0 -280
- package/dist/telemetry-B80oJfxR.cjs.map +0 -1
- package/dist/telemetry-ueaMzs_c.js +0 -243
- package/dist/telemetry-ueaMzs_c.js.map +0 -1
- package/src/loggers/diagnostics.ts +0 -77
- package/src/reporters/cliReporter.ts +0 -89
- package/src/reporters/fileReporter.ts +0 -103
- package/src/reporters/jsonReporter.ts +0 -15
- package/src/reporters/report.ts +0 -84
- package/src/telemetry.ts +0 -280
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
|
-
const require_constants = require("./constants-CAKUpLcQ.cjs");
|
|
3
|
-
let node_crypto = require("node:crypto");
|
|
4
|
-
let node_dns = require("node:dns");
|
|
5
|
-
let node_os = require("node:os");
|
|
6
|
-
node_os = require_chunk.__toESM(node_os, 1);
|
|
7
|
-
let node_process = require("node:process");
|
|
8
|
-
node_process = require_chunk.__toESM(node_process, 1);
|
|
9
|
-
//#region ../../internals/utils/src/env.ts
|
|
10
|
-
/**
|
|
11
|
-
* Returns `true` when running inside a GitHub Actions workflow.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* if (isGitHubActions()) {
|
|
16
|
-
* core.setOutput('result', 'ok')
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
function isGitHubActions() {
|
|
21
|
-
return !!process.env.GITHUB_ACTIONS;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns `true` when the process is running in a CI environment.
|
|
25
|
-
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
26
|
-
* TeamCity, Buildkite, and Azure Pipelines.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* if (isCIEnvironment()) {
|
|
31
|
-
* logger.level = 'error'
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
function isCIEnvironment() {
|
|
36
|
-
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
40
|
-
* width and is not running in CI.
|
|
41
|
-
*
|
|
42
|
-
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
43
|
-
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
44
|
-
* with a negative count and throw a `RangeError`). We therefore require a
|
|
45
|
-
* positive column count before declaring the TTY usable.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* if (canUseTTY()) {
|
|
50
|
-
* renderProgressBar()
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
function canUseTTY() {
|
|
55
|
-
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region ../../internals/utils/src/network.ts
|
|
59
|
-
/**
|
|
60
|
-
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
61
|
-
*/
|
|
62
|
-
const TEST_DOMAINS = [
|
|
63
|
-
"dns.google.com",
|
|
64
|
-
"cloudflare.com",
|
|
65
|
-
"one.one.one.one"
|
|
66
|
-
];
|
|
67
|
-
/**
|
|
68
|
-
* Returns `true` when the system has internet connectivity.
|
|
69
|
-
* Probes DNS resolution against well-known stable domains.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* if (await isOnline()) {
|
|
74
|
-
* await fetchLatestVersion()
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
async function isOnline() {
|
|
79
|
-
for (const domain of TEST_DOMAINS) try {
|
|
80
|
-
await node_dns.promises.resolve(domain);
|
|
81
|
-
return true;
|
|
82
|
-
} catch {}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```ts
|
|
90
|
-
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
91
|
-
* // null when offline
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
async function executeIfOnline(fn) {
|
|
95
|
-
if (!await isOnline()) return null;
|
|
96
|
-
try {
|
|
97
|
-
return await fn();
|
|
98
|
-
} catch {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/telemetry.ts
|
|
104
|
-
/**
|
|
105
|
-
* Returns `true` when the current process runs inside a CI environment.
|
|
106
|
-
*/
|
|
107
|
-
function isCi() {
|
|
108
|
-
return isCIEnvironment();
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
112
|
-
*/
|
|
113
|
-
function isTelemetryDisabled() {
|
|
114
|
-
return node_process.default.env["DO_NOT_TRACK"] === "1" || node_process.default.env["DO_NOT_TRACK"] === "true" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "1" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.
|
|
118
|
-
* See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
|
|
119
|
-
*/
|
|
120
|
-
function buildOtlpPayload(event) {
|
|
121
|
-
const traceId = (0, node_crypto.randomBytes)(16).toString("hex");
|
|
122
|
-
const spanId = (0, node_crypto.randomBytes)(8).toString("hex");
|
|
123
|
-
const endTimeNs = BigInt(Date.now()) * 1000000n;
|
|
124
|
-
const startTimeNs = endTimeNs - BigInt(event.duration) * 1000000n;
|
|
125
|
-
const attributes = [
|
|
126
|
-
{
|
|
127
|
-
key: "kubb.command",
|
|
128
|
-
value: { stringValue: event.command }
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
key: "kubb.version",
|
|
132
|
-
value: { stringValue: event.kubbVersion }
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
key: "kubb.node_version",
|
|
136
|
-
value: { stringValue: event.nodeVersion }
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
key: "kubb.platform",
|
|
140
|
-
value: { stringValue: event.platform }
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
key: "kubb.ci",
|
|
144
|
-
value: { boolValue: event.ci }
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
key: "kubb.files_created",
|
|
148
|
-
value: { intValue: event.filesCreated }
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
key: "kubb.status",
|
|
152
|
-
value: { stringValue: event.status }
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
key: "kubb.plugins",
|
|
156
|
-
value: { arrayValue: { values: event.plugins.map((p) => ({ kvlistValue: { values: [{
|
|
157
|
-
key: "name",
|
|
158
|
-
value: { stringValue: p.name }
|
|
159
|
-
}, {
|
|
160
|
-
key: "options",
|
|
161
|
-
value: { stringValue: JSON.stringify({
|
|
162
|
-
...p.options,
|
|
163
|
-
usedEnumNames: void 0
|
|
164
|
-
}) }
|
|
165
|
-
}] } })) } }
|
|
166
|
-
}
|
|
167
|
-
];
|
|
168
|
-
return { resourceSpans: [{
|
|
169
|
-
resource: { attributes: [
|
|
170
|
-
{
|
|
171
|
-
key: "service.name",
|
|
172
|
-
value: { stringValue: "kubb-cli" }
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
key: "service.version",
|
|
176
|
-
value: { stringValue: event.kubbVersion }
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
key: "telemetry.sdk.language",
|
|
180
|
-
value: { stringValue: "nodejs" }
|
|
181
|
-
}
|
|
182
|
-
] },
|
|
183
|
-
scopeSpans: [{
|
|
184
|
-
scope: {
|
|
185
|
-
name: "kubb-cli",
|
|
186
|
-
version: event.kubbVersion
|
|
187
|
-
},
|
|
188
|
-
spans: [{
|
|
189
|
-
traceId,
|
|
190
|
-
spanId,
|
|
191
|
-
name: event.command,
|
|
192
|
-
kind: 1,
|
|
193
|
-
startTimeUnixNano: String(startTimeNs),
|
|
194
|
-
endTimeUnixNano: String(endTimeNs),
|
|
195
|
-
attributes,
|
|
196
|
-
status: { code: event.status === "success" ? 1 : 2 }
|
|
197
|
-
}]
|
|
198
|
-
}]
|
|
199
|
-
}] };
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Send an anonymous telemetry event to the Kubb OTLP endpoint.
|
|
203
|
-
* Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.
|
|
204
|
-
* Fails silently to never interrupt the generation process.
|
|
205
|
-
*/
|
|
206
|
-
async function sendTelemetry(event) {
|
|
207
|
-
if (isTelemetryDisabled()) return;
|
|
208
|
-
await executeIfOnline(async () => {
|
|
209
|
-
try {
|
|
210
|
-
await fetch(`${require_constants.OTLP_ENDPOINT}/v1/traces`, {
|
|
211
|
-
method: "POST",
|
|
212
|
-
headers: {
|
|
213
|
-
"Content-Type": "application/json",
|
|
214
|
-
"Kubb-Telemetry-Version": "1",
|
|
215
|
-
"Kubb-Telemetry-Source": "kubb-cli"
|
|
216
|
-
},
|
|
217
|
-
body: JSON.stringify(buildOtlpPayload(event)),
|
|
218
|
-
signal: AbortSignal.timeout(5e3)
|
|
219
|
-
});
|
|
220
|
-
} catch (_e) {}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Build an anonymous telemetry payload from a completed generation run.
|
|
225
|
-
* No file paths, OpenAPI specs, or secrets are included.
|
|
226
|
-
*/
|
|
227
|
-
function buildTelemetryEvent(options) {
|
|
228
|
-
const [seconds, nanoseconds] = node_process.default.hrtime(options.hrStart);
|
|
229
|
-
const duration = Math.round(seconds * 1e3 + nanoseconds / 1e6);
|
|
230
|
-
return {
|
|
231
|
-
command: options.command,
|
|
232
|
-
kubbVersion: options.kubbVersion,
|
|
233
|
-
nodeVersion: node_process.default.versions.node.split(".")[0],
|
|
234
|
-
platform: node_os.default.platform(),
|
|
235
|
-
ci: isCi(),
|
|
236
|
-
plugins: options.plugins ?? [],
|
|
237
|
-
duration,
|
|
238
|
-
filesCreated: options.filesCreated ?? 0,
|
|
239
|
-
status: options.status
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
//#endregion
|
|
243
|
-
Object.defineProperty(exports, "buildTelemetryEvent", {
|
|
244
|
-
enumerable: true,
|
|
245
|
-
get: function() {
|
|
246
|
-
return buildTelemetryEvent;
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
Object.defineProperty(exports, "canUseTTY", {
|
|
250
|
-
enumerable: true,
|
|
251
|
-
get: function() {
|
|
252
|
-
return canUseTTY;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
Object.defineProperty(exports, "executeIfOnline", {
|
|
256
|
-
enumerable: true,
|
|
257
|
-
get: function() {
|
|
258
|
-
return executeIfOnline;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
Object.defineProperty(exports, "isGitHubActions", {
|
|
262
|
-
enumerable: true,
|
|
263
|
-
get: function() {
|
|
264
|
-
return isGitHubActions;
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
Object.defineProperty(exports, "isTelemetryDisabled", {
|
|
268
|
-
enumerable: true,
|
|
269
|
-
get: function() {
|
|
270
|
-
return isTelemetryDisabled;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
Object.defineProperty(exports, "sendTelemetry", {
|
|
274
|
-
enumerable: true,
|
|
275
|
-
get: function() {
|
|
276
|
-
return sendTelemetry;
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
//# sourceMappingURL=telemetry-B80oJfxR.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-B80oJfxR.cjs","names":["dnsPromises","process","OTLP_ENDPOINT","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from './constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: Array<OtlpAnyValue> } }\ntype OtlpKvListValue = { kvlistValue: { values: Array<OtlpKeyValue> } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n events?: Array<OtlpSpanEvent>\n droppedEventsCount?: number\n links?: Array<OtlpSpanLink>\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: Array<OtlpSpan>\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: Array<OtlpScopeSpans>\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: Array<OtlpResourceSpans>\n}\n\n/**\n * Anonymous plugin name and options snapshot sent with each telemetry event.\n */\nexport type TelemetryPlugin = {\n /**\n * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.\n */\n name: string\n /**\n * anonymized plugin options snapshot, values are included but cannot be traced back to the user.\n */\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: Array<TelemetryPlugin>\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Returns `true` when the current process runs inside a CI environment.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: Array<OtlpKeyValue> = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: Array<TelemetryPlugin>\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,CAAC,QAAQ,IAAI;AACvB;;;;;;;;;;;;;AAcA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;AAEhB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YAAqB;CACnC,OAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACzF;;;;;;ACtDA,MAAM,eAAe;CAAC;CAAkB;CAAkB;AAAiB;;;;;;;;;;;;AAa3E,eAAsB,WAA6B;C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AO;CAC7D,MAAM,WAAW,KAAK,MAAM,UAAU,MAAO,cAAc,GAAG;CAE9D,OAAO;EACL,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,aAAaA,aAAAA,QAAQ,SAAS,KAAK,MAAM,GAAG,EAAE;EAC9C,UAAUE,QAAAA,QAAG,SAAS;EACtB,IAAI,KAAK;EACT,SAAS,QAAQ,WAAW,CAAC;EAC7B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;CAClB;AACF"}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import "./chunk-CRm0XQPb.js";
|
|
2
|
-
import { n as OTLP_ENDPOINT } from "./constants-CYxk4aNm.js";
|
|
3
|
-
import { randomBytes } from "node:crypto";
|
|
4
|
-
import { promises } from "node:dns";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import process$1 from "node:process";
|
|
7
|
-
//#region ../../internals/utils/src/env.ts
|
|
8
|
-
/**
|
|
9
|
-
* Returns `true` when running inside a GitHub Actions workflow.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* if (isGitHubActions()) {
|
|
14
|
-
* core.setOutput('result', 'ok')
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
function isGitHubActions() {
|
|
19
|
-
return !!process.env.GITHUB_ACTIONS;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns `true` when the process is running in a CI environment.
|
|
23
|
-
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
24
|
-
* TeamCity, Buildkite, and Azure Pipelines.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* if (isCIEnvironment()) {
|
|
29
|
-
* logger.level = 'error'
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
function isCIEnvironment() {
|
|
34
|
-
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
38
|
-
* width and is not running in CI.
|
|
39
|
-
*
|
|
40
|
-
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
41
|
-
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
42
|
-
* with a negative count and throw a `RangeError`). We therefore require a
|
|
43
|
-
* positive column count before declaring the TTY usable.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* if (canUseTTY()) {
|
|
48
|
-
* renderProgressBar()
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
function canUseTTY() {
|
|
53
|
-
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
//#region ../../internals/utils/src/network.ts
|
|
57
|
-
/**
|
|
58
|
-
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
59
|
-
*/
|
|
60
|
-
const TEST_DOMAINS = [
|
|
61
|
-
"dns.google.com",
|
|
62
|
-
"cloudflare.com",
|
|
63
|
-
"one.one.one.one"
|
|
64
|
-
];
|
|
65
|
-
/**
|
|
66
|
-
* Returns `true` when the system has internet connectivity.
|
|
67
|
-
* Probes DNS resolution against well-known stable domains.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* if (await isOnline()) {
|
|
72
|
-
* await fetchLatestVersion()
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
async function isOnline() {
|
|
77
|
-
for (const domain of TEST_DOMAINS) try {
|
|
78
|
-
await promises.resolve(domain);
|
|
79
|
-
return true;
|
|
80
|
-
} catch {}
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
89
|
-
* // null when offline
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
async function executeIfOnline(fn) {
|
|
93
|
-
if (!await isOnline()) return null;
|
|
94
|
-
try {
|
|
95
|
-
return await fn();
|
|
96
|
-
} catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/telemetry.ts
|
|
102
|
-
/**
|
|
103
|
-
* Returns `true` when the current process runs inside a CI environment.
|
|
104
|
-
*/
|
|
105
|
-
function isCi() {
|
|
106
|
-
return isCIEnvironment();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
110
|
-
*/
|
|
111
|
-
function isTelemetryDisabled() {
|
|
112
|
-
return process$1.env["DO_NOT_TRACK"] === "1" || process$1.env["DO_NOT_TRACK"] === "true" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "1" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.
|
|
116
|
-
* See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
|
|
117
|
-
*/
|
|
118
|
-
function buildOtlpPayload(event) {
|
|
119
|
-
const traceId = randomBytes(16).toString("hex");
|
|
120
|
-
const spanId = randomBytes(8).toString("hex");
|
|
121
|
-
const endTimeNs = BigInt(Date.now()) * 1000000n;
|
|
122
|
-
const startTimeNs = endTimeNs - BigInt(event.duration) * 1000000n;
|
|
123
|
-
const attributes = [
|
|
124
|
-
{
|
|
125
|
-
key: "kubb.command",
|
|
126
|
-
value: { stringValue: event.command }
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
key: "kubb.version",
|
|
130
|
-
value: { stringValue: event.kubbVersion }
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
key: "kubb.node_version",
|
|
134
|
-
value: { stringValue: event.nodeVersion }
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
key: "kubb.platform",
|
|
138
|
-
value: { stringValue: event.platform }
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
key: "kubb.ci",
|
|
142
|
-
value: { boolValue: event.ci }
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
key: "kubb.files_created",
|
|
146
|
-
value: { intValue: event.filesCreated }
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
key: "kubb.status",
|
|
150
|
-
value: { stringValue: event.status }
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
key: "kubb.plugins",
|
|
154
|
-
value: { arrayValue: { values: event.plugins.map((p) => ({ kvlistValue: { values: [{
|
|
155
|
-
key: "name",
|
|
156
|
-
value: { stringValue: p.name }
|
|
157
|
-
}, {
|
|
158
|
-
key: "options",
|
|
159
|
-
value: { stringValue: JSON.stringify({
|
|
160
|
-
...p.options,
|
|
161
|
-
usedEnumNames: void 0
|
|
162
|
-
}) }
|
|
163
|
-
}] } })) } }
|
|
164
|
-
}
|
|
165
|
-
];
|
|
166
|
-
return { resourceSpans: [{
|
|
167
|
-
resource: { attributes: [
|
|
168
|
-
{
|
|
169
|
-
key: "service.name",
|
|
170
|
-
value: { stringValue: "kubb-cli" }
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
key: "service.version",
|
|
174
|
-
value: { stringValue: event.kubbVersion }
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
key: "telemetry.sdk.language",
|
|
178
|
-
value: { stringValue: "nodejs" }
|
|
179
|
-
}
|
|
180
|
-
] },
|
|
181
|
-
scopeSpans: [{
|
|
182
|
-
scope: {
|
|
183
|
-
name: "kubb-cli",
|
|
184
|
-
version: event.kubbVersion
|
|
185
|
-
},
|
|
186
|
-
spans: [{
|
|
187
|
-
traceId,
|
|
188
|
-
spanId,
|
|
189
|
-
name: event.command,
|
|
190
|
-
kind: 1,
|
|
191
|
-
startTimeUnixNano: String(startTimeNs),
|
|
192
|
-
endTimeUnixNano: String(endTimeNs),
|
|
193
|
-
attributes,
|
|
194
|
-
status: { code: event.status === "success" ? 1 : 2 }
|
|
195
|
-
}]
|
|
196
|
-
}]
|
|
197
|
-
}] };
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Send an anonymous telemetry event to the Kubb OTLP endpoint.
|
|
201
|
-
* Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.
|
|
202
|
-
* Fails silently to never interrupt the generation process.
|
|
203
|
-
*/
|
|
204
|
-
async function sendTelemetry(event) {
|
|
205
|
-
if (isTelemetryDisabled()) return;
|
|
206
|
-
await executeIfOnline(async () => {
|
|
207
|
-
try {
|
|
208
|
-
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
209
|
-
method: "POST",
|
|
210
|
-
headers: {
|
|
211
|
-
"Content-Type": "application/json",
|
|
212
|
-
"Kubb-Telemetry-Version": "1",
|
|
213
|
-
"Kubb-Telemetry-Source": "kubb-cli"
|
|
214
|
-
},
|
|
215
|
-
body: JSON.stringify(buildOtlpPayload(event)),
|
|
216
|
-
signal: AbortSignal.timeout(5e3)
|
|
217
|
-
});
|
|
218
|
-
} catch (_e) {}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Build an anonymous telemetry payload from a completed generation run.
|
|
223
|
-
* No file paths, OpenAPI specs, or secrets are included.
|
|
224
|
-
*/
|
|
225
|
-
function buildTelemetryEvent(options) {
|
|
226
|
-
const [seconds, nanoseconds] = process$1.hrtime(options.hrStart);
|
|
227
|
-
const duration = Math.round(seconds * 1e3 + nanoseconds / 1e6);
|
|
228
|
-
return {
|
|
229
|
-
command: options.command,
|
|
230
|
-
kubbVersion: options.kubbVersion,
|
|
231
|
-
nodeVersion: process$1.versions.node.split(".")[0],
|
|
232
|
-
platform: os.platform(),
|
|
233
|
-
ci: isCi(),
|
|
234
|
-
plugins: options.plugins ?? [],
|
|
235
|
-
duration,
|
|
236
|
-
filesCreated: options.filesCreated ?? 0,
|
|
237
|
-
status: options.status
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
export { canUseTTY as a, executeIfOnline as i, isTelemetryDisabled as n, isGitHubActions as o, sendTelemetry as r, buildTelemetryEvent as t };
|
|
242
|
-
|
|
243
|
-
//# sourceMappingURL=telemetry-ueaMzs_c.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-ueaMzs_c.js","names":["dnsPromises","process"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from './constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: Array<OtlpAnyValue> } }\ntype OtlpKvListValue = { kvlistValue: { values: Array<OtlpKeyValue> } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n events?: Array<OtlpSpanEvent>\n droppedEventsCount?: number\n links?: Array<OtlpSpanLink>\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: Array<OtlpKeyValue>\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: Array<OtlpSpan>\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: Array<OtlpScopeSpans>\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: Array<OtlpResourceSpans>\n}\n\n/**\n * Anonymous plugin name and options snapshot sent with each telemetry event.\n */\nexport type TelemetryPlugin = {\n /**\n * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.\n */\n name: string\n /**\n * anonymized plugin options snapshot, values are included but cannot be traced back to the user.\n */\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: Array<TelemetryPlugin>\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Returns `true` when the current process runs inside a CI environment.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: Array<OtlpKeyValue> = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: Array<TelemetryPlugin>\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,CAAC,QAAQ,IAAI;AACvB;;;;;;;;;;;;;AAcA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,QAAQ,IAAI,UACZ,QAAQ,IAAI,oBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI;AAEhB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YAAqB;CACnC,OAAO,CAAC,CAAC,QAAQ,OAAO,UAAU,QAAQ,OAAO,WAAW,KAAK,KAAK,CAAC,gBAAgB;AACzF;;;;;;ACtDA,MAAM,eAAe;CAAC;CAAkB;CAAkB;AAAiB;;;;;;;;;;;;AAa3E,eAAsB,WAA6B;CACjD,KAAK,MAAM,UAAU,cACnB,IAAI;EACF,MAAMA,SAAY,QAAQ,MAAM;EAChC,OAAO;CACT,QAAQ,CAER;CAGF,OAAO;AACT;;;;;;;;;;AAWA,eAAsB,gBAA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,WAAW,CAAC;EAC7B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;CAClB;AACF"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'node:util'
|
|
2
|
-
import { type Diagnostic, diagnosticCode, Diagnostics, type DiagnosticSeverity, isProblemDiagnostic } from '@kubb/core'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Glyph and accent color per severity, matching the miette/oxlint convention
|
|
6
|
-
* (`×` error, `⚠` warning, `ℹ` advice).
|
|
7
|
-
*/
|
|
8
|
-
const severityStyle: Record<DiagnosticSeverity, { glyph: string; color: 'red' | 'yellow' | 'blue' }> = {
|
|
9
|
-
error: { glyph: '×', color: 'red' },
|
|
10
|
-
warning: { glyph: '⚠', color: 'yellow' },
|
|
11
|
-
info: { glyph: 'ℹ', color: 'blue' },
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The colored, bold severity glyph (`×`, `⚠`, `ℹ`) on its own. Pass it as clack's
|
|
16
|
-
* `symbol` so clack owns the gutter and adds the bar to the continuation lines,
|
|
17
|
-
* instead of baking the glyph into the message text.
|
|
18
|
-
*/
|
|
19
|
-
export function diagnosticSymbol(severity: DiagnosticSeverity): string {
|
|
20
|
-
const { glyph, color } = severityStyle[severity]
|
|
21
|
-
return styleText(color, styleText('bold', glyph))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The `plugin(CODE): message` headline, without the leading severity glyph.
|
|
26
|
-
*/
|
|
27
|
-
export function diagnosticHeadline(diagnostic: Diagnostic): string {
|
|
28
|
-
const { code, severity, message } = diagnostic
|
|
29
|
-
const plugin = isProblemDiagnostic(diagnostic) ? diagnostic.plugin : undefined
|
|
30
|
-
const { color } = severityStyle[severity]
|
|
31
|
-
|
|
32
|
-
const rule = styleText(color, styleText('bold', plugin ? `${plugin}(${code})` : code))
|
|
33
|
-
return `${rule}: ${message}`
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The detail lines below the headline: optional `at <pointer>`, `help:`, and
|
|
38
|
-
* `docs:`. OpenAPI has no line/column, so the location is the JSON pointer the
|
|
39
|
-
* adapter built. Each line keeps a two-space indent so it sits under the headline.
|
|
40
|
-
*/
|
|
41
|
-
export function diagnosticDetails(diagnostic: Diagnostic): Array<string> {
|
|
42
|
-
const { code } = diagnostic
|
|
43
|
-
const problem = isProblemDiagnostic(diagnostic) ? diagnostic : undefined
|
|
44
|
-
const location = problem?.location
|
|
45
|
-
const help = problem?.help
|
|
46
|
-
const lines: Array<string> = []
|
|
47
|
-
|
|
48
|
-
if (location && 'pointer' in location) {
|
|
49
|
-
lines.push(` ${styleText('dim', 'at')} ${styleText('cyan', location.pointer)}`)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (help) {
|
|
53
|
-
lines.push(` ${styleText('cyan', 'help:')} ${help}`)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (code !== diagnosticCode.unknown) {
|
|
57
|
-
lines.push(` ${styleText('dim', 'docs:')} ${styleText('cyan', Diagnostics.docsUrl(code))}`)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return lines
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Renders a {@link Diagnostic} in the oxlint style as a self-contained block: a
|
|
65
|
-
* `× plugin(CODE): message` header followed by the {@link diagnosticDetails}.
|
|
66
|
-
* Use this where clack's gutter is not available (plain, file output); clack
|
|
67
|
-
* loggers pass {@link diagnosticSymbol}, {@link diagnosticHeadline}, and
|
|
68
|
-
* {@link diagnosticDetails} to `clack.log.message` instead.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* formatDiagnostic({ code: 'KUBB_REF_NOT_FOUND', severity: 'error', message: 'Could not find Pet', help: 'Add Pet under components.schemas.', plugin: '@kubb/plugin-zod', location: { kind: 'schema', pointer: '#/components/schemas/Pet' } })
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export function formatDiagnostic(diagnostic: Diagnostic): Array<string> {
|
|
76
|
-
return [`${diagnosticSymbol(diagnostic.severity)} ${diagnosticHeadline(diagnostic)}`, ...diagnosticDetails(diagnostic)]
|
|
77
|
-
}
|