From d6437a7e131ab98706efe31263cddb4ae957557a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Feb 2026 11:44:24 -0800 Subject: [PATCH] Move toolbar below chat input, fix electron preload bundling, and update build configs - Move BranchToolbar below the chat input box to match Codex app layout - Change worktree path to ~/.t3code/worktrees/{repo}/{branch} - Split desktop tsdown config into separate main/preload builds to prevent code-splitting from leaking node:os into the sandboxed preload script - Migrate turbo scripts to turbo watch, add desktop start/smoke-test tasks - Update server output to .mjs, add CJS format, remove tsx dependency Co-Authored-By: Claude Opus 4.6 --- README.md | 4 ++-- apps/desktop/package.json | 2 +- apps/desktop/scripts/dev-electron.mjs | 2 +- apps/desktop/scripts/smoke-test.mjs | 6 +----- apps/desktop/src/main.ts | 2 +- apps/desktop/tsdown.config.ts | 25 ++++++++++++++++++------- apps/desktop/turbo.jsonc | 10 ++++++++++ apps/server/package.json | 9 ++++----- apps/server/tsdown.config.ts | 4 ++-- apps/server/turbo.jsonc | 16 ++++++++++++++++ apps/web/turbo.jsonc | 9 +++++++++ bun.lock | 1 - package.json | 16 ++++++++-------- turbo.json | 4 ++-- vitest.config.ts | 12 +++++++++++- 15 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 apps/server/turbo.jsonc create mode 100644 apps/web/turbo.jsonc diff --git a/README.md b/README.md index 1f18c9d30017780e9b4f1b3dd6ae7ede3cde0db8..93f955361e0fa299a5b045d6c4e848ad040901b1 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,8 @@ npx t3 ## Scripts -- `bun run dev` — Starts contracts, server, and web dev tasks via Turborepo's parallel task runner. -- `bun run dev:server` — Starts just the WebSocket server (uses tsx for TS execution). +- `bun run dev` — Starts contracts, server, and web in `turbo watch` mode. +- `bun run dev:server` — Starts just the WebSocket server (uses Bun TypeScript execution). - `bun run dev:web` — Starts just the Vite dev server for the web app. - `bun run start` — Runs the production server (serves built web app as static files). - `bun run build` — Builds contracts, web app, and server through Turbo. diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 3b4fd30f9c6f57f225bc17fd5c4fb93bf4043622..d6afd21ce940cbbd337504fb545c19c59ed95e2c 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -8,7 +8,7 @@ "dev:bundle": "tsdown --watch", "dev:electron": "bun run scripts/dev-electron.mjs", "build": "tsdown", - "start": "electron dist-electron/main.cjs", + "start": "electron dist-electron/main.js", "typecheck": "tsc --noEmit", "test": "vitest run --passWithNoTests", "smoke-test": "node scripts/smoke-test.mjs" diff --git a/apps/desktop/scripts/dev-electron.mjs b/apps/desktop/scripts/dev-electron.mjs index 0c49d1e58681b3e2a666a4d44d4495032897e33b..2a6153a7da7c6549ec75106f99601025de575079 100644 --- a/apps/desktop/scripts/dev-electron.mjs +++ b/apps/desktop/scripts/dev-electron.mjs @@ -10,7 +10,7 @@ await waitOn({ `tcp:${port}`, "file:dist-electron/main.js", "file:dist-electron/preload.js", - "file:../server/dist/index.js", + // "file:../server/dist/index.cjs", ], }); diff --git a/apps/desktop/scripts/smoke-test.mjs b/apps/desktop/scripts/smoke-test.mjs index 895d18b8b60fa1033821432038aaeccdf7eaa481..883da7203a53a9b47a7b3b54d1972a48cd64759c 100644 --- a/apps/desktop/scripts/smoke-test.mjs +++ b/apps/desktop/scripts/smoke-test.mjs @@ -1,16 +1,12 @@ -import { execSync, spawn } from "node:child_process"; +import { spawn } from "node:child_process"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const desktopDir = resolve(__dirname, ".."); -const rootDir = resolve(__dirname, "../../.."); const electronBin = resolve(desktopDir, "node_modules/.bin/electron"); const mainJs = resolve(desktopDir, "dist-electron/main.js"); -console.log("Building contracts + web + server + desktop..."); -execSync("bun run build", { cwd: rootDir, stdio: "inherit" }); - console.log("\nLaunching Electron smoke test..."); const child = spawn(electronBin, [mainJs], { diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 3161a2e9dc1d46e24665ea70d14ca7ec09b6933c..66e4b8a330dbb4469051d6c3272f6f2e008a1ca0 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -13,7 +13,7 @@ fixPath(); const PICK_FOLDER_CHANNEL = "desktop:pick-folder"; const ROOT_DIR = path.resolve(__dirname, "../../.."); -const BACKEND_ENTRY = path.join(ROOT_DIR, "apps/server/dist/index.js"); +const BACKEND_ENTRY = path.join(ROOT_DIR, "apps/server/dist/index.mjs"); const WEB_ENTRY = path.join(ROOT_DIR, "apps/web/dist/index.html"); const STATE_DIR = path.join(os.homedir(), ".t3", "userdata"); const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL); diff --git a/apps/desktop/tsdown.config.ts b/apps/desktop/tsdown.config.ts index f87ac594df3f9211f349cdeab4f53597a18eabd9..4cffbb2587936a57053b77090be840eecddc1a1b 100644 --- a/apps/desktop/tsdown.config.ts +++ b/apps/desktop/tsdown.config.ts @@ -1,10 +1,21 @@ -import { defineConfig } from "tsup"; +import { defineConfig } from "tsdown"; -export default defineConfig({ - entry: ["src/main.ts", "src/preload.ts"], - format: "cjs", +const shared = { + format: "cjs" as const, outDir: "dist-electron", sourcemap: true, - clean: true, - noExternal: ["@t3tools/contracts"], -}); + outExtensions: () => ({ js: ".js" }), +}; + +export default defineConfig([ + { + ...shared, + entry: ["src/main.ts"], + clean: true, + noExternal: ["@t3tools/contracts"], + }, + { + ...shared, + entry: ["src/preload.ts"], + }, +]); diff --git a/apps/desktop/turbo.jsonc b/apps/desktop/turbo.jsonc index 843ebb0b2dd7843ddce795f6cd2e6e66bfbce738..0f8f5b4b8e38ba3577b0015cb6bf271bca593c9f 100644 --- a/apps/desktop/turbo.jsonc +++ b/apps/desktop/turbo.jsonc @@ -9,5 +9,15 @@ "dev": { "persistent": true, }, + "start": { + "dependsOn": ["build", "@t3tools/web#build", "t3#build"], + "cache": false, + "persistent": true, + }, + "smoke-test": { + "dependsOn": ["build", "@t3tools/web#build", "t3#build"], + "cache": false, + "outputs": [], + }, }, } diff --git a/apps/server/package.json b/apps/server/package.json index f26426cff236592a19582cc0451301a2b2d81022..7ed3d161447f94f000efb08c5b2e26f8083f7a12 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -2,17 +2,17 @@ "name": "t3", "version": "0.1.0", "bin": { - "t3": "./dist/index.js" + "t3": "./dist/index.mjs" }, "files": [ "dist" ], "type": "module", - "main": "./dist/index.js", + "main": "./dist/index.mjs", "scripts": { - "dev": "VITE_DEV_SERVER_URL=http://localhost:5173 tsx src/index.ts", + "dev": "VITE_DEV_SERVER_URL=http://localhost:5173 bun run src/index.ts", "build": "tsdown && node scripts/bundle-client.mjs", - "start": "node dist/index.js", + "start": "node dist/index.mjs", "typecheck": "tsc --noEmit", "test": "vitest run" }, @@ -26,7 +26,6 @@ "@types/node": "^22.10.2", "@types/ws": "^8.5.13", "tsdown": "^0.20.3", - "tsx": "^4.19.0", "typescript": "^5.7.3" } } diff --git a/apps/server/tsdown.config.ts b/apps/server/tsdown.config.ts index 6708d8e27c0fad417a0b60ed71d9d2049c186977..e5cd33b05956bb81e41af21687ff50296dd4c980 100644 --- a/apps/server/tsdown.config.ts +++ b/apps/server/tsdown.config.ts @@ -2,12 +2,12 @@ import { defineConfig } from "tsup"; export default defineConfig({ entry: ["src/index.ts"], - format: "esm", + format: ["esm", "cjs"], outDir: "dist", sourcemap: true, clean: true, noExternal: ["@t3tools/contracts"], banner: { - js: '#!/usr/bin/env node\n', + js: "#!/usr/bin/env node\n", }, }); diff --git a/apps/server/turbo.jsonc b/apps/server/turbo.jsonc new file mode 100644 index 0000000000000000000000000000000000000000..348412533d8f0f503992d5773e7b4ba78eabfb21 --- /dev/null +++ b/apps/server/turbo.jsonc @@ -0,0 +1,16 @@ +{ + "$schema": "https://turbo.build/schema.json", + "extends": ["//"], + "tasks": { + "dev": { + "dependsOn": ["@t3tools/contracts#dev"], + "persistent": true, + "interruptible": true + }, + "start": { + "dependsOn": ["build"], + "cache": false, + "persistent": true + } + } +} diff --git a/apps/web/turbo.jsonc b/apps/web/turbo.jsonc new file mode 100644 index 0000000000000000000000000000000000000000..619cc63b3608e8e5924b416fcd93b668adb0cd9f --- /dev/null +++ b/apps/web/turbo.jsonc @@ -0,0 +1,9 @@ +{ + "$schema": "https://turbo.build/schema.json", + "extends": ["//"], + "tasks": { + "dev": { + "persistent": true + } + } +} diff --git a/bun.lock b/bun.lock index 5785a3f14732ea5a6383dc1f03c63169e5f0854d..49f27c42124c0e6ebb606032cc0762ee35eaa5b2 100644 --- a/bun.lock +++ b/bun.lock @@ -43,7 +43,6 @@ "@types/node": "^22.10.2", "@types/ws": "^8.5.13", "tsdown": "^0.20.3", - "tsx": "^4.19.0", "typescript": "^5.7.3", }, }, diff --git a/package.json b/package.json index c592c9621111001b98544212e94097444c5177f2..e41205a186c74ad1ee6c57ea039943f6b31ad195 100644 --- a/package.json +++ b/package.json @@ -6,20 +6,20 @@ "packages/*" ], "scripts": { - "dev": "T3CODE_LOG_WS_EVENTS=1 VITE_WS_URL=ws://localhost:3773 turbo run dev --ui=tui --filter=@t3tools/contracts --filter=@t3tools/web --filter=t3 --parallel", - "dev:server": "bun run build:contracts && bun run --cwd apps/server dev", - "dev:web": "VITE_WS_URL=ws://localhost:3773 bun run --cwd apps/web dev", + "dev": "T3CODE_LOG_WS_EVENTS=1 VITE_WS_URL=ws://localhost:3773 turbo watch dev --ui=tui --filter=@t3tools/contracts --filter=@t3tools/web --filter=t3", + "dev:server": "turbo watch dev --filter=t3", + "dev:web": "VITE_WS_URL=ws://localhost:3773 turbo watch dev --filter=@t3tools/web", "dev:desktop": "turbo watch dev --filter=@t3tools/desktop --filter=t3 --filter=@t3tools/web", - "start": "node apps/server/dist/index.js", - "start:desktop": "bun run --cwd apps/desktop start", + "start": "turbo run start --filter=t3", + "start:desktop": "turbo run start --filter=@t3tools/desktop", "build": "turbo run build", - "build:desktop": "bun run build:contracts && bun run --cwd apps/web build && bun run --cwd apps/server build && bun run --cwd apps/desktop build", + "build:desktop": "turbo run build --filter=@t3tools/desktop --filter=t3", "typecheck": "turbo run typecheck", "lint": "oxlint --report-unused-disable-directives", "test": "turbo run test", - "test:desktop-smoke": "bun run --cwd apps/desktop smoke-test", + "test:desktop-smoke": "turbo run smoke-test --filter=@t3tools/desktop", "fmt": "oxfmt", - "build:contracts": "bun run --cwd packages/contracts build" + "build:contracts": "turbo run build --filter=@t3tools/contracts" }, "devDependencies": { "oxfmt": "^0.28.0", diff --git a/turbo.json b/turbo.json index 6d0970bf95c71911f22da3f4118c33ffe6205bda..d797982de9c0c8278e38594066e8e541e6cf39c0 100644 --- a/turbo.json +++ b/turbo.json @@ -18,9 +18,9 @@ "outputs": ["dist/**", "dist-electron/**"] }, "dev": { - "dependsOn": ["@t3tools/contracts#build"], + "dependsOn": ["^dev"], "cache": false, - "persistent": true + "persistent": false }, "typecheck": { "dependsOn": ["^typecheck"], diff --git a/vitest.config.ts b/vitest.config.ts index 8fb6f2dcff4e2fd53bcae820251424c4156d6187..b8c4e89a2b1f4c27487e79d366a5bef1a0a2f6af 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,3 +1,13 @@ +import * as path from "node:path"; import { defineConfig } from "vitest/config"; -export default defineConfig({}); +export default defineConfig({ + resolve: { + alias: [ + { + find: /^@t3tools\/contracts$/, + replacement: path.resolve(import.meta.dirname, "./packages/contracts/src/index.ts"), + }, + ], + }, +}); -- 2.54.0