Skip to content

Commit cb39e97

Browse files
abhithesysclaude
authored andcommitted
fix: derive observability-cloud SDK_VERSION from package.json at build time
The hardcoded constant had already drifted (0.0.1 vs manifest 0.0.2), failing the package's own version-match test — and changesets-automated bumps would re-break it on every release. tsdown now injects the manifest version via define, with vitest.config.ts mirroring it for tests; the existing test stays as the guard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f8d9b92 commit cb39e97

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@openuidev/observability-cloud": patch
3+
---
4+
5+
`SDK_VERSION` is now derived from package.json at build time instead of a
6+
hardcoded constant that had drifted (wire envelopes previously reported
7+
`0.0.1` regardless of the released version).

packages/observability-cloud/src/core/wire.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { ObservabilityLevel } from "@openuidev/observability";
22
import type { StreamWireEvent } from "../events/stream";
33

4-
/** Must be kept in sync with packages/observability-cloud/package.json on release. */
5-
export const SDK_VERSION = "0.0.1";
4+
declare const __SDK_VERSION__: string;
5+
6+
/** Injected from package.json at build time (tsdown define; vitest.config.ts mirrors it for tests). */
7+
export const SDK_VERSION = __SDK_VERSION__;
68

79
export interface WireEventBase {
810
id: string;

packages/observability-cloud/tsdown.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import { readFileSync } from "node:fs";
12
import { defineConfig } from "tsdown";
23

4+
const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
5+
version: string;
6+
};
7+
38
export default defineConfig({
49
entry: ["src/index.ts"],
10+
define: {
11+
__SDK_VERSION__: JSON.stringify(version),
12+
},
513
format: ["esm", "cjs"],
614
dts: true,
715
sourcemap: true,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { readFileSync } from "node:fs";
2+
import { defineConfig } from "vitest/config";
3+
4+
const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
5+
version: string;
6+
};
7+
8+
export default defineConfig({
9+
define: {
10+
// Mirrors the tsdown define so src imports resolve SDK_VERSION in tests.
11+
__SDK_VERSION__: JSON.stringify(version),
12+
},
13+
});

0 commit comments

Comments
 (0)