Compare commits

...
Author SHA1 Message Date
Nicolò Boschi 89530942d8 fix(typescript-client): derive CLIENT_VERSION via tsup define
The hardcoded `CLIENT_VERSION = "0.5.1"` in src/index.ts has fallen
behind npm releases through 0.5.6 / 0.5.7 / 0.6.0 — every published
release since 0.5.1 ships a stale constant, mis-attributing User-Agent
in server-side telemetry and foreclosing client-side feature gating.

Substitute `__CLIENT_VERSION__` with `pkg.version` via tsup's `define`
at build time. Source has no JSON import, so the fix is uniform across
runtimes (Node CJS/ESM, Deno via npm:, Deno via raw src) — unlike a
direct `import pkg from "../package.json"`, which Deno rejects without
`with { type: "json" }`, and which would in turn cascade into tsconfig
+ ts-jest reconfiguration (see #1535 for that path).

A `typeof` guard with a `0.0.0-dev` sentinel keeps raw-source loads
(jest, `npm run test:deno`) from throwing ReferenceError when the
build-time substitution hasn't run.

Verified locally: build, jest 6/6, Node CJS/ESM, Deno (dist), Deno
(raw src) all report the substituted version (or the dev sentinel
where appropriate). dist no longer inlines the full package.json
(devDependencies, scripts, repository url) — only the version string.

Closes #1535.
2026-05-08 12:39:13 +02:00
2 changed files with 12 additions and 1 deletions
+6 -1
View File
@@ -53,7 +53,12 @@ import type {
TagGroupNotInput,
} from "../generated/types.gen";
export const CLIENT_VERSION = "0.5.1";
// __CLIENT_VERSION__ is replaced by tsup's `define` with package.json's version
// at build time. The typeof guard keeps raw-source loads (jest, deno test:deno)
// from throwing ReferenceError; they get a sentinel that makes drift obvious.
declare const __CLIENT_VERSION__: string | undefined;
export const CLIENT_VERSION: string =
typeof __CLIENT_VERSION__ !== "undefined" ? __CLIENT_VERSION__ : "0.0.0-dev";
export const DEFAULT_USER_AGENT = `hindsight-client-typescript/${CLIENT_VERSION}`;
export interface HindsightClientOptions {
@@ -1,4 +1,5 @@
import { defineConfig } from "tsup";
import pkg from "./package.json";
export default defineConfig({
entry: ["src/index.ts"],
@@ -9,4 +10,9 @@ export default defineConfig({
sourcemap: true,
// Bundle all relative imports (src + generated) into the output
bundle: true,
// Substitute __CLIENT_VERSION__ with package.json's version at build time so
// the constant in src/index.ts can never drift from what npm publishes.
define: {
__CLIENT_VERSION__: JSON.stringify(pkg.version),
},
});