Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
"scripts": {
"build": "tsc",
"build": "node scripts/gen-version.mjs && tsc",
"generate": "openapi-ts",
"lint": "oxlint .",
"format": "oxfmt --write .",
Expand Down
18 changes: 18 additions & 0 deletions scripts/gen-version.mjs
Original file line number Diff line number Diff line change
@@ -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})`);
7 changes: 1 addition & 6 deletions src/low/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
json?: unknown;
Expand Down
2 changes: 2 additions & 0 deletions src/low/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// GENERATED by scripts/gen-version.mjs from package.json — do not edit.
export const SDK_VERSION = "0.1.0";
Loading