@kubb/cli 5.9.3 → 5.9.4

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.
Files changed (108) hide show
  1. package/dist/Telemetry-ByFeVTz5.cjs +314 -0
  2. package/dist/Telemetry-ByFeVTz5.cjs.map +1 -0
  3. package/dist/Telemetry-E_BBHmnT.js +259 -0
  4. package/dist/Telemetry-E_BBHmnT.js.map +1 -0
  5. package/dist/background-CZ2nVKwB.js +1 -0
  6. package/dist/{background-BcRoKru0.cjs → background-DdUVvDwi.cjs} +7 -6
  7. package/dist/{background-BcRoKru0.cjs.map → background-DdUVvDwi.cjs.map} +1 -1
  8. package/dist/{background-CCex47-d.js → background-H30JH70B.js} +3 -2
  9. package/dist/{background-CCex47-d.js.map → background-H30JH70B.js.map} +1 -1
  10. package/dist/{reporters-B4rZOlo8.cjs → config-Ck2JHe5r.cjs} +36 -4
  11. package/dist/config-Ck2JHe5r.cjs.map +1 -0
  12. package/dist/{reporters-H21Jvrff.js → config-DxePdyxe.js} +29 -3
  13. package/dist/config-DxePdyxe.js.map +1 -0
  14. package/dist/credentials-C8tjAhTo.js +1 -0
  15. package/dist/credentials-CZK6zPLv.js +62 -0
  16. package/dist/credentials-CZK6zPLv.js.map +1 -0
  17. package/dist/credentials-DDaKqtJn.cjs +113 -0
  18. package/dist/credentials-DDaKqtJn.cjs.map +1 -0
  19. package/dist/index.cjs +702 -208
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.js +697 -207
  22. package/dist/index.js.map +1 -1
  23. package/dist/{output-BnK0scpX.cjs → output-Cd3Kmvo0.cjs} +141 -66
  24. package/dist/output-Cd3Kmvo0.cjs.map +1 -0
  25. package/dist/{output-qFt4vV7K.js → output-DS5hyqwL.js} +173 -129
  26. package/dist/output-DS5hyqwL.js.map +1 -0
  27. package/dist/{registry-B7BvdrGE.js → registry-CSXUuuCy.js} +2 -2
  28. package/dist/{registry-B7BvdrGE.js.map → registry-CSXUuuCy.js.map} +1 -1
  29. package/dist/{registry-DER9aRyg.cjs → registry-CrvQxnxy.cjs} +6 -6
  30. package/dist/{registry-DER9aRyg.cjs.map → registry-CrvQxnxy.cjs.map} +1 -1
  31. package/dist/rolldown-runtime-CPE0t6oh.cjs +53 -0
  32. package/dist/{run-QPsBYkq_.js → run-BPD5Vaon.js} +5 -7
  33. package/dist/{run-QPsBYkq_.js.map → run-BPD5Vaon.js.map} +1 -1
  34. package/dist/{run-Co732JNO.cjs → run-C0Tfrddq.cjs} +5 -6
  35. package/dist/{run-Co732JNO.cjs.map → run-C0Tfrddq.cjs.map} +1 -1
  36. package/dist/{run-DFos0eOY.cjs → run-CbN00IHp.cjs} +16 -18
  37. package/dist/{run-DFos0eOY.cjs.map → run-CbN00IHp.cjs.map} +1 -1
  38. package/dist/{run-B1jaQu6Q.js → run-CecrPSop.js} +2 -3
  39. package/dist/{run-B1jaQu6Q.js.map → run-CecrPSop.js.map} +1 -1
  40. package/dist/{run-DunTcXOS.js → run-Ck04_W4q.js} +2 -3
  41. package/dist/{run-DunTcXOS.js.map → run-Ck04_W4q.js.map} +1 -1
  42. package/dist/{run-BRUwQ5Y7.js → run-DcP1czVQ.js} +25 -84
  43. package/dist/run-DcP1czVQ.js.map +1 -0
  44. package/dist/{run-CIvFRMLt.cjs → run-Dyc52IzX.cjs} +5 -6
  45. package/dist/{run-CIvFRMLt.cjs.map → run-Dyc52IzX.cjs.map} +1 -1
  46. package/dist/{run-DxGkjzRm.cjs → run-QqLDhthl.cjs} +46 -158
  47. package/dist/run-QqLDhthl.cjs.map +1 -0
  48. package/dist/run-WkXSXG2V.js +1 -0
  49. package/dist/{snapshot-DUJU70H_.cjs → snapshot-NGLcfG6E.cjs} +17 -26
  50. package/dist/snapshot-NGLcfG6E.cjs.map +1 -0
  51. package/dist/{snapshot-CkpJr-gr.js → snapshot-iEjgROga.js} +15 -24
  52. package/dist/snapshot-iEjgROga.js.map +1 -0
  53. package/dist/studioWorker.js +2 -2
  54. package/package.json +7 -8
  55. package/dist/Telemetry-C9gmBTr0.cjs +0 -231
  56. package/dist/Telemetry-C9gmBTr0.cjs.map +0 -1
  57. package/dist/Telemetry-CSc7OVsv.js +0 -207
  58. package/dist/Telemetry-CSc7OVsv.js.map +0 -1
  59. package/dist/agent-BPIqnEl2.js +0 -59
  60. package/dist/agent-BPIqnEl2.js.map +0 -1
  61. package/dist/agent-DElUuYuy.cjs +0 -120
  62. package/dist/agent-DElUuYuy.cjs.map +0 -1
  63. package/dist/background-1AFVK_yN.js +0 -1
  64. package/dist/commands-BuY0nrlU.cjs +0 -87
  65. package/dist/commands-BuY0nrlU.cjs.map +0 -1
  66. package/dist/commands-atq2z0Bo.js +0 -81
  67. package/dist/commands-atq2z0Bo.js.map +0 -1
  68. package/dist/config-B6UIKcl1.js +0 -117
  69. package/dist/config-B6UIKcl1.js.map +0 -1
  70. package/dist/config-Bo9ro7vg.cjs +0 -129
  71. package/dist/config-Bo9ro7vg.cjs.map +0 -1
  72. package/dist/constants-Cii4HX64.js +0 -12
  73. package/dist/constants-Cii4HX64.js.map +0 -1
  74. package/dist/constants-Df449N47.cjs +0 -29
  75. package/dist/constants-Df449N47.cjs.map +0 -1
  76. package/dist/errors-BdA8M78q.cjs +0 -43
  77. package/dist/errors-BdA8M78q.cjs.map +0 -1
  78. package/dist/errors-DmC83ALX.js +0 -32
  79. package/dist/errors-DmC83ALX.js.map +0 -1
  80. package/dist/output-BnK0scpX.cjs.map +0 -1
  81. package/dist/output-qFt4vV7K.js.map +0 -1
  82. package/dist/reporters-B4rZOlo8.cjs.map +0 -1
  83. package/dist/reporters-H21Jvrff.js.map +0 -1
  84. package/dist/run-BGTUbY2h.cjs +0 -130
  85. package/dist/run-BGTUbY2h.cjs.map +0 -1
  86. package/dist/run-BPQzGEIs.js +0 -178
  87. package/dist/run-BPQzGEIs.js.map +0 -1
  88. package/dist/run-BRUwQ5Y7.js.map +0 -1
  89. package/dist/run-BYff_byB.js +0 -71
  90. package/dist/run-BYff_byB.js.map +0 -1
  91. package/dist/run-Bhs7mJ1f.cjs +0 -79
  92. package/dist/run-Bhs7mJ1f.cjs.map +0 -1
  93. package/dist/run-CH48n-MJ.js +0 -1
  94. package/dist/run-DfEoWJuy.js +0 -126
  95. package/dist/run-DfEoWJuy.js.map +0 -1
  96. package/dist/run-Dm9OZUkQ.cjs +0 -182
  97. package/dist/run-Dm9OZUkQ.cjs.map +0 -1
  98. package/dist/run-DpAMfkm5.cjs +0 -72
  99. package/dist/run-DpAMfkm5.cjs.map +0 -1
  100. package/dist/run-DxGkjzRm.cjs.map +0 -1
  101. package/dist/run-DxxYCqEo.js +0 -77
  102. package/dist/run-DxxYCqEo.js.map +0 -1
  103. package/dist/snapshot-CkpJr-gr.js.map +0 -1
  104. package/dist/snapshot-DUJU70H_.cjs.map +0 -1
  105. package/dist/utils-BHW8kA8P.js +0 -83
  106. package/dist/utils-BHW8kA8P.js.map +0 -1
  107. package/dist/utils-BzQ46pgd.cjs +0 -109
  108. package/dist/utils-BzQ46pgd.cjs.map +0 -1
@@ -0,0 +1,314 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CPE0t6oh.cjs");
2
+ let node_crypto = require("node:crypto");
3
+ let node_os = require("node:os");
4
+ node_os = require_rolldown_runtime.__toESM(node_os, 1);
5
+ let node_process = require("node:process");
6
+ node_process = require_rolldown_runtime.__toESM(node_process, 1);
7
+ let gunshi_agent = require("gunshi/agent");
8
+ //#region ../../internals/utils/src/errors.ts
9
+ /**
10
+ * Coerces an unknown thrown value to an `Error` instance.
11
+ * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * try { ... } catch(err) {
16
+ * throw new Error('Build failed', { cause: toError(err) })
17
+ * }
18
+ * ```
19
+ */
20
+ function toError(value) {
21
+ return value instanceof Error ? value : new Error(String(value));
22
+ }
23
+ /**
24
+ * Extracts a human-readable message from any thrown value.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * getErrorMessage(new Error('oops')) // 'oops'
29
+ * getErrorMessage('plain string') // 'plain string'
30
+ * ```
31
+ */
32
+ function getErrorMessage(value) {
33
+ return value instanceof Error ? value.message : String(value);
34
+ }
35
+ //#endregion
36
+ //#region ../../internals/utils/src/isCIEnvironment.ts
37
+ /**
38
+ * Returns `true` when a known CI provider has set its environment variable.
39
+ * `CI=false` and `CI=0` count as not CI, so a user can opt out locally.
40
+ */
41
+ function isCIEnvironment() {
42
+ const ci = node_process.default.env.CI;
43
+ return !!(ci && ci !== "false" && ci !== "0" || node_process.default.env.GITHUB_ACTIONS || node_process.default.env.GITLAB_CI || node_process.default.env.BITBUCKET_BUILD_NUMBER || node_process.default.env.JENKINS_URL || node_process.default.env.CIRCLECI || node_process.default.env.TRAVIS || node_process.default.env.TEAMCITY_VERSION || node_process.default.env.BUILDKITE || node_process.default.env.TF_BUILD);
44
+ }
45
+ //#endregion
46
+ //#region ../../internals/utils/src/runtime.ts
47
+ const isBun = typeof Bun !== "undefined";
48
+ const isDeno = "Deno" in globalThis;
49
+ /**
50
+ * The JavaScript runtime executing the current process: its name, version and whether it is Bun.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
55
+ * ```
56
+ */
57
+ const runtime = {
58
+ isBun,
59
+ ...detect()
60
+ };
61
+ function detect() {
62
+ if (isBun) return {
63
+ name: "bun",
64
+ version: process.versions.bun ?? ""
65
+ };
66
+ if (isDeno) return {
67
+ name: "deno",
68
+ version: globalThis.Deno?.version?.deno ?? ""
69
+ };
70
+ return {
71
+ name: "node",
72
+ version: process.versions?.node ?? ""
73
+ };
74
+ }
75
+ //#endregion
76
+ //#region ../../internals/utils/src/time.ts
77
+ /**
78
+ * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
79
+ * Rounds to 2 decimal places for sub-millisecond precision without noise.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const start = process.hrtime()
84
+ * doWork()
85
+ * getElapsedMs(start) // 42.35
86
+ * ```
87
+ */
88
+ function getElapsedMs(hrStart) {
89
+ const [seconds, nanoseconds] = process.hrtime(hrStart);
90
+ const ms = seconds * 1e3 + nanoseconds / 1e6;
91
+ return Math.round(ms * 100) / 100;
92
+ }
93
+ /**
94
+ * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * formatMs(250) // '250ms'
99
+ * formatMs(1500) // '1.50s'
100
+ * formatMs(90000) // '1m 30.0s'
101
+ * ```
102
+ */
103
+ function formatMs(ms) {
104
+ if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
105
+ if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
106
+ return `${Math.round(ms)}ms`;
107
+ }
108
+ //#endregion
109
+ //#region package.json
110
+ var version = "5.9.4";
111
+ //#endregion
112
+ //#region src/Telemetry.ts
113
+ /** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
114
+ const OTLP_ENDPOINT = "https://otlp.kubb.dev";
115
+ /**
116
+ * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
117
+ */
118
+ function isDisabled() {
119
+ return ["DO_NOT_TRACK", "KUBB_DISABLE_TELEMETRY"].some((name) => ["1", "true"].includes(node_process.default.env[name] ?? ""));
120
+ }
121
+ /** Tracks one command run for the running CLI version; returns the reporter the command calls once it knows how it ended. */
122
+ function trackRun({ command, hrStart }) {
123
+ return (result) => sendTelemetry(buildOtlpPayload({
124
+ command,
125
+ duration: Math.round(getElapsedMs(hrStart)),
126
+ ...result
127
+ }));
128
+ }
129
+ /**
130
+ * The OTLP trace payload for one run: a span named after the command whose attributes are the
131
+ * anonymous run facts. The attribute keys are the contract with otlp.kubb.dev.
132
+ *
133
+ * @see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
134
+ */
135
+ function buildOtlpPayload({ command, duration, status, plugins = [], filesCreated = 0 }) {
136
+ const traceId = (0, node_crypto.randomBytes)(16).toString("hex");
137
+ const spanId = (0, node_crypto.randomBytes)(8).toString("hex");
138
+ const endTimeNs = BigInt(Date.now()) * 1000000n;
139
+ const startTimeNs = endTimeNs - BigInt(duration) * 1000000n;
140
+ const pluginNames = [...new Set(plugins.map((plugin) => plugin.name))].sort();
141
+ const agent = (0, gunshi_agent.getAgentProfile)();
142
+ const attributes = [
143
+ {
144
+ key: "kubb.command",
145
+ value: { stringValue: command }
146
+ },
147
+ {
148
+ key: "kubb.version",
149
+ value: { stringValue: version }
150
+ },
151
+ {
152
+ key: "kubb.node_version",
153
+ value: { stringValue: node_process.default.versions.node.split(".")[0] }
154
+ },
155
+ {
156
+ key: "kubb.runtime",
157
+ value: { stringValue: runtime.name }
158
+ },
159
+ {
160
+ key: "kubb.runtime_version",
161
+ value: { stringValue: runtime.version.split(".")[0] }
162
+ },
163
+ {
164
+ key: "kubb.platform",
165
+ value: { stringValue: node_os.default.platform() }
166
+ },
167
+ {
168
+ key: "kubb.ci",
169
+ value: { boolValue: isCIEnvironment() }
170
+ },
171
+ ...agent.isAgent && agent.name ? [{
172
+ key: "kubb.agent",
173
+ value: { stringValue: agent.name }
174
+ }] : [],
175
+ {
176
+ key: "kubb.files_created",
177
+ value: { intValue: filesCreated }
178
+ },
179
+ {
180
+ key: "kubb.status",
181
+ value: { stringValue: status }
182
+ },
183
+ {
184
+ key: "kubb.plugins",
185
+ value: { arrayValue: { values: pluginNames.map((name) => ({ stringValue: name })) } }
186
+ },
187
+ ...pluginNames.map((name) => ({
188
+ key: `kubb.plugin.${name}`,
189
+ value: { boolValue: true }
190
+ })),
191
+ {
192
+ key: "kubb.plugin_options",
193
+ value: { arrayValue: { values: plugins.map((p) => ({ kvlistValue: { values: [{
194
+ key: "name",
195
+ value: { stringValue: p.name }
196
+ }, {
197
+ key: "options",
198
+ value: { stringValue: JSON.stringify({
199
+ ...p.options,
200
+ usedEnumNames: void 0
201
+ }) }
202
+ }] } })) } }
203
+ }
204
+ ];
205
+ return { resourceSpans: [{
206
+ resource: { attributes: [
207
+ {
208
+ key: "service.name",
209
+ value: { stringValue: "kubb" }
210
+ },
211
+ {
212
+ key: "service.version",
213
+ value: { stringValue: version }
214
+ },
215
+ {
216
+ key: "telemetry.sdk.language",
217
+ value: { stringValue: "nodejs" }
218
+ }
219
+ ] },
220
+ scopeSpans: [{
221
+ scope: {
222
+ name: "kubb-core",
223
+ version
224
+ },
225
+ spans: [{
226
+ traceId,
227
+ spanId,
228
+ name: command,
229
+ kind: 1,
230
+ startTimeUnixNano: String(startTimeNs),
231
+ endTimeUnixNano: String(endTimeNs),
232
+ attributes,
233
+ status: { code: status === "success" ? 1 : 2 }
234
+ }]
235
+ }]
236
+ }] };
237
+ }
238
+ /**
239
+ * Send an OTLP payload to the Kubb endpoint. Respects `DO_NOT_TRACK` and
240
+ * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run. No file
241
+ * paths, OpenAPI specs, or secrets are sent.
242
+ */
243
+ async function sendTelemetry(payload) {
244
+ if (isDisabled()) return;
245
+ try {
246
+ await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
247
+ method: "POST",
248
+ headers: {
249
+ "Content-Type": "application/json",
250
+ "Kubb-Telemetry-Version": "1",
251
+ "Kubb-Telemetry-Source": "kubb-cli"
252
+ },
253
+ body: JSON.stringify(payload),
254
+ signal: AbortSignal.timeout(5e3)
255
+ });
256
+ } catch (_e) {}
257
+ }
258
+ //#endregion
259
+ Object.defineProperty(exports, "formatMs", {
260
+ enumerable: true,
261
+ get: function() {
262
+ return formatMs;
263
+ }
264
+ });
265
+ Object.defineProperty(exports, "getElapsedMs", {
266
+ enumerable: true,
267
+ get: function() {
268
+ return getElapsedMs;
269
+ }
270
+ });
271
+ Object.defineProperty(exports, "getErrorMessage", {
272
+ enumerable: true,
273
+ get: function() {
274
+ return getErrorMessage;
275
+ }
276
+ });
277
+ Object.defineProperty(exports, "isCIEnvironment", {
278
+ enumerable: true,
279
+ get: function() {
280
+ return isCIEnvironment;
281
+ }
282
+ });
283
+ Object.defineProperty(exports, "isDisabled", {
284
+ enumerable: true,
285
+ get: function() {
286
+ return isDisabled;
287
+ }
288
+ });
289
+ Object.defineProperty(exports, "runtime", {
290
+ enumerable: true,
291
+ get: function() {
292
+ return runtime;
293
+ }
294
+ });
295
+ Object.defineProperty(exports, "toError", {
296
+ enumerable: true,
297
+ get: function() {
298
+ return toError;
299
+ }
300
+ });
301
+ Object.defineProperty(exports, "trackRun", {
302
+ enumerable: true,
303
+ get: function() {
304
+ return trackRun;
305
+ }
306
+ });
307
+ Object.defineProperty(exports, "version", {
308
+ enumerable: true,
309
+ get: function() {
310
+ return version;
311
+ }
312
+ });
313
+
314
+ //# sourceMappingURL=Telemetry-ByFeVTz5.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Telemetry-ByFeVTz5.cjs","names":["process","process","randomBytes","getAgentProfile","os"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/isCIEnvironment.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/time.ts","../package.json","../src/Telemetry.ts"],"sourcesContent":["/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n","import process from 'node:process'\n\n/**\n * Returns `true` when a known CI provider has set its environment variable.\n * `CI=false` and `CI=0` count as not CI, so a user can opt out locally.\n */\nexport function isCIEnvironment(): boolean {\n const ci = process.env.CI\n return !!(\n (ci && ci !== 'false' && ci !== '0') ||\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","// Bun polyfills `process.versions.node`, so detection keys off the globals instead.\nconst isBun = typeof Bun !== 'undefined'\nconst isDeno = 'Deno' in globalThis\n\n/**\n * The JavaScript runtime executing the current process: its name, version and whether it is Bun.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport const runtime = { isBun, ...detect() } as const\n\nfunction detect(): { name: 'bun' | 'deno' | 'node'; version: string } {\n if (isBun) return { name: 'bun', version: process.versions.bun ?? '' }\n if (isDeno) return { name: 'deno', version: (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? '' }\n return { name: 'node', version: process.versions?.node ?? '' }\n}\n","/**\n * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.\n * Rounds to 2 decimal places for sub-millisecond precision without noise.\n *\n * @example\n * ```ts\n * const start = process.hrtime()\n * doWork()\n * getElapsedMs(start) // 42.35\n * ```\n */\nexport function getElapsedMs(hrStart: [number, number]): number {\n const [seconds, nanoseconds] = process.hrtime(hrStart)\n const ms = seconds * 1000 + nanoseconds / 1e6\n return Math.round(ms * 100) / 100\n}\n\n/**\n * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).\n *\n * @example\n * ```ts\n * formatMs(250) // '250ms'\n * formatMs(1500) // '1.50s'\n * formatMs(90000) // '1m 30.0s'\n * ```\n */\nexport function formatMs(ms: number): string {\n if (ms >= 60000) {\n const mins = Math.floor(ms / 60000)\n const secs = ((ms % 60000) / 1000).toFixed(1)\n return `${mins}m ${secs}s`\n }\n\n if (ms >= 1000) {\n return `${(ms / 1000).toFixed(2)}s`\n }\n return `${Math.round(ms)}ms`\n}\n","","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { getElapsedMs, isCIEnvironment, runtime } from '@internals/utils'\nimport { getAgentProfile } from 'gunshi/agent'\nimport { version } from '../package.json'\n\n/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */\nconst OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\ntype TelemetryCommand = 'generate' | 'mcp' | 'studio' | 'validate'\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 snapshot of the plugin options. Values are included but cannot be traced back to a user.\n */\n options: Record<string, unknown>\n}\n\n/** How a command run ended, as the command reports it to the function {@link trackRun} returned. */\ntype RunResult = {\n status: 'success' | 'failed'\n plugins?: Array<TelemetryPlugin>\n filesCreated?: number\n}\n\n/**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\nexport function isDisabled(): boolean {\n return ['DO_NOT_TRACK', 'KUBB_DISABLE_TELEMETRY'].some((name) => ['1', 'true'].includes(process.env[name] ?? ''))\n}\n\n/** Tracks one command run for the running CLI version; returns the reporter the command calls once it knows how it ended. */\nexport function trackRun({ command, hrStart }: { command: TelemetryCommand; hrStart: [number, number] }): (result: RunResult) => Promise<void> {\n return (result) => sendTelemetry(buildOtlpPayload({ command, duration: Math.round(getElapsedMs(hrStart)), ...result }))\n}\n\n/**\n * The OTLP trace payload for one run: a span named after the command whose attributes are the\n * anonymous run facts. The attribute keys are the contract with otlp.kubb.dev.\n *\n * @see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload({ command, duration, status, plugins = [], filesCreated = 0 }: RunResult & { command: TelemetryCommand; duration: number }) {\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(duration) * 1_000_000n\n const pluginNames = [...new Set(plugins.map((plugin) => plugin.name))].sort()\n const agent = getAgentProfile()\n\n const attributes = [\n { key: 'kubb.command', value: { stringValue: command } },\n { key: 'kubb.version', value: { stringValue: version } },\n { key: 'kubb.node_version', value: { stringValue: process.versions.node.split('.')[0] as string } },\n { key: 'kubb.runtime', value: { stringValue: runtime.name } },\n { key: 'kubb.runtime_version', value: { stringValue: runtime.version.split('.')[0] as string } },\n { key: 'kubb.platform', value: { stringValue: os.platform() } },\n { key: 'kubb.ci', value: { boolValue: isCIEnvironment() } },\n ...(agent.isAgent && agent.name ? [{ key: 'kubb.agent', value: { stringValue: agent.name } }] : []),\n { key: 'kubb.files_created', value: { intValue: filesCreated } },\n { key: 'kubb.status', value: { stringValue: status } },\n {\n key: 'kubb.plugins',\n value: { arrayValue: { values: pluginNames.map((name) => ({ stringValue: name })) } },\n },\n ...pluginNames.map((name) => ({ key: `kubb.plugin.${name}`, value: { boolValue: true } })),\n {\n key: 'kubb.plugin_options',\n value: {\n arrayValue: {\n values: plugins.map((p) => ({\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 return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb' } },\n { key: 'service.version', value: { stringValue: version } },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-core', version },\n spans: [\n {\n traceId,\n spanId,\n name: command,\n kind: 1,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: status === 'success' ? 1 : 2,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an OTLP payload to the Kubb endpoint. Respects `DO_NOT_TRACK` and\n * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run. No file\n * paths, OpenAPI specs, or secrets are sent.\n */\nexport async function sendTelemetry(payload: ReturnType<typeof buildOtlpPayload>): Promise<void> {\n if (isDisabled()) {\n return\n }\n\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(payload),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the run\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAWA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE;;;;;;;;;;AAWA,SAAgB,gBAAgB,OAAwB;CACtD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;;;;;;;ACpBA,SAAgB,kBAA2B;CACzC,MAAM,KAAKA,aAAAA,QAAQ,IAAI;CACvB,OAAO,CAAC,EACL,MAAM,OAAO,WAAW,OAAO,OAChCA,aAAAA,QAAQ,IAAI,kBACZA,aAAAA,QAAQ,IAAI,aACZA,aAAAA,QAAQ,IAAI,0BACZA,aAAAA,QAAQ,IAAI,eACZA,aAAAA,QAAQ,IAAI,YACZA,aAAAA,QAAQ,IAAI,UACZA,aAAAA,QAAQ,IAAI,oBACZA,aAAAA,QAAQ,IAAI,aACZA,aAAAA,QAAQ,IAAI;AAEhB;;;ACnBA,MAAM,QAAQ,OAAO,QAAQ;AAC7B,MAAM,SAAS,UAAU;;;;;;;;;AAUzB,MAAa,UAAU;CAAE;CAAO,GAAG,OAAO;AAAE;AAE5C,SAAS,SAA6D;CACpE,IAAI,OAAO,OAAO;EAAE,MAAM;EAAO,SAAS,QAAQ,SA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YAAY,EACV,QAAQ,QAAQ,KAAK,OAAO,EAC1B,aAAa,EACX,QAAQ,CACN;IAAE,KAAK;IAAQ,OAAO,EAAE,aAAa,EAAE,KAAK;GAAE,GAC9C;IACE,KAAK;IACL,OAAO,EACL,aAAa,KAAK,UAAU;KAC1B,GAAG,EAAE;KACL,eAAe,KAAA;IACjB,CAAC,EACH;GACF,CACF,EACF,EACF,EAAE,EACJ,EACF;EACF;CACF;CAEA,OAAO,EACL,eAAe,CACb;EACE,UAAU,EACR,YAAY;GACV;IAAE,KAAK;IAAgB,OAAO,EAAE,aAAa,OAAO;GAAE;GACtD;IAAE,KAAK;IAAmB,OAAO,EAAE,aAAa,QAAQ;GAAE;GAC1D;IAAE,KAAK;IAA0B,OAAO,EAAE,aAAa,SAAS;GAAE;EACpE,EACF;EACA,YAAY,CACV;GACE,OAAO;IAAE,MAAM;IAAa;GAAQ;GACpC,OAAO,CACL;IACE;IACA;IACA,MAAM;IACN,MAAM;IACN,mBAAmB,OAAO,WAAW;IACrC,iBAAiB,OAAO,SAAS;IACjC;IACA,QAAQ,EACN,MAAM,WAAW,YAAY,IAAI,EACnC;GACF,CACF;EACF,CACF;CACF,CACF,EACF;AACF;;;;;;AAOA,eAAsB,cAAc,SAA6D;CAC/F,IAAI,WAAW,GACb;CAGF,IAAI;EACF,MAAM,MAAM,GAAG,cAAc,aAAa;GACxC,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,0BAA0B;IAC1B,yBAAyB;GAC3B;GACA,MAAM,KAAK,UAAU,OAAO;GAC5B,QAAQ,YAAY,QAAQ,GAAK;EACnC,CAAC;CACH,SAAS,IAAI,CAEb;AACF"}
@@ -0,0 +1,259 @@
1
+ import "./rolldown-runtime-CRm0XQPb.js";
2
+ import { randomBytes } from "node:crypto";
3
+ import os from "node:os";
4
+ import process$1 from "node:process";
5
+ import { getAgentProfile } from "gunshi/agent";
6
+ //#region ../../internals/utils/src/errors.ts
7
+ /**
8
+ * Coerces an unknown thrown value to an `Error` instance.
9
+ * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * try { ... } catch(err) {
14
+ * throw new Error('Build failed', { cause: toError(err) })
15
+ * }
16
+ * ```
17
+ */
18
+ function toError(value) {
19
+ return value instanceof Error ? value : new Error(String(value));
20
+ }
21
+ /**
22
+ * Extracts a human-readable message from any thrown value.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * getErrorMessage(new Error('oops')) // 'oops'
27
+ * getErrorMessage('plain string') // 'plain string'
28
+ * ```
29
+ */
30
+ function getErrorMessage(value) {
31
+ return value instanceof Error ? value.message : String(value);
32
+ }
33
+ //#endregion
34
+ //#region ../../internals/utils/src/isCIEnvironment.ts
35
+ /**
36
+ * Returns `true` when a known CI provider has set its environment variable.
37
+ * `CI=false` and `CI=0` count as not CI, so a user can opt out locally.
38
+ */
39
+ function isCIEnvironment() {
40
+ const ci = process$1.env.CI;
41
+ return !!(ci && ci !== "false" && ci !== "0" || process$1.env.GITHUB_ACTIONS || process$1.env.GITLAB_CI || process$1.env.BITBUCKET_BUILD_NUMBER || process$1.env.JENKINS_URL || process$1.env.CIRCLECI || process$1.env.TRAVIS || process$1.env.TEAMCITY_VERSION || process$1.env.BUILDKITE || process$1.env.TF_BUILD);
42
+ }
43
+ //#endregion
44
+ //#region ../../internals/utils/src/runtime.ts
45
+ const isBun = typeof Bun !== "undefined";
46
+ const isDeno = "Deno" in globalThis;
47
+ /**
48
+ * The JavaScript runtime executing the current process: its name, version and whether it is Bun.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise
53
+ * ```
54
+ */
55
+ const runtime = {
56
+ isBun,
57
+ ...detect()
58
+ };
59
+ function detect() {
60
+ if (isBun) return {
61
+ name: "bun",
62
+ version: process.versions.bun ?? ""
63
+ };
64
+ if (isDeno) return {
65
+ name: "deno",
66
+ version: globalThis.Deno?.version?.deno ?? ""
67
+ };
68
+ return {
69
+ name: "node",
70
+ version: process.versions?.node ?? ""
71
+ };
72
+ }
73
+ //#endregion
74
+ //#region ../../internals/utils/src/time.ts
75
+ /**
76
+ * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
77
+ * Rounds to 2 decimal places for sub-millisecond precision without noise.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const start = process.hrtime()
82
+ * doWork()
83
+ * getElapsedMs(start) // 42.35
84
+ * ```
85
+ */
86
+ function getElapsedMs(hrStart) {
87
+ const [seconds, nanoseconds] = process.hrtime(hrStart);
88
+ const ms = seconds * 1e3 + nanoseconds / 1e6;
89
+ return Math.round(ms * 100) / 100;
90
+ }
91
+ /**
92
+ * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * formatMs(250) // '250ms'
97
+ * formatMs(1500) // '1.50s'
98
+ * formatMs(90000) // '1m 30.0s'
99
+ * ```
100
+ */
101
+ function formatMs(ms) {
102
+ if (ms >= 6e4) return `${Math.floor(ms / 6e4)}m ${(ms % 6e4 / 1e3).toFixed(1)}s`;
103
+ if (ms >= 1e3) return `${(ms / 1e3).toFixed(2)}s`;
104
+ return `${Math.round(ms)}ms`;
105
+ }
106
+ //#endregion
107
+ //#region package.json
108
+ var version = "5.9.4";
109
+ //#endregion
110
+ //#region src/Telemetry.ts
111
+ /** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
112
+ const OTLP_ENDPOINT = "https://otlp.kubb.dev";
113
+ /**
114
+ * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
115
+ */
116
+ function isDisabled() {
117
+ return ["DO_NOT_TRACK", "KUBB_DISABLE_TELEMETRY"].some((name) => ["1", "true"].includes(process$1.env[name] ?? ""));
118
+ }
119
+ /** Tracks one command run for the running CLI version; returns the reporter the command calls once it knows how it ended. */
120
+ function trackRun({ command, hrStart }) {
121
+ return (result) => sendTelemetry(buildOtlpPayload({
122
+ command,
123
+ duration: Math.round(getElapsedMs(hrStart)),
124
+ ...result
125
+ }));
126
+ }
127
+ /**
128
+ * The OTLP trace payload for one run: a span named after the command whose attributes are the
129
+ * anonymous run facts. The attribute keys are the contract with otlp.kubb.dev.
130
+ *
131
+ * @see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/
132
+ */
133
+ function buildOtlpPayload({ command, duration, status, plugins = [], filesCreated = 0 }) {
134
+ const traceId = randomBytes(16).toString("hex");
135
+ const spanId = randomBytes(8).toString("hex");
136
+ const endTimeNs = BigInt(Date.now()) * 1000000n;
137
+ const startTimeNs = endTimeNs - BigInt(duration) * 1000000n;
138
+ const pluginNames = [...new Set(plugins.map((plugin) => plugin.name))].sort();
139
+ const agent = getAgentProfile();
140
+ const attributes = [
141
+ {
142
+ key: "kubb.command",
143
+ value: { stringValue: command }
144
+ },
145
+ {
146
+ key: "kubb.version",
147
+ value: { stringValue: version }
148
+ },
149
+ {
150
+ key: "kubb.node_version",
151
+ value: { stringValue: process$1.versions.node.split(".")[0] }
152
+ },
153
+ {
154
+ key: "kubb.runtime",
155
+ value: { stringValue: runtime.name }
156
+ },
157
+ {
158
+ key: "kubb.runtime_version",
159
+ value: { stringValue: runtime.version.split(".")[0] }
160
+ },
161
+ {
162
+ key: "kubb.platform",
163
+ value: { stringValue: os.platform() }
164
+ },
165
+ {
166
+ key: "kubb.ci",
167
+ value: { boolValue: isCIEnvironment() }
168
+ },
169
+ ...agent.isAgent && agent.name ? [{
170
+ key: "kubb.agent",
171
+ value: { stringValue: agent.name }
172
+ }] : [],
173
+ {
174
+ key: "kubb.files_created",
175
+ value: { intValue: filesCreated }
176
+ },
177
+ {
178
+ key: "kubb.status",
179
+ value: { stringValue: status }
180
+ },
181
+ {
182
+ key: "kubb.plugins",
183
+ value: { arrayValue: { values: pluginNames.map((name) => ({ stringValue: name })) } }
184
+ },
185
+ ...pluginNames.map((name) => ({
186
+ key: `kubb.plugin.${name}`,
187
+ value: { boolValue: true }
188
+ })),
189
+ {
190
+ key: "kubb.plugin_options",
191
+ value: { arrayValue: { values: plugins.map((p) => ({ kvlistValue: { values: [{
192
+ key: "name",
193
+ value: { stringValue: p.name }
194
+ }, {
195
+ key: "options",
196
+ value: { stringValue: JSON.stringify({
197
+ ...p.options,
198
+ usedEnumNames: void 0
199
+ }) }
200
+ }] } })) } }
201
+ }
202
+ ];
203
+ return { resourceSpans: [{
204
+ resource: { attributes: [
205
+ {
206
+ key: "service.name",
207
+ value: { stringValue: "kubb" }
208
+ },
209
+ {
210
+ key: "service.version",
211
+ value: { stringValue: version }
212
+ },
213
+ {
214
+ key: "telemetry.sdk.language",
215
+ value: { stringValue: "nodejs" }
216
+ }
217
+ ] },
218
+ scopeSpans: [{
219
+ scope: {
220
+ name: "kubb-core",
221
+ version
222
+ },
223
+ spans: [{
224
+ traceId,
225
+ spanId,
226
+ name: command,
227
+ kind: 1,
228
+ startTimeUnixNano: String(startTimeNs),
229
+ endTimeUnixNano: String(endTimeNs),
230
+ attributes,
231
+ status: { code: status === "success" ? 1 : 2 }
232
+ }]
233
+ }]
234
+ }] };
235
+ }
236
+ /**
237
+ * Send an OTLP payload to the Kubb endpoint. Respects `DO_NOT_TRACK` and
238
+ * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run. No file
239
+ * paths, OpenAPI specs, or secrets are sent.
240
+ */
241
+ async function sendTelemetry(payload) {
242
+ if (isDisabled()) return;
243
+ try {
244
+ await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
245
+ method: "POST",
246
+ headers: {
247
+ "Content-Type": "application/json",
248
+ "Kubb-Telemetry-Version": "1",
249
+ "Kubb-Telemetry-Source": "kubb-cli"
250
+ },
251
+ body: JSON.stringify(payload),
252
+ signal: AbortSignal.timeout(5e3)
253
+ });
254
+ } catch (_e) {}
255
+ }
256
+ //#endregion
257
+ export { getElapsedMs as a, getErrorMessage as c, formatMs as i, toError as l, trackRun as n, runtime as o, version as r, isCIEnvironment as s, isDisabled as t };
258
+
259
+ //# sourceMappingURL=Telemetry-E_BBHmnT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Telemetry-E_BBHmnT.js","names":["process","process"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/isCIEnvironment.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/time.ts","../package.json","../src/Telemetry.ts"],"sourcesContent":["/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n","import process from 'node:process'\n\n/**\n * Returns `true` when a known CI provider has set its environment variable.\n * `CI=false` and `CI=0` count as not CI, so a user can opt out locally.\n */\nexport function isCIEnvironment(): boolean {\n const ci = process.env.CI\n return !!(\n (ci && ci !== 'false' && ci !== '0') ||\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","// Bun polyfills `process.versions.node`, so detection keys off the globals instead.\nconst isBun = typeof Bun !== 'undefined'\nconst isDeno = 'Deno' in globalThis\n\n/**\n * The JavaScript runtime executing the current process: its name, version and whether it is Bun.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport const runtime = { isBun, ...detect() } as const\n\nfunction detect(): { name: 'bun' | 'deno' | 'node'; version: string } {\n if (isBun) return { name: 'bun', version: process.versions.bun ?? '' }\n if (isDeno) return { name: 'deno', version: (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? '' }\n return { name: 'node', version: process.versions?.node ?? '' }\n}\n","/**\n * Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.\n * Rounds to 2 decimal places for sub-millisecond precision without noise.\n *\n * @example\n * ```ts\n * const start = process.hrtime()\n * doWork()\n * getElapsedMs(start) // 42.35\n * ```\n */\nexport function getElapsedMs(hrStart: [number, number]): number {\n const [seconds, nanoseconds] = process.hrtime(hrStart)\n const ms = seconds * 1000 + nanoseconds / 1e6\n return Math.round(ms * 100) / 100\n}\n\n/**\n * Converts a millisecond duration into a human-readable string (`ms`, `s`, or `m s`).\n *\n * @example\n * ```ts\n * formatMs(250) // '250ms'\n * formatMs(1500) // '1.50s'\n * formatMs(90000) // '1m 30.0s'\n * ```\n */\nexport function formatMs(ms: number): string {\n if (ms >= 60000) {\n const mins = Math.floor(ms / 60000)\n const secs = ((ms % 60000) / 1000).toFixed(1)\n return `${mins}m ${secs}s`\n }\n\n if (ms >= 1000) {\n return `${(ms / 1000).toFixed(2)}s`\n }\n return `${Math.round(ms)}ms`\n}\n","","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { getElapsedMs, isCIEnvironment, runtime } from '@internals/utils'\nimport { getAgentProfile } from 'gunshi/agent'\nimport { version } from '../package.json'\n\n/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */\nconst OTLP_ENDPOINT = 'https://otlp.kubb.dev' as const\n\ntype TelemetryCommand = 'generate' | 'mcp' | 'studio' | 'validate'\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 snapshot of the plugin options. Values are included but cannot be traced back to a user.\n */\n options: Record<string, unknown>\n}\n\n/** How a command run ended, as the command reports it to the function {@link trackRun} returned. */\ntype RunResult = {\n status: 'success' | 'failed'\n plugins?: Array<TelemetryPlugin>\n filesCreated?: number\n}\n\n/**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\nexport function isDisabled(): boolean {\n return ['DO_NOT_TRACK', 'KUBB_DISABLE_TELEMETRY'].some((name) => ['1', 'true'].includes(process.env[name] ?? ''))\n}\n\n/** Tracks one command run for the running CLI version; returns the reporter the command calls once it knows how it ended. */\nexport function trackRun({ command, hrStart }: { command: TelemetryCommand; hrStart: [number, number] }): (result: RunResult) => Promise<void> {\n return (result) => sendTelemetry(buildOtlpPayload({ command, duration: Math.round(getElapsedMs(hrStart)), ...result }))\n}\n\n/**\n * The OTLP trace payload for one run: a span named after the command whose attributes are the\n * anonymous run facts. The attribute keys are the contract with otlp.kubb.dev.\n *\n * @see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload({ command, duration, status, plugins = [], filesCreated = 0 }: RunResult & { command: TelemetryCommand; duration: number }) {\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(duration) * 1_000_000n\n const pluginNames = [...new Set(plugins.map((plugin) => plugin.name))].sort()\n const agent = getAgentProfile()\n\n const attributes = [\n { key: 'kubb.command', value: { stringValue: command } },\n { key: 'kubb.version', value: { stringValue: version } },\n { key: 'kubb.node_version', value: { stringValue: process.versions.node.split('.')[0] as string } },\n { key: 'kubb.runtime', value: { stringValue: runtime.name } },\n { key: 'kubb.runtime_version', value: { stringValue: runtime.version.split('.')[0] as string } },\n { key: 'kubb.platform', value: { stringValue: os.platform() } },\n { key: 'kubb.ci', value: { boolValue: isCIEnvironment() } },\n ...(agent.isAgent && agent.name ? [{ key: 'kubb.agent', value: { stringValue: agent.name } }] : []),\n { key: 'kubb.files_created', value: { intValue: filesCreated } },\n { key: 'kubb.status', value: { stringValue: status } },\n {\n key: 'kubb.plugins',\n value: { arrayValue: { values: pluginNames.map((name) => ({ stringValue: name })) } },\n },\n ...pluginNames.map((name) => ({ key: `kubb.plugin.${name}`, value: { boolValue: true } })),\n {\n key: 'kubb.plugin_options',\n value: {\n arrayValue: {\n values: plugins.map((p) => ({\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 return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb' } },\n { key: 'service.version', value: { stringValue: version } },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-core', version },\n spans: [\n {\n traceId,\n spanId,\n name: command,\n kind: 1,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: status === 'success' ? 1 : 2,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an OTLP payload to the Kubb endpoint. Respects `DO_NOT_TRACK` and\n * `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run. No file\n * paths, OpenAPI specs, or secrets are sent.\n */\nexport async function sendTelemetry(payload: ReturnType<typeof buildOtlpPayload>): Promise<void> {\n if (isDisabled()) {\n return\n }\n\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(payload),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently, telemetry must never break the run\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAWA,SAAgB,Q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OAAO,SAAS;IACjC;IACA,QAAQ,EACN,MAAM,WAAW,YAAY,IAAI,EACnC;GACF,CACF;EACF,CACF;CACF,CACF,EACF;AACF;;;;;;AAOA,eAAsB,cAAc,SAA6D;CAC/F,IAAI,WAAW,GACb;CAGF,IAAI;EACF,MAAM,MAAM,GAAG,cAAc,aAAa;GACxC,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,0BAA0B;IAC1B,yBAAyB;GAC3B;GACA,MAAM,KAAK,UAAU,OAAO;GAC5B,QAAQ,YAAY,QAAQ,GAAK;EACnC,CAAC;CACH,SAAS,IAAI,CAEb;AACF"}
@@ -0,0 +1 @@
1
+ export { t as getWorkerLogPath, n as getWorkerStatus, i as startWorker, a as stopWorker } from "./background-H30JH70B.js";
@@ -1,10 +1,11 @@
1
- const require_agent = require("./agent-DElUuYuy.cjs");
2
- const require_run = require("./run-DxGkjzRm.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-CPE0t6oh.cjs");
2
+ const require_credentials = require("./credentials-DDaKqtJn.cjs");
3
+ const require_run = require("./run-QqLDhthl.cjs");
3
4
  require("node:crypto");
4
5
  let tinyexec = require("tinyexec");
5
6
  let node_fs_promises = require("node:fs/promises");
6
7
  let node_path = require("node:path");
7
- node_path = require_agent.__toESM(node_path, 1);
8
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
8
9
  let node_module = require("node:module");
9
10
  let node_net = require("node:net");
10
11
  let node_timers_promises = require("node:timers/promises");
@@ -16,8 +17,8 @@ const states = [
16
17
  "authentication required",
17
18
  "stopped"
18
19
  ];
19
- const getWorkerLogPath = () => node_path.default.join(require_run.getProjectKubbHome(), "worker.log");
20
- const statePath = () => node_path.default.join(require_run.getProjectKubbHome(), "worker.json");
20
+ const getWorkerLogPath = () => node_path.default.join(require_credentials.getProjectKubbHome(), "worker.log");
21
+ const statePath = () => node_path.default.join(require_credentials.getProjectKubbHome(), "worker.json");
21
22
  async function readWorker() {
22
23
  try {
23
24
  const value = JSON.parse(await (0, node_fs_promises.readFile)(statePath(), "utf8"));
@@ -169,4 +170,4 @@ exports.getWorkerStatus = getWorkerStatus;
169
170
  exports.startWorker = startWorker;
170
171
  exports.stopWorker = stopWorker;
171
172
 
172
- //# sourceMappingURL=background-BcRoKru0.cjs.map
173
+ //# sourceMappingURL=background-DdUVvDwi.cjs.map