@kubb/cli 5.10.1 → 5.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Telemetry-BfdvvZus.cjs → Telemetry-BV4GonCV.cjs} +2 -2
- package/dist/Telemetry-BV4GonCV.cjs.map +1 -0
- package/dist/Telemetry-CH2kkxWK.cjs +322 -0
- package/dist/Telemetry-CH2kkxWK.cjs.map +1 -0
- package/dist/{Telemetry-Bf6lUdai.js → Telemetry-Cz9QCzRo.js} +2 -2
- package/dist/Telemetry-Cz9QCzRo.js.map +1 -0
- package/dist/{background-D5K6ecEo.js → background-DFME5huR.js} +30 -7
- package/dist/background-DFME5huR.js.map +1 -0
- package/dist/{background-obsD4Gj2.cjs → background-DVZB1n4j.cjs} +25 -6
- package/dist/background-DVZB1n4j.cjs.map +1 -0
- package/dist/background-WaKtfQWr.cjs +192 -0
- package/dist/background-WaKtfQWr.cjs.map +1 -0
- package/dist/{background-C8doa9-4.js → background-_A5NwvYH.js} +1 -1
- package/dist/{config-CcqzzfB7.cjs → config-DKAqX5sW.cjs} +18 -4
- package/dist/config-DKAqX5sW.cjs.map +1 -0
- package/dist/{config-IMZ26zcb.js → config-DV_7s1m-.js} +19 -5
- package/dist/config-DV_7s1m-.js.map +1 -0
- package/dist/config-OL_izsmp.cjs +113 -0
- package/dist/config-OL_izsmp.cjs.map +1 -0
- package/dist/credentials-xOkTTDWj.cjs +113 -0
- package/dist/credentials-xOkTTDWj.cjs.map +1 -0
- package/dist/index.cjs +65 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +65 -24
- package/dist/index.js.map +1 -1
- package/dist/output-C5g7AtWH.cjs +1008 -0
- package/dist/output-C5g7AtWH.cjs.map +1 -0
- package/dist/{output-mwVt_Vj9.js → output-D_gc1nrM.js} +99 -44
- package/dist/output-D_gc1nrM.js.map +1 -0
- package/dist/{output-DLrxGtuN.cjs → output-nieBFDgM.cjs} +104 -43
- package/dist/output-nieBFDgM.cjs.map +1 -0
- package/dist/{registry-x-_nbYR6.cjs → registry-C8E_G7Xc.cjs} +49 -15
- package/dist/registry-C8E_G7Xc.cjs.map +1 -0
- package/dist/registry-CIpW2zQc.cjs +157 -0
- package/dist/registry-CIpW2zQc.cjs.map +1 -0
- package/dist/{registry-ChqX2AFQ.js → registry-De1vVn1d.js} +50 -16
- package/dist/registry-De1vVn1d.js.map +1 -0
- package/dist/rolldown-runtime-C0BPl7ul.cjs +43 -0
- package/dist/run-BbhrOuK6.cjs +40 -0
- package/dist/{run-1MJA0P5x.cjs.map → run-BbhrOuK6.cjs.map} +1 -1
- package/dist/{run-DHiVlG37.cjs → run-BnLba1gt.cjs} +27 -14
- package/dist/run-BnLba1gt.cjs.map +1 -0
- package/dist/{run-D4vOhfbJ.js → run-Bp47k1W1.js} +2 -2
- package/dist/{run-D4vOhfbJ.js.map → run-Bp47k1W1.js.map} +1 -1
- package/dist/run-BpdJ6X75.cjs +32 -0
- package/dist/{run-B13e9GQz.cjs.map → run-BpdJ6X75.cjs.map} +1 -1
- package/dist/{run-Cm0sJO0h.js → run-CCMlmk-z.js} +1 -1
- package/dist/{run-DTz7gAk1.js → run-CPYD1Lp0.js} +27 -14
- package/dist/run-CPYD1Lp0.js.map +1 -0
- package/dist/run-CSOEGpWZ.cjs +326 -0
- package/dist/run-CSOEGpWZ.cjs.map +1 -0
- package/dist/{run-B13e9GQz.cjs → run-CvE8ZdKG.cjs} +2 -2
- package/dist/run-CvE8ZdKG.cjs.map +1 -0
- package/dist/{run-Cu3pmezx.js → run-DaFK-Uy2.js} +2 -2
- package/dist/{run-Cu3pmezx.js.map → run-DaFK-Uy2.js.map} +1 -1
- package/dist/{run-BAlcXyYw.js → run-Ij84bqza.js} +22 -16
- package/dist/run-Ij84bqza.js.map +1 -0
- package/dist/{run-1MJA0P5x.cjs → run-MFjzBB_M.cjs} +2 -2
- package/dist/run-MFjzBB_M.cjs.map +1 -0
- package/dist/run-hgSZImuK.cjs +345 -0
- package/dist/run-hgSZImuK.cjs.map +1 -0
- package/dist/{run-CUyhuGlK.cjs → run-hyi91b22.cjs} +22 -16
- package/dist/run-hyi91b22.cjs.map +1 -0
- package/dist/{snapshot-DCG-Jf1A.js → snapshot-B6w3BLum.js} +22 -9
- package/dist/snapshot-B6w3BLum.js.map +1 -0
- package/dist/snapshot-DP9Pcnsg.cjs +264 -0
- package/dist/snapshot-DP9Pcnsg.cjs.map +1 -0
- package/dist/{snapshot-C5cthCuU.cjs → snapshot-D_F4XkYQ.cjs} +22 -9
- package/dist/snapshot-D_F4XkYQ.cjs.map +1 -0
- package/dist/studioWorker.js +2 -2
- package/package.json +15 -10
- package/dist/Telemetry-Bf6lUdai.js.map +0 -1
- package/dist/Telemetry-BfdvvZus.cjs.map +0 -1
- package/dist/background-D5K6ecEo.js.map +0 -1
- package/dist/background-obsD4Gj2.cjs.map +0 -1
- package/dist/config-CcqzzfB7.cjs.map +0 -1
- package/dist/config-IMZ26zcb.js.map +0 -1
- package/dist/output-DLrxGtuN.cjs.map +0 -1
- package/dist/output-mwVt_Vj9.js.map +0 -1
- package/dist/registry-ChqX2AFQ.js.map +0 -1
- package/dist/registry-x-_nbYR6.cjs.map +0 -1
- package/dist/run-BAlcXyYw.js.map +0 -1
- package/dist/run-CUyhuGlK.cjs.map +0 -1
- package/dist/run-DHiVlG37.cjs.map +0 -1
- package/dist/run-DTz7gAk1.js.map +0 -1
- package/dist/snapshot-C5cthCuU.cjs.map +0 -1
- package/dist/snapshot-DCG-Jf1A.js.map +0 -1
- package/dist/studioWorker.d.ts +0 -1
|
@@ -107,7 +107,7 @@ function formatMs(ms) {
|
|
|
107
107
|
}
|
|
108
108
|
//#endregion
|
|
109
109
|
//#region package.json
|
|
110
|
-
var version = "5.10.
|
|
110
|
+
var version = "5.10.3";
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/Telemetry.ts
|
|
113
113
|
/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
|
|
@@ -319,4 +319,4 @@ Object.defineProperty(exports, "version", {
|
|
|
319
319
|
}
|
|
320
320
|
});
|
|
321
321
|
|
|
322
|
-
//# sourceMappingURL=Telemetry-
|
|
322
|
+
//# sourceMappingURL=Telemetry-BV4GonCV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-BV4GonCV.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\n/**\n * Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a\n * non-`Error` cause or a cycle.\n *\n * @example\n * ```ts\n * getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)\n * // ['Config failed loading', 'boom']\n * ```\n */\nexport function getErrorChain(error: unknown): Array<Error> {\n const chain: Array<Error> = []\n for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) {\n chain.push(current)\n }\n return chain\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 * Name the MCP client sends in its `initialize` request, e.g. `'claude-code'`. Only set for `kubb mcp`.\n */\n mcpClient?: string\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({\n command,\n duration,\n status,\n plugins = [],\n filesCreated = 0,\n mcpClient,\n}: 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 // A terminal on stdin means a person typed the command; agents, scripts, and CI pipe it.\n { key: 'kubb.tty', value: { boolValue: process.stdin.isTTY === true } },\n ...(agent.isAgent && agent.name ? [{ key: 'kubb.agent', value: { stringValue: agent.name } }] : []),\n // The client picks this name, so cap its length before it leaves the machine.\n ...(mcpClient ? [{ key: 'kubb.mcp_client', value: { stringValue: mcpClient.slice(0, 64) } }] : []),\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,oBAC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AC/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,322 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.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.10.3";
|
|
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, mcpClient }) {
|
|
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
|
+
{
|
|
172
|
+
key: "kubb.tty",
|
|
173
|
+
value: { boolValue: node_process.default.stdin.isTTY === true }
|
|
174
|
+
},
|
|
175
|
+
...agent.isAgent && agent.name ? [{
|
|
176
|
+
key: "kubb.agent",
|
|
177
|
+
value: { stringValue: agent.name }
|
|
178
|
+
}] : [],
|
|
179
|
+
...mcpClient ? [{
|
|
180
|
+
key: "kubb.mcp_client",
|
|
181
|
+
value: { stringValue: mcpClient.slice(0, 64) }
|
|
182
|
+
}] : [],
|
|
183
|
+
{
|
|
184
|
+
key: "kubb.files_created",
|
|
185
|
+
value: { intValue: filesCreated }
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "kubb.status",
|
|
189
|
+
value: { stringValue: status }
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "kubb.plugins",
|
|
193
|
+
value: { arrayValue: { values: pluginNames.map((name) => ({ stringValue: name })) } }
|
|
194
|
+
},
|
|
195
|
+
...pluginNames.map((name) => ({
|
|
196
|
+
key: `kubb.plugin.${name}`,
|
|
197
|
+
value: { boolValue: true }
|
|
198
|
+
})),
|
|
199
|
+
{
|
|
200
|
+
key: "kubb.plugin_options",
|
|
201
|
+
value: { arrayValue: { values: plugins.map((p) => ({ kvlistValue: { values: [{
|
|
202
|
+
key: "name",
|
|
203
|
+
value: { stringValue: p.name }
|
|
204
|
+
}, {
|
|
205
|
+
key: "options",
|
|
206
|
+
value: { stringValue: JSON.stringify({
|
|
207
|
+
...p.options,
|
|
208
|
+
usedEnumNames: void 0
|
|
209
|
+
}) }
|
|
210
|
+
}] } })) } }
|
|
211
|
+
}
|
|
212
|
+
];
|
|
213
|
+
return { resourceSpans: [{
|
|
214
|
+
resource: { attributes: [
|
|
215
|
+
{
|
|
216
|
+
key: "service.name",
|
|
217
|
+
value: { stringValue: "kubb" }
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
key: "service.version",
|
|
221
|
+
value: { stringValue: version }
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
key: "telemetry.sdk.language",
|
|
225
|
+
value: { stringValue: "nodejs" }
|
|
226
|
+
}
|
|
227
|
+
] },
|
|
228
|
+
scopeSpans: [{
|
|
229
|
+
scope: {
|
|
230
|
+
name: "kubb-core",
|
|
231
|
+
version
|
|
232
|
+
},
|
|
233
|
+
spans: [{
|
|
234
|
+
traceId,
|
|
235
|
+
spanId,
|
|
236
|
+
name: command,
|
|
237
|
+
kind: 1,
|
|
238
|
+
startTimeUnixNano: String(startTimeNs),
|
|
239
|
+
endTimeUnixNano: String(endTimeNs),
|
|
240
|
+
attributes,
|
|
241
|
+
status: { code: status === "success" ? 1 : 2 }
|
|
242
|
+
}]
|
|
243
|
+
}]
|
|
244
|
+
}] };
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Send an OTLP payload to the Kubb endpoint. Respects `DO_NOT_TRACK` and
|
|
248
|
+
* `KUBB_DISABLE_TELEMETRY`, and fails silently so telemetry never interrupts a run. No file
|
|
249
|
+
* paths, OpenAPI specs, or secrets are sent.
|
|
250
|
+
*/
|
|
251
|
+
async function sendTelemetry(payload) {
|
|
252
|
+
if (isDisabled()) return;
|
|
253
|
+
try {
|
|
254
|
+
await fetch(`${OTLP_ENDPOINT}/v1/traces`, {
|
|
255
|
+
method: "POST",
|
|
256
|
+
headers: {
|
|
257
|
+
"Content-Type": "application/json",
|
|
258
|
+
"Kubb-Telemetry-Version": "1",
|
|
259
|
+
"Kubb-Telemetry-Source": "kubb-cli"
|
|
260
|
+
},
|
|
261
|
+
body: JSON.stringify(payload),
|
|
262
|
+
signal: AbortSignal.timeout(5e3)
|
|
263
|
+
});
|
|
264
|
+
} catch (_e) {}
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
Object.defineProperty(exports, "formatMs", {
|
|
268
|
+
enumerable: true,
|
|
269
|
+
get: function() {
|
|
270
|
+
return formatMs;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, "getElapsedMs", {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function() {
|
|
276
|
+
return getElapsedMs;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(exports, "getErrorMessage", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
get: function() {
|
|
282
|
+
return getErrorMessage;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(exports, "isCIEnvironment", {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function() {
|
|
288
|
+
return isCIEnvironment;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(exports, "isDisabled", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: function() {
|
|
294
|
+
return isDisabled;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
Object.defineProperty(exports, "runtime", {
|
|
298
|
+
enumerable: true,
|
|
299
|
+
get: function() {
|
|
300
|
+
return runtime;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(exports, "toError", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
get: function() {
|
|
306
|
+
return toError;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(exports, "trackRun", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
get: function() {
|
|
312
|
+
return trackRun;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
Object.defineProperty(exports, "version", {
|
|
316
|
+
enumerable: true,
|
|
317
|
+
get: function() {
|
|
318
|
+
return version;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
//# sourceMappingURL=Telemetry-CH2kkxWK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-CH2kkxWK.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\n/**\n * Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a\n * non-`Error` cause or a cycle.\n *\n * @example\n * ```ts\n * getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)\n * // ['Config failed loading', 'boom']\n * ```\n */\nexport function getErrorChain(error: unknown): Array<Error> {\n const chain: Array<Error> = []\n for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) {\n chain.push(current)\n }\n return chain\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 * Name the MCP client sends in its `initialize` request, e.g. `'claude-code'`. Only set for `kubb mcp`.\n */\n mcpClient?: string\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({\n command,\n duration,\n status,\n plugins = [],\n filesCreated = 0,\n mcpClient,\n}: 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 // A terminal on stdin means a person typed the command; agents, scripts, and CI pipe it.\n { key: 'kubb.tty', value: { boolValue: process.stdin.isTTY === true } },\n ...(agent.isAgent && agent.name ? [{ key: 'kubb.agent', value: { stringValue: agent.name } }] : []),\n // The client picks this name, so cap its length before it leaves the machine.\n ...(mcpClient ? [{ key: 'kubb.mcp_client', value: { stringValue: mcpClient.slice(0, 64) } }] : []),\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,IA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AAM,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"}
|
|
@@ -105,7 +105,7 @@ function formatMs(ms) {
|
|
|
105
105
|
}
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region package.json
|
|
108
|
-
var version = "5.10.
|
|
108
|
+
var version = "5.10.3";
|
|
109
109
|
//#endregion
|
|
110
110
|
//#region src/Telemetry.ts
|
|
111
111
|
/** OpenTelemetry ingestion endpoint for anonymous usage telemetry. */
|
|
@@ -264,4 +264,4 @@ async function sendTelemetry(payload) {
|
|
|
264
264
|
//#endregion
|
|
265
265
|
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 };
|
|
266
266
|
|
|
267
|
-
//# sourceMappingURL=Telemetry-
|
|
267
|
+
//# sourceMappingURL=Telemetry-Cz9QCzRo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Telemetry-Cz9QCzRo.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\n/**\n * Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a\n * non-`Error` cause or a cycle.\n *\n * @example\n * ```ts\n * getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)\n * // ['Config failed loading', 'boom']\n * ```\n */\nexport function getErrorChain(error: unknown): Array<Error> {\n const chain: Array<Error> = []\n for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) {\n chain.push(current)\n }\n return chain\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 * Name the MCP client sends in its `initialize` request, e.g. `'claude-code'`. Only set for `kubb mcp`.\n */\n mcpClient?: string\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({\n command,\n duration,\n status,\n plugins = [],\n filesCreated = 0,\n mcpClient,\n}: 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 // A terminal on stdin means a person typed the command; agents, scripts, and CI pipe it.\n { key: 'kubb.tty', value: { boolValue: process.stdin.isTTY === true } },\n ...(agent.isAgent && agent.name ? [{ key: 'kubb.agent', value: { stringValue: agent.name } }] : []),\n // The client picks this name, so cap its length before it leaves the machine.\n ...(mcpClient ? [{ key: 'kubb.mcp_client', value: { stringValue: mcpClient.slice(0, 64) } }] : []),\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,OAAu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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"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
-
import { a as prepareConnection } from "./run-
|
|
2
|
+
import { a as prepareConnection } from "./run-CPYD1Lp0.js";
|
|
3
3
|
import { i as getProjectKubbHome } from "./credentials-CZK6zPLv.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { hash, randomBytes } from "node:crypto";
|
|
6
6
|
import { x } from "tinyexec";
|
|
7
7
|
import { readFile, rename, writeFile } from "node:fs/promises";
|
|
8
8
|
import path from "node:path";
|
|
9
|
+
import { Diagnostics } from "@kubb/core";
|
|
9
10
|
import { connect, createServer } from "node:net";
|
|
10
11
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
11
12
|
//#region src/runners/studio/background.ts
|
|
@@ -57,7 +58,11 @@ function requestWorker(record, command) {
|
|
|
57
58
|
socket.once("end", () => {
|
|
58
59
|
try {
|
|
59
60
|
const response = JSON.parse(received);
|
|
60
|
-
if (response.id !== record.id || response.pid !== record.pid || !states.includes(response.state)) throw new Error(
|
|
61
|
+
if (response.id !== record.id || response.pid !== record.pid || !states.includes(response.state)) throw new Diagnostics.Error({
|
|
62
|
+
code: Diagnostics.code.internalError,
|
|
63
|
+
severity: "error",
|
|
64
|
+
message: "Worker identity changed"
|
|
65
|
+
});
|
|
61
66
|
resolve(response);
|
|
62
67
|
} catch (error) {
|
|
63
68
|
reject(error);
|
|
@@ -91,7 +96,12 @@ async function stopWorker() {
|
|
|
91
96
|
try {
|
|
92
97
|
await requestWorker(record, "stop");
|
|
93
98
|
} catch (error) {
|
|
94
|
-
if (error.code !== "ECONNREFUSED" && isAlive(record.pid) && record.state !== "stopped" && record.state !== "authentication required") throw new Error(
|
|
99
|
+
if (error.code !== "ECONNREFUSED" && isAlive(record.pid) && record.state !== "stopped" && record.state !== "authentication required") throw new Diagnostics.Error({
|
|
100
|
+
code: Diagnostics.code.unknown,
|
|
101
|
+
severity: "error",
|
|
102
|
+
message: "Cannot verify the background worker. No process was signaled.",
|
|
103
|
+
help: "Check `worker.log`, then stop the process by hand if it is still running."
|
|
104
|
+
});
|
|
95
105
|
return;
|
|
96
106
|
}
|
|
97
107
|
const deadline = Date.now() + 15e3;
|
|
@@ -103,7 +113,11 @@ async function stopWorker() {
|
|
|
103
113
|
}
|
|
104
114
|
await setTimeout$1(100);
|
|
105
115
|
}
|
|
106
|
-
throw new Error(
|
|
116
|
+
throw new Diagnostics.Error({
|
|
117
|
+
code: Diagnostics.code.unknown,
|
|
118
|
+
severity: "error",
|
|
119
|
+
message: "The worker has not finished shutting down. Check worker.log and try again."
|
|
120
|
+
});
|
|
107
121
|
}
|
|
108
122
|
/** The listening port is the project lock, so stale state never needs a PID-based takeover. */
|
|
109
123
|
async function serveWorker(shutdown) {
|
|
@@ -150,7 +164,11 @@ async function serveWorker(shutdown) {
|
|
|
150
164
|
if (existing?.port === port) try {
|
|
151
165
|
return { existing: await requestWorker(existing, "status") };
|
|
152
166
|
} catch {}
|
|
153
|
-
throw new Error(
|
|
167
|
+
throw new Diagnostics.Error({
|
|
168
|
+
code: Diagnostics.code.unknown,
|
|
169
|
+
severity: "error",
|
|
170
|
+
message: "The project control port is occupied or another worker is starting. Try again after stopping that listener."
|
|
171
|
+
});
|
|
154
172
|
}
|
|
155
173
|
record.port = port;
|
|
156
174
|
let saving = Promise.resolve();
|
|
@@ -204,7 +222,12 @@ async function startWorker(options) {
|
|
|
204
222
|
"ipc"
|
|
205
223
|
]
|
|
206
224
|
} }).process;
|
|
207
|
-
if (!child) throw new Error(
|
|
225
|
+
if (!child) throw new Diagnostics.Error({
|
|
226
|
+
code: Diagnostics.code.unknown,
|
|
227
|
+
severity: "error",
|
|
228
|
+
message: "Background worker failed to start",
|
|
229
|
+
help: "Run `kubb studio` in the foreground to see why it fails."
|
|
230
|
+
});
|
|
208
231
|
try {
|
|
209
232
|
await new Promise((resolve, reject) => {
|
|
210
233
|
const timer = setTimeout(() => done(/* @__PURE__ */ new Error("Background worker startup timed out")), 2e4);
|
|
@@ -247,4 +270,4 @@ async function startWorker(options) {
|
|
|
247
270
|
//#endregion
|
|
248
271
|
export { stopWorker as a, startWorker as i, getWorkerStatus as n, serveWorker as r, getWorkerLogPath as t };
|
|
249
272
|
|
|
250
|
-
//# sourceMappingURL=background-
|
|
273
|
+
//# sourceMappingURL=background-DFME5huR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-DFME5huR.js","names":["connectSocket","delay"],"sources":["../src/runners/studio/background.ts"],"sourcesContent":["import { hash, randomBytes } from 'node:crypto'\nimport { readFile, rename, writeFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { connect as connectSocket, createServer } from 'node:net'\nimport path from 'node:path'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { Diagnostics } from '@kubb/core'\nimport { x } from 'tinyexec'\nimport { getProjectKubbHome } from './credentials.ts'\nimport { prepareConnection, type PreparedConnection, type StudioOptions, type WorkerState } from './run.ts'\n\nexport type WorkerRecord = { id: string; pid: number; port: number; state: WorkerState }\nconst states: Array<WorkerState> = ['starting', 'connected', 'reconnecting', 'authentication required', 'stopped']\nexport const getWorkerLogPath = () => path.join(getProjectKubbHome(), 'worker.log')\nconst statePath = () => path.join(getProjectKubbHome(), 'worker.json')\n\nasync function readWorker(): Promise<WorkerRecord | null> {\n try {\n const value: unknown = JSON.parse(await readFile(statePath(), 'utf8'))\n if (!value || typeof value !== 'object') return null\n const record = value as Partial<WorkerRecord>\n return typeof record.id === 'string' &&\n /^[a-f0-9]{32}$/.test(record.id) &&\n Number.isInteger(record.pid) &&\n (record.pid ?? 0) > 1 &&\n Number.isInteger(record.port) &&\n (record.port ?? 0) > 0 &&\n (record.port ?? 0) <= 65535 &&\n states.includes(record.state as WorkerState)\n ? (record as WorkerRecord)\n : null\n } catch {\n return null\n }\n}\n\nfunction isAlive(pid: number): boolean {\n try {\n process.kill(pid, 0)\n return true\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === 'EPERM'\n }\n}\n\n/** Authenticated loopback IPC; a stored PID never authorizes sending a process signal. */\nfunction requestWorker(record: WorkerRecord, command: 'status' | 'stop'): Promise<WorkerRecord> {\n return new Promise((resolve, reject) => {\n const socket = connectSocket({ host: '127.0.0.1', port: record.port })\n let received = ''\n socket.setTimeout(2_000, () => socket.destroy(new Error('Worker control timed out')))\n socket.once('error', reject)\n socket.once('connect', () => socket.write(JSON.stringify({ id: record.id, command }) + '\\n'))\n socket.on('data', (chunk: Buffer) => {\n received += chunk.toString()\n if (received.length > 4096) socket.destroy(new Error('Invalid worker response'))\n })\n socket.once('end', () => {\n try {\n const response = JSON.parse(received) as WorkerRecord\n if (response.id !== record.id || response.pid !== record.pid || !states.includes(response.state))\n throw new Diagnostics.Error({ code: Diagnostics.code.internalError, severity: 'error', message: 'Worker identity changed' })\n resolve(response)\n } catch (error) {\n reject(error)\n }\n })\n })\n}\n\nexport async function getWorkerStatus(): Promise<{ running: boolean; state: WorkerState; pid?: number }> {\n const record = await readWorker()\n if (!record) return { running: false, state: 'stopped' }\n try {\n const response = await requestWorker(record, 'status')\n return { running: true, state: response.state, pid: response.pid }\n } catch {\n return { running: false, state: record.state === 'authentication required' ? record.state : 'stopped' }\n }\n}\n\nexport async function stopWorker(): Promise<void> {\n const record = await readWorker()\n if (!record) return\n try {\n await requestWorker(record, 'stop')\n } catch (error) {\n if (\n (error as NodeJS.ErrnoException).code !== 'ECONNREFUSED' &&\n isAlive(record.pid) &&\n record.state !== 'stopped' &&\n record.state !== 'authentication required'\n ) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Cannot verify the background worker. No process was signaled.',\n help: 'Check `worker.log`, then stop the process by hand if it is still running.',\n })\n }\n return\n }\n const deadline = Date.now() + 15_000\n while (Date.now() < deadline) {\n try {\n await requestWorker(record, 'status')\n } catch {\n return\n }\n await delay(100)\n }\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'The worker has not finished shutting down. Check worker.log and try again.',\n })\n}\n\n/** The listening port is the project lock, so stale state never needs a PID-based takeover. */\nexport async function serveWorker(shutdown: AbortController) {\n const record: WorkerRecord = { id: randomBytes(16).toString('hex'), pid: process.pid, port: 0, state: 'starting' }\n const server = createServer((socket) => {\n let input = ''\n socket.setTimeout(2_000, () => socket.destroy())\n socket.on('error', () => {})\n socket.on('data', (chunk: Buffer) => {\n input += chunk.toString()\n if (input.length > 4096) {\n socket.destroy()\n return\n }\n if (!input.includes('\\n')) return\n try {\n const request = JSON.parse(input) as { id?: unknown; command?: unknown }\n if (request.id !== record.id || !['status', 'stop'].includes(String(request.command))) {\n socket.destroy()\n return\n }\n socket.end(JSON.stringify(record))\n if (request.command === 'stop') shutdown.abort()\n } catch {\n socket.destroy()\n }\n })\n })\n // Hash the project directory to choose its loopback port; fail on collisions.\n const port = 20_000 + (Number.parseInt(hash('sha256', getProjectKubbHome()).slice(0, 8), 16) % 30_000)\n try {\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject)\n server.listen(port, '127.0.0.1', resolve)\n })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EADDRINUSE') throw error\n // Let a simultaneous starter finish writing its record before checking ownership.\n await delay(100)\n const existing = await readWorker()\n if (existing?.port === port) {\n try {\n return { existing: await requestWorker(existing, 'status') }\n } catch {\n /* Refuse an unverified listener. */\n }\n }\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'The project control port is occupied or another worker is starting. Try again after stopping that listener.',\n })\n }\n record.port = port\n let saving = Promise.resolve()\n const save = () => {\n const value = JSON.stringify(record)\n saving = saving.then(async () => {\n const temporary = `${statePath()}.${record.id}`\n await writeFile(temporary, value, { mode: 0o600 })\n await rename(temporary, statePath())\n })\n return saving\n }\n try {\n await save()\n } catch (error) {\n server.close()\n throw error\n }\n return {\n async state(state: WorkerState) {\n record.state = state\n await save()\n },\n async close() {\n try {\n if (record.state !== 'authentication required') {\n record.state = 'stopped'\n await save()\n }\n } finally {\n await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())))\n }\n },\n }\n}\n\nexport type WorkerLaunch = { options: StudioOptions; prepared: PreparedConnection }\n\nexport async function startWorker(options: StudioOptions): Promise<void> {\n const current = await getWorkerStatus()\n if (current.running) {\n console.log(`Already running (${current.state}, PID ${current.pid}).`)\n return\n }\n const prepared = await prepareConnection(options)\n const entry = path.join(path.dirname(createRequire(import.meta.url).resolve('@kubb/cli/package.json')), 'dist', 'studioWorker.js')\n const child = x(process.execPath, [...process.execArgv, entry], {\n nodeOptions: { cwd: process.cwd(), detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] },\n }).process\n if (!child)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Background worker failed to start',\n help: 'Run `kubb studio` in the foreground to see why it fails.',\n })\n try {\n const started = new Promise<void>((resolve, reject) => {\n const timer = setTimeout(() => done(new Error('Background worker startup timed out')), 20_000)\n const done = (error?: Error) => {\n clearTimeout(timer)\n child.removeListener('error', failed)\n child.removeListener('exit', exited)\n child.removeListener('message', ready)\n if (error) reject(error)\n else resolve()\n }\n const failed = (error: Error) => done(error)\n const exited = () => done(new Error(`Background worker exited during startup. Check ${getWorkerLogPath()}`))\n child.once('error', failed)\n child.once('exit', exited)\n const ready = (message: unknown) => {\n if (!message || typeof message !== 'object' || !('started' in message) || message.started !== true)\n return done(new Error('Invalid worker startup response'))\n done()\n }\n child.once('message', ready)\n child.send({ options: { ...options, autoOpen: false }, prepared } satisfies WorkerLaunch, (error) => {\n if (error) done(error)\n })\n })\n await started\n if (child.connected) child.disconnect()\n child.unref()\n const status = await getWorkerStatus()\n console.log(`Background worker ${status.state} (PID ${status.pid ?? child.pid}). Logs: ${getWorkerLogPath()}`)\n } catch (error) {\n // This is the child we just spawned, not a PID recovered from disk.\n child.kill('SIGTERM')\n throw error\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,SAA6B;CAAC;CAAY;CAAa;CAAgB;CAA2B;AAAS;AACjH,MAAa,yBAAyB,KAAK,KAAK,mBAAmB,GAAG,YAAY;AAClF,MAAM,kBAAkB,KAAK,KAAK,mBAAmB,GAAG,aAAa;AAErE,eAAe,aAA2C;CACxD,IAAI;EACF,MAAM,QAAiB,KAAK,MAAM,MAAM,SAAS,UAAU,GAAG,MAAM,CAAC;EACrE,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;EAChD,MAAM,SAAS;EACf,OAAO,OAAO,OAAO,OAAO,YAC1B,iBAAiB,KAAK,OAAO,EAAE,KAC/B,OAAO,UAAU,OAAO,GAAG,MAC1B,OAAO,OAAO,KAAK,KACpB,OAAO,UAAU,OAAO,IAAI,MAC3B,OAAO,QAAQ,KAAK,MACpB,OAAO,QAAQ,MAAM,SACtB,OAAO,SAAS,OAAO,KAAoB,IACxC,SACD;CACN,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,QAAQ,KAAsB;CACrC,IAAI;EACF,QAAQ,KAAK,KAAK,CAA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B,MAAM,KAAK,QAAQ,MAAM;GACzB,MAAM,SAAS,YAAqB;IAClC,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,EAAE,aAAa,YAAY,QAAQ,YAAY,MAC5F,OAAO,qBAAK,IAAI,MAAM,iCAAiC,CAAC;IAC1D,KAAK;GACP;GACA,MAAM,KAAK,WAAW,KAAK;GAC3B,MAAM,KAAK;IAAE,SAAS;KAAE,GAAG;KAAS,UAAU;IAAM;IAAG;GAAS,IAA2B,UAAU;IACnG,IAAI,OAAO,KAAK,KAAK;GACvB,CAAC;EACH,CACY;EACZ,IAAI,MAAM,WAAW,MAAM,WAAW;EACtC,MAAM,MAAM;EACZ,MAAM,SAAS,MAAM,gBAAgB;EACrC,QAAQ,IAAI,qBAAqB,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,IAAI,WAAW,iBAAiB,GAAG;CAC/G,SAAS,OAAO;EAEd,MAAM,KAAK,SAAS;EACpB,MAAM;CACR;AACF"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-CPE0t6oh.cjs");
|
|
2
2
|
const require_credentials = require("./credentials-DDaKqtJn.cjs");
|
|
3
|
-
const require_run = require("./run-
|
|
3
|
+
const require_run = require("./run-BnLba1gt.cjs");
|
|
4
4
|
require("node:crypto");
|
|
5
5
|
let tinyexec = require("tinyexec");
|
|
6
6
|
let node_fs_promises = require("node:fs/promises");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
9
|
+
let _kubb_core = require("@kubb/core");
|
|
9
10
|
let node_module = require("node:module");
|
|
10
11
|
let node_net = require("node:net");
|
|
11
12
|
let node_timers_promises = require("node:timers/promises");
|
|
@@ -58,7 +59,11 @@ function requestWorker(record, command) {
|
|
|
58
59
|
socket.once("end", () => {
|
|
59
60
|
try {
|
|
60
61
|
const response = JSON.parse(received);
|
|
61
|
-
if (response.id !== record.id || response.pid !== record.pid || !states.includes(response.state)) throw new Error(
|
|
62
|
+
if (response.id !== record.id || response.pid !== record.pid || !states.includes(response.state)) throw new _kubb_core.Diagnostics.Error({
|
|
63
|
+
code: _kubb_core.Diagnostics.code.internalError,
|
|
64
|
+
severity: "error",
|
|
65
|
+
message: "Worker identity changed"
|
|
66
|
+
});
|
|
62
67
|
resolve(response);
|
|
63
68
|
} catch (error) {
|
|
64
69
|
reject(error);
|
|
@@ -92,7 +97,12 @@ async function stopWorker() {
|
|
|
92
97
|
try {
|
|
93
98
|
await requestWorker(record, "stop");
|
|
94
99
|
} catch (error) {
|
|
95
|
-
if (error.code !== "ECONNREFUSED" && isAlive(record.pid) && record.state !== "stopped" && record.state !== "authentication required") throw new Error(
|
|
100
|
+
if (error.code !== "ECONNREFUSED" && isAlive(record.pid) && record.state !== "stopped" && record.state !== "authentication required") throw new _kubb_core.Diagnostics.Error({
|
|
101
|
+
code: _kubb_core.Diagnostics.code.unknown,
|
|
102
|
+
severity: "error",
|
|
103
|
+
message: "Cannot verify the background worker. No process was signaled.",
|
|
104
|
+
help: "Check `worker.log`, then stop the process by hand if it is still running."
|
|
105
|
+
});
|
|
96
106
|
return;
|
|
97
107
|
}
|
|
98
108
|
const deadline = Date.now() + 15e3;
|
|
@@ -104,7 +114,11 @@ async function stopWorker() {
|
|
|
104
114
|
}
|
|
105
115
|
await (0, node_timers_promises.setTimeout)(100);
|
|
106
116
|
}
|
|
107
|
-
throw new Error(
|
|
117
|
+
throw new _kubb_core.Diagnostics.Error({
|
|
118
|
+
code: _kubb_core.Diagnostics.code.unknown,
|
|
119
|
+
severity: "error",
|
|
120
|
+
message: "The worker has not finished shutting down. Check worker.log and try again."
|
|
121
|
+
});
|
|
108
122
|
}
|
|
109
123
|
async function startWorker(options) {
|
|
110
124
|
const current = await getWorkerStatus();
|
|
@@ -124,7 +138,12 @@ async function startWorker(options) {
|
|
|
124
138
|
"ipc"
|
|
125
139
|
]
|
|
126
140
|
} }).process;
|
|
127
|
-
if (!child) throw new Error(
|
|
141
|
+
if (!child) throw new _kubb_core.Diagnostics.Error({
|
|
142
|
+
code: _kubb_core.Diagnostics.code.unknown,
|
|
143
|
+
severity: "error",
|
|
144
|
+
message: "Background worker failed to start",
|
|
145
|
+
help: "Run `kubb studio` in the foreground to see why it fails."
|
|
146
|
+
});
|
|
128
147
|
try {
|
|
129
148
|
await new Promise((resolve, reject) => {
|
|
130
149
|
const timer = setTimeout(() => done(/* @__PURE__ */ new Error("Background worker startup timed out")), 2e4);
|
|
@@ -170,4 +189,4 @@ exports.getWorkerStatus = getWorkerStatus;
|
|
|
170
189
|
exports.startWorker = startWorker;
|
|
171
190
|
exports.stopWorker = stopWorker;
|
|
172
191
|
|
|
173
|
-
//# sourceMappingURL=background-
|
|
192
|
+
//# sourceMappingURL=background-DVZB1n4j.cjs.map
|