From 59ee0f0d18e7d227e6e860fbcde267efdfc4801d Mon Sep 17 00:00:00 2001 From: wei-hai Date: Thu, 23 Jul 2026 09:55:53 -0700 Subject: [PATCH] fix: derive User-Agent version from package.json at build time SDK_VERSION was a hardcoded constant, but versioning is tag-driven: the publish workflow injects the release version into package.json before build and never touched the constant, so every published npm build reported the User-Agent version as the stale placeholder (0.1.0) regardless of the real version. Generate src/low/version.ts from package.json in `pnpm build` (via scripts/gen-version.mjs) and import SDK_VERSION from it. The committed version.ts holds the placeholder so typecheck/test/lint work without a build; the publish build regenerates it from the tag-injected version. No change to publish.yml needed. Verified: injecting 0.1.3 then building yields User-Agent comfy-sdk-typescript/0.1.3. Co-Authored-By: Claude Opus 4.8 --- package.json | 2 +- scripts/gen-version.mjs | 18 ++++++++++++++++++ src/low/transport.ts | 7 +------ src/low/version.ts | 2 ++ 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 scripts/gen-version.mjs create mode 100644 src/low/version.ts diff --git a/package.json b/package.json index 741e18b..916f315 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ } }, "scripts": { - "build": "tsc", + "build": "node scripts/gen-version.mjs && tsc", "generate": "openapi-ts", "lint": "oxlint .", "format": "oxfmt --write .", diff --git a/scripts/gen-version.mjs b/scripts/gen-version.mjs new file mode 100644 index 0000000..b826bea --- /dev/null +++ b/scripts/gen-version.mjs @@ -0,0 +1,18 @@ +// Generate src/low/version.ts from package.json's version so the SDK's +// User-Agent always reports the published package version. This runs as part of +// `pnpm build`; the publish workflow sets package.json to the release-tag +// version before building (tag-driven versioning), so the published bundle +// carries that version instead of a hand-kept constant that silently drifts. +import { readFileSync, writeFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; + +const root = new URL("..", import.meta.url); +const pkg = JSON.parse(readFileSync(new URL("package.json", root), "utf8")); +const out = fileURLToPath(new URL("src/low/version.ts", root)); + +const body = `// GENERATED by scripts/gen-version.mjs from package.json — do not edit. +export const SDK_VERSION = ${JSON.stringify(pkg.version)}; +`; + +writeFileSync(out, body); +console.log(`Wrote src/low/version.ts (SDK_VERSION = ${pkg.version})`); diff --git a/src/low/transport.ts b/src/low/transport.ts index f7e3b75..bdb7961 100644 --- a/src/low/transport.ts +++ b/src/low/transport.ts @@ -29,16 +29,11 @@ import { errorFromEnvelope } from "./errors.js"; import type { Asset, AssetFromHashData, Job, PostJobsData } from "./generated/types.gen.js"; import { iterateSse, type RawEvent } from "./sse.js"; +import { SDK_VERSION } from "./version.js"; const API_PREFIX = "/api/v2"; const DEFAULT_TIMEOUT_MS = 30_000; -// Mirrors `version` in package.json. Hand-kept in sync: this package builds -// with plain `tsc` (no bundler/codegen step to inline it), and importing -// `../../package.json` directly would step outside `tsc`'s configured -// `rootDir`. -const SDK_VERSION = "0.1.0"; - export interface RequestOptions { headers?: Record; json?: unknown; diff --git a/src/low/version.ts b/src/low/version.ts new file mode 100644 index 0000000..0a17c87 --- /dev/null +++ b/src/low/version.ts @@ -0,0 +1,2 @@ +// GENERATED by scripts/gen-version.mjs from package.json — do not edit. +export const SDK_VERSION = "0.1.0";