@devries-cameron20 / t3code Mirror · read-only / commits / 9f94a876b7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 16:00 UTC

fix(cli): tagged source builds report the release version (#36350)

Co-authored-by: Lakshmi Tanmay <lakshmi@voltcrash.com>

Julius Marminge committed Nov 13, 2026 at 13:19 UTC 9f94a876b7f4a9676fa703796d229e7c4c62ec28
7 files changed +126 -12
apps/server/vite.config.ts
+20 -3
@@ -5,6 +5,7 @@ import { defineConfig, mergeConfig } from "vite-plus";
5
6 import baseConfig from "../../vite.config.ts";
7 import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
8 +import { resolveTaggedSourceVersion } from "../../scripts/lib/tagged-source-version.ts";
9 import rootPackageJson from "../../package.json" with { type: "json" };
10 import packageJson from "./package.json" with { type: "json" };
11 import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
@@ -18,9 +19,12 @@ import {
19 export { shouldBundleCliDependency };
20
21 const repoEnv = loadRepoEnv();
21 -const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
22 - ? "nightly"
23 - : "latest";
22 +const serverManifestPath = NodePath.join(import.meta.dirname, "package.json");
23 +// The desktop packager passes APP_VERSION; it can equal the manifest at a commit tagged otherwise.
24 +const buildVersion =
25 + process.env.APP_VERSION?.trim() ||
26 + resolveTaggedSourceVersion(NodePath.join(import.meta.dirname, "../.."), packageJson.version);
27 +const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(buildVersion) ? "nightly" : "latest";
28 // Official release workflows set the telemetry channel; local builds and forks use "dev".
29 const TELEMETRY_CHANNELS = ["stable", "nightly", "preview", "dev"];
30 const telemetryChannel = process.env.T3CODE_TELEMETRY_CHANNEL?.trim() || "dev";
@@ -88,6 +92,19 @@ export default mergeConfig(
92 },
93 },
94 pack: {
95 + plugins: [
96 + {
97 + // Every server module reads its version from this manifest import.
98 + name: "t3code:build-version",
99 + load(id) {
100 + if (NodePath.resolve(id) !== serverManifestPath) return;
101 + return {
102 + code: JSON.stringify({ ...packageJson, version: buildVersion }),
103 + moduleType: "json",
104 + };
105 + },
106 + },
107 + ],
108 // SEA embeds one entry; expose the history worker as a hidden subcommand.
109 entry: packBootstrap
110 ? ["src/bin.ts"]
apps/web/tsconfig.json
+1
@@ -35,6 +35,7 @@
35 "scripts/verify-built-boot.ts",
36 "scripts/warm-dep-cache.ts",
37 "../../scripts/lib/public-config.ts",
38 + "../../scripts/lib/tagged-source-version.ts",
39 "../../scripts/lib/third-party-licenses.ts"
40 ]
41 }
apps/web/vite.config.ts
+9 -2
@@ -19,6 +19,7 @@ import {
19 } from "@t3tools/shared/devProxy";
20
21 import { loadRepoEnv } from "../../scripts/lib/public-config";
22 +import { resolveTaggedSourceVersion } from "../../scripts/lib/tagged-source-version";
23 import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
24 import { tailwindPlugins } from "./vite/tailwind";
25 import { warmBundledDevPlugin } from "./vite/warmBundledDev";
@@ -45,7 +46,6 @@ const configuredRelayTracingToken = repoEnv.VITE_RELAY_OTLP_TRACES_TOKEN?.trim()
46 const configuredHostedAppChannel = process.env.VITE_HOSTED_APP_CHANNEL?.trim() || "";
47 const configuredReleaseChannel =
48 process.env.T3CODE_BUILT_DEV === "1" ? "dev" : process.env.VITE_RELEASE_CHANNEL?.trim() || "";
48 -const configuredAppVersion = process.env.APP_VERSION?.trim() || pkg.version;
49 const configuredDesktopUpdateRepository =
50 process.env.T3CODE_DESKTOP_UPDATE_REPOSITORY?.trim() ||
51 process.env.GITHUB_REPOSITORY?.trim() ||
@@ -295,7 +295,14 @@ const configuredAllowedHosts = (process.env.T3CODE_DEV_ALLOWED_HOSTS ?? "")
295 .filter((entry) => entry.length > 0);
296 const allowedHosts = [".ts.net", ...configuredAllowedHosts];
297
298 -export default defineConfig(() => {
298 +export default defineConfig(({ command }) => {
299 + // `vp dev` and `--built` dev pair this client with a server run from source, which reports the
300 + // manifest version. Only a production build is paired with a packed server.
301 + const configuredAppVersion =
302 + process.env.APP_VERSION?.trim() ||
303 + (command === "build" && !builtDev
304 + ? resolveTaggedSourceVersion(`${import.meta.dirname}/../..`, pkg.version)
305 + : pkg.version);
306 return {
307 run: {
308 tasks: {
scripts/build-desktop-artifact.ts
+3 -1
@@ -43,6 +43,7 @@ import {
43 import { loadRepoEnv } from "./lib/public-config.ts";
44 import { selectDesktopRuntimeExternalDependencies } from "./lib/desktop-external-packages.ts";
45 import { resolveCatalogDependencies } from "./lib/resolve-catalog.ts";
46 +import { resolveTaggedSourceVersion } from "./lib/tagged-source-version.ts";
47
48 import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
49 import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -3686,7 +3687,8 @@ const buildDesktopArtifactUnlocked = Effect.fn("buildDesktopArtifactUnlocked")(f
3687 }),
3688 });
3689
3689 - const appVersion = options.version ?? serverPackageJson.version;
3690 + const appVersion =
3691 + options.version ?? resolveTaggedSourceVersion(repoRoot, serverPackageJson.version);
3692 const iconAssets = resolveDesktopBuildIconAssets(appVersion);
3693 const commitHash = yield* resolveGitCommitHash(repoRoot);
3694 const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
scripts/lib/tagged-source-version.test.ts new
+59
@@ -0,0 +1,59 @@
1 +// @effect-diagnostics nodeBuiltinImport:off - Exercises Git tag discovery against temporary repositories.
2 +import * as NodeChildProcess from "node:child_process";
3 +import * as NodeFS from "node:fs";
4 +import * as NodeOS from "node:os";
5 +import * as NodePath from "node:path";
6 +import { expect, it } from "vite-plus/test";
7 +
8 +import { releasePackageFiles, resolveTaggedSourceVersion } from "./tagged-source-version.ts";
9 +
10 +function makeRoot() {
11 + const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "tagged-source-version-"));
12 + return {
13 + root,
14 + writeManifest: (relativePath: string, version: string) => {
15 + const filePath = NodePath.join(root, relativePath);
16 + NodeFS.mkdirSync(NodePath.dirname(filePath), { recursive: true });
17 + NodeFS.writeFileSync(filePath, JSON.stringify({ version }));
18 + },
19 + git: (...args: ReadonlyArray<string>) =>
20 + NodeChildProcess.execFileSync(
21 + "git",
22 + ["-c", "user.name=Test", "-c", "user.email=test@example.com", ...args],
23 + { cwd: root, stdio: "pipe" },
24 + ),
25 + [Symbol.dispose]: () => NodeFS.rmSync(root, { recursive: true, force: true }),
26 + };
27 +}
28 +
29 +it("reports the single stable tag on HEAD unless a release manifest was edited", () => {
30 + using repo = makeRoot();
31 + for (const relativePath of releasePackageFiles) repo.writeManifest(relativePath, "0.1.5");
32 + repo.git("init", "--quiet");
33 + repo.git("add", ".");
34 + repo.git("commit", "--quiet", "--no-gpg-sign", "-m", "source");
35 + const resolve = () => resolveTaggedSourceVersion(repo.root, "0.1.5");
36 +
37 + repo.git("tag", "v0.1.6-nightly.20261031.3977");
38 + expect(resolve()).toBe("0.1.5");
39 +
40 + repo.git("tag", "--no-sign", "-a", "v0.1.6", "-m", "release");
41 + expect(resolve()).toBe("0.1.6");
42 +
43 + // A nightly or preview job on the tagged commit aligns the manifests to its own version.
44 + repo.writeManifest("apps/web/package.json", "0.1.7-preview.1");
45 + expect(resolveTaggedSourceVersion(repo.root, "0.1.7-preview.1")).toBe("0.1.7-preview.1");
46 + repo.writeManifest("apps/web/package.json", "0.1.5");
47 + expect(resolve()).toBe("0.1.6");
48 +
49 + repo.git("tag", "v0.1.7");
50 + expect(resolve()).toBe("0.1.5");
51 +
52 + repo.git("commit", "--quiet", "--no-gpg-sign", "--allow-empty", "-m", "after release");
53 + expect(resolve()).toBe("0.1.5");
54 +});
55 +
56 +it("keeps the manifest version in a source archive without Git metadata", () => {
57 + using repo = makeRoot();
58 + expect(resolveTaggedSourceVersion(repo.root, "0.1.5")).toBe("0.1.5");
59 +});
scripts/lib/tagged-source-version.ts new
+31
@@ -0,0 +1,31 @@
1 +// @effect-diagnostics-next-line nodeBuiltinImport:off -- Build configs resolve the tag before an Effect runtime exists.
2 +import * as NodeChildProcess from "node:child_process";
3 +
4 +export const releasePackageFiles = [
5 + "apps/server/package.json",
6 + "apps/desktop/package.json",
7 + "apps/web/package.json",
8 + "packages/contracts/package.json",
9 +] as const;
10 +
11 +/**
12 + * A release is tagged on the commit it was built from, and the manifest bump lands on main
13 + * afterwards, so source at `vX.Y.Z` still carries the previous version. Server, web and desktop
14 + * builds must all resolve through here, or the client reports a different version than its server.
15 + */
16 +export function resolveTaggedSourceVersion(repoRoot: string, manifestVersion: string): string {
17 + const git = (...args: ReadonlyArray<string>) =>
18 + NodeChildProcess.execFileSync("git", args, { cwd: repoRoot, encoding: "utf8", stdio: "pipe" });
19 +
20 + try {
21 + // Release jobs and the desktop packager write the version they build into the manifests.
22 + git("diff", "--quiet", "HEAD", "--", ...releasePackageFiles);
23 + const stableTags = git("tag", "--points-at", "HEAD")
24 + .split("\n")
25 + .filter((tag) => /^v\d+\.\d+\.\d+$/.test(tag));
26 + if (stableTags.length === 1) return stableTags[0]!.slice(1);
27 + } catch {
28 + // No Git, a source archive, or edited manifests: the manifest is the version.
29 + }
30 + return manifestVersion;
31 +}
scripts/update-release-package-versions.ts
+3 -6
@@ -12,6 +12,8 @@ import * as Schema from "effect/Schema";
12 import { Argument, Command, Flag } from "effect/cli";
13 import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";
14
15 +import { releasePackageFiles } from "./lib/tagged-source-version.ts";
16 +
17 export class ReleasePackageManifestError extends Schema.TaggedError<ReleasePackageManifestError>()(
18 "ReleasePackageManifestError",
19 {
@@ -46,12 +48,7 @@ export class ReleaseGitHubOutputWriteError extends Schema.TaggedError<ReleaseGit
48 }
49 }
50
49 -export const releasePackageFiles = [
50 - "apps/server/package.json",
51 - "apps/desktop/package.json",
52 - "apps/web/package.json",
53 - "packages/contracts/package.json",
54 -] as const;
51 +export { releasePackageFiles };
52
53 interface UpdateReleasePackageVersionsOptions {
54 readonly rootDir?: string | undefined;