Skip to content

Commit 67ea600

Browse files
committed
publish alpha
1 parent 56de146 commit 67ea600

6 files changed

Lines changed: 167 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ T3CODE_DEV_INSTANCE=feature-xyz bun run dev:desktop
5656
bun run build
5757
bun run start
5858

59+
# Publish an alpha build without touching npm "latest"
60+
bun run version:alpha
61+
bun run publish:alpha
62+
5963
# Build a shareable macOS .dmg (arm64 by default)
6064
bun run dist:desktop:dmg
6165

6266
# Or from any project directory after publishing:
6367
npx t3
68+
npx t3@alpha
6469
```
6570

6671
## Scripts
@@ -75,6 +80,8 @@ npx t3
7580
- `bun run build` — Builds contracts, web app, and server through Turbo.
7681
- `bun run typecheck` — Strict TypeScript checks for all packages.
7782
- `bun run test` — Runs workspace tests.
83+
- `bun run version:alpha` — Sets or increments the `t3` package to an `x.y.z-alpha.n` prerelease.
84+
- `bun run publish:alpha` — Builds `t3` and publishes it with the npm `alpha` dist-tag, leaving `latest` unchanged.
7885
- `bun run dist:desktop:dmg` — Builds a shareable macOS `.dmg` into `./release`.
7986
- `bun run dist:desktop:dmg:x64` — Builds an Intel macOS `.dmg`.
8087

‎apps/server/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "t3",
3-
"version": "0.1.0",
3+
"version": "0.1.0-alpha.1",
44
"bin": {
55
"t3": "./dist/index.mjs"
66
},

‎apps/server/src/codexAppServerManager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type ChildProcessWithoutNullStreams, spawn } from "node:child_process";
22
import { randomUUID } from "node:crypto";
33
import { EventEmitter } from "node:events";
44
import readline from "node:readline";
5+
import serverPackage from "../package.json";
56

67
import {
78
ApprovalRequestId,
@@ -200,7 +201,7 @@ export class CodexAppServerManager extends EventEmitter<CodexAppServerManagerEve
200201
clientInfo: {
201202
name: "t3code_desktop",
202203
title: "T3 Code Desktop",
203-
version: "0.1.0",
204+
version: serverPackage.version,
204205
},
205206
capabilities: {
206207
experimentalApi: false,

‎package.json‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
"test:desktop-smoke": "turbo run smoke-test --filter=@t3tools/desktop",
3030
"fmt": "oxfmt",
3131
"build:contracts": "turbo run build --filter=@t3tools/contracts",
32-
"dist:desktop:dmg": "node scripts/build-desktop-dmg.mjs",
33-
"dist:desktop:dmg:arm64": "node scripts/build-desktop-dmg.mjs --arch arm64",
34-
"dist:desktop:dmg:x64": "node scripts/build-desktop-dmg.mjs --arch x64",
32+
"version:alpha": "node scripts/version-alpha.mjs",
33+
"version:alpha:dry-run": "node scripts/version-alpha.mjs --dry-run",
34+
"publish:alpha": "node scripts/publish-alpha.mjs",
35+
"publish:alpha:dry-run": "node scripts/publish-alpha.mjs --dry-run",
36+
"dist:desktop:dmg": "node --env-file=.env scripts/build-desktop-dmg.mjs",
37+
"dist:desktop:dmg:arm64": "node --env-file=.env scripts/build-desktop-dmg.mjs --arch arm64",
38+
"dist:desktop:dmg:x64": "node --env-file=.env scripts/build-desktop-dmg.mjs --arch x64",
3539
"clean": "rm -rf node_modules apps/*/node_modules packages/*/node_modules apps/*/dist apps/*/dist-electron packages/*/dist .turbo apps/*/.turbo packages/*/.turbo",
3640
"sync:vscode-icons": "node scripts/sync-vscode-icons.mjs"
3741
},

‎scripts/publish-alpha.mjs‎

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { chmodSync, cpSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2+
import { spawnSync } from "node:child_process";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
const repoRoot = fileURLToPath(new URL("..", import.meta.url));
8+
const packageDir = fileURLToPath(new URL("../apps/server", import.meta.url));
9+
const packageJsonPath = fileURLToPath(new URL("../apps/server/package.json", import.meta.url));
10+
const rootPackageJsonPath = fileURLToPath(new URL("../package.json", import.meta.url));
11+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
12+
const rootPackageJson = JSON.parse(readFileSync(rootPackageJsonPath, "utf8"));
13+
const version = packageJson.version;
14+
const isDryRun = process.argv.includes("--dry-run");
15+
16+
if (!/^\d+\.\d+\.\d+-alpha\.\d+$/.test(version)) {
17+
throw new Error(
18+
`Refusing alpha publish because apps/server/package.json is "${version}". Use bun run version:alpha first.`,
19+
);
20+
}
21+
22+
const build = spawnSync("bun", ["run", "build", "--filter=t3"], {
23+
cwd: repoRoot,
24+
stdio: "inherit",
25+
});
26+
27+
if (build.status !== 0) {
28+
process.exit(build.status ?? 1);
29+
}
30+
31+
function readWorkspaceCatalog(rootManifest) {
32+
const workspaces = rootManifest?.workspaces;
33+
if (!workspaces || typeof workspaces !== "object" || Array.isArray(workspaces)) {
34+
return {};
35+
}
36+
37+
const catalog = workspaces.catalog;
38+
if (!catalog || typeof catalog !== "object" || Array.isArray(catalog)) {
39+
return {};
40+
}
41+
42+
return catalog;
43+
}
44+
45+
function resolveCatalogDependencies(dependencies, catalog, dependencySourceLabel) {
46+
return Object.fromEntries(
47+
Object.entries(dependencies ?? {}).map(([dependencyName, spec]) => {
48+
if (typeof spec !== "string" || !spec.startsWith("catalog:")) {
49+
return [dependencyName, spec];
50+
}
51+
52+
const catalogKey = spec.slice("catalog:".length).trim();
53+
const lookupKey = catalogKey.length > 0 ? catalogKey : dependencyName;
54+
const resolvedSpec = catalog[lookupKey];
55+
if (typeof resolvedSpec !== "string" || resolvedSpec.length === 0) {
56+
throw new Error(
57+
`Unable to resolve '${spec}' for ${dependencySourceLabel} dependency '${dependencyName}'.`,
58+
);
59+
}
60+
61+
return [dependencyName, resolvedSpec];
62+
}),
63+
);
64+
}
65+
66+
const publishDir = mkdtempSync(path.join(os.tmpdir(), "t3-alpha-publish-"));
67+
cpSync(path.join(packageDir, "dist"), path.join(publishDir, "dist"), { recursive: true });
68+
mkdirSync(path.join(publishDir, "bin"), { recursive: true });
69+
writeFileSync(
70+
path.join(publishDir, "bin", "t3"),
71+
'#!/usr/bin/env node\nimport "../dist/index.mjs";\n',
72+
);
73+
chmodSync(path.join(publishDir, "bin", "t3"), 0o755);
74+
75+
const publishManifest = {
76+
name: packageJson.name,
77+
version: packageJson.version,
78+
type: packageJson.type,
79+
bin: {
80+
t3: "bin/t3",
81+
},
82+
main: packageJson.main,
83+
files: ["dist", "bin"],
84+
dependencies: resolveCatalogDependencies(
85+
packageJson.dependencies,
86+
readWorkspaceCatalog(rootPackageJson),
87+
"apps/server",
88+
),
89+
};
90+
91+
writeFileSync(path.join(publishDir, "package.json"), `${JSON.stringify(publishManifest, null, 2)}\n`);
92+
93+
const publishArgs = ["publish", "--tag", "alpha"];
94+
if (isDryRun) {
95+
publishArgs.push("--dry-run");
96+
}
97+
98+
const publish = spawnSync("npm", publishArgs, {
99+
cwd: publishDir,
100+
stdio: "inherit",
101+
});
102+
103+
rmSync(publishDir, { recursive: true, force: true });
104+
process.exit(publish.status ?? 1);

‎scripts/version-alpha.mjs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { readFileSync, writeFileSync } from "node:fs";
2+
import { fileURLToPath } from "node:url";
3+
4+
const packageJsonPath = fileURLToPath(new URL("../apps/server/package.json", import.meta.url));
5+
const args = process.argv.slice(2);
6+
const dryRun = args.includes("--dry-run");
7+
const versionArg = args.find((arg) => arg !== "--dry-run");
8+
9+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
10+
const currentVersion = packageJson.version;
11+
12+
const alphaVersionPattern = /^\d+\.\d+\.\d+-alpha\.\d+$/;
13+
const alphaCounterPattern = /^(?<base>\d+\.\d+\.\d+)-alpha\.(?<counter>\d+)$/;
14+
15+
function nextAlphaVersion(version) {
16+
const alphaMatch = version.match(alphaCounterPattern);
17+
if (alphaMatch?.groups) {
18+
const counter = Number.parseInt(alphaMatch.groups.counter, 10);
19+
return `${alphaMatch.groups.base}-alpha.${counter + 1}`;
20+
}
21+
22+
if (version.includes("-")) {
23+
throw new Error(
24+
`Cannot derive an alpha version from prerelease version "${version}". Pass an explicit version instead.`,
25+
);
26+
}
27+
28+
return `${version}-alpha.0`;
29+
}
30+
31+
const nextVersion = versionArg ?? nextAlphaVersion(currentVersion);
32+
33+
if (!alphaVersionPattern.test(nextVersion)) {
34+
throw new Error(
35+
`Expected an explicit alpha version like "0.1.0-alpha.0", received "${nextVersion}".`,
36+
);
37+
}
38+
39+
if (dryRun) {
40+
console.log(nextVersion);
41+
process.exit(0);
42+
}
43+
44+
packageJson.version = nextVersion;
45+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
46+
console.log(`Updated apps/server/package.json to ${nextVersion}`);

0 commit comments

Comments
 (0)