Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

development.md

231 lines10.0 KB

1# Development
2​
3## First checkout
4​
5Install `vp` using the [root README](../../README.md#install-vp). The checkout requires Node 24;
6Bun is optional. From the repository root:
7​
8```sh
9vp i
10vp run dev
11```
12​
13Open the pairing URL printed by the dev runner. The bare origin does not authenticate
14a new browser.
15​
16Prefer a container? See [Dev container](../internals/devcontainer.md) for VS Code and Codespaces setup.
17​
18## Choosing a dev process
19​
20Use `vp run dev` for server and web, or `vp run dev:desktop` for the Electron client.
21`dev:server` and `dev:web` start those processes separately.
22See the [mobile README](../../apps/mobile/README.md) for native builds and Metro.
23​
24Flags go directly after the task name, for example `vp run dev --home-dir /tmp/t3code-dev`.
25Add `--browser` to open a browser automatically.
26​
27### State and ports
28​
29Linked worktrees default to their own `.t3/userdata`, even when `T3CODE_HOME` is set.
30The main checkout defaults to `~/.t3/dev/userdata`. An explicit `--home-dir` wins in both cases.
31Never run a development server against the live `~/.t3/userdata`.
32See [test data](../../AGENTS.md#test-data) for copying a consistent database snapshot.
33​
34Read ports from the `[dev-runner]` output. Worktrees derive stable preferences from their paths,
35but occupied ports can shift them. `T3CODE_PORT_OFFSET` or `T3CODE_DEV_INSTANCE` can select a
36different preference when needed.
37​
38### Sharing and remote debugging
39​
40`vp run dev --share` publishes the web port over the machine's tailnet and prints a pairing URL
41for that origin. Give the tester the complete URL, including its token. The dev runner removes
42its mapping on exit.
43​
44Leave `VITE_HTTP_URL` and `VITE_WS_URL` unset. Vite proxies the backend through the browser's
45origin so the same build works over localhost and remote connections.
46​
47Shared runs enable bundled dev to avoid a network round trip for each import level.
48`T3CODE_BUNDLED_DEV=0` opts out when debugging bundler differences. Two reload traps matter
49when changing this setup:
50​
51- The web entry must dynamically import the app so React refresh initializes before application
52 chunks. Static imports can work on first load and fail after a route split.
53- Bundled dev rebuilds Tailwind through watched files. Its ordinary Vite hot-update hook expects
54 a server/module graph that Rolldown does not provide.
55- The app and its routes are lazy chunks, built on first request. A plugin pre-bundles the
56 startup chain when the server starts. Renaming or moving a startup route or the app entry
57 silently drops it from that list.
58​
59The workarounds live in the [web entry](../../apps/web/src/bootstrap.ts),
60[Tailwind plugin](../../apps/web/vite/tailwind.ts), and
61[startup warmup](../../apps/web/vite/warmBundledDev.ts).
62​
63`vp run dev --share --built` skips the Vite dev server. It runs `vp build --watch` for the web
64app, and the backend serves `apps/web/dist` on the same tailnet URL and pairing flow. Use it when
65someone tests over a slow link or only needs to use the app: loads are production size, and the
66first load does not wait for dev bundling. There is no HMR. After an edit, wait for the
67`built in` line (about 6 s), then reload. Until the first build exists, the URL shows a page that
68reloads by itself. The license manifest is not generated in this mode. `--built` requires
69`--share` and the `dev` mode.
70​
71#### Reusable dev credential
72​
73Use this only on a hostname where you trust every service. Browsers send cookies to all ports
74on that hostname. Any service you visit there can receive the reusable admin credential,
75including services unrelated to T3 Code. If you run untrusted services on that hostname, keep
76normal per-environment pairing instead.
77​
78To use one browser profile across web dev worktrees on the same hostname, generate one fixed
79value once:
80​
81```sh
82openssl rand -hex 32
83```
84​
85Put that value in the main checkout's gitignored `.env`:
86​
87```dotenv
88T3CODE_DEV_AUTH_TOKEN=<the value generated above>
89```
90​
91The `t3.json` Setup Worktree action links that file to each worktree's `.env`. The dev runner reads repository env files at startup. `.env.local` and inherited process
92environment values override `.env`, so no per-worktree export is needed after setup.
93​
94For a manual worktree or launcher without that link, export the same fixed value instead:
95​
96```sh
97export T3CODE_DEV_AUTH_TOKEN="<the value generated above>"
98```
99​
100Do not generate a new value at startup. Start or restart `vp run dev --share` after configuration,
101then open its printed startup pairing URL once per browser profile on that hostname. Later web dev
102servers on the same hostname accept the shared cookie across ports. The cookie expires after 30
103days. Reload an old tab if its URL now serves a replacement environment.
104​
105The token and startup pairing URLs are reusable administrative secrets. Never put them in a
106commit, pull request, or public output. Every server still seeds its own auth database record at
107startup and keeps its own SQLite data, signing key, and revocation state. Desktop and non-dev
108servers ignore the value. See [environment authentication](../internals/environment-auth.md#reusable-dev-credential)
109for the security model.
110​
111## Checks
112​
113`vp run check:changed` runs CI's fast checks for your branch's changes: format and lint of the
114changed files, `knip:check` when code or a manifest changes, the generated GraphQL checks, typecheck
115of the affected packages and their dependents, and the test files beside the changed files. It maps
116files to packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), as CI does. It
117compares against the merge base with `origin/main`, or with a ref you pass. CI still runs the full
118test suites and the jobs the summary lists, so a local pass does not promise a green CI run.
119​
120While you iterate, run single checks:
121​
122```sh
123vp test run <files>
124vp lint <files>
125vp run --filter <package> typecheck
126```
127​
128In `apps/web`, a test that renders React or touches the DOM is named `*.browser.test.{ts,tsx}`
129and runs in headless Chromium with the React Compiler on, like the app. There is no jsdom; other
130`*.test.ts` files run in Node.
131​
132TypeScript workspaces typecheck with tsc-rs, which has Effect diagnostics built in.
133Keep `typescript`, `@effect/tsgo`, and the `effect-tsgo patch` prepare step: editors
134still use them for Effect quick fixes and refactors. Keep `@effect/tsgo` on the
135effect-tsgo version that tsc-rs ports (see the tsc-rs README), or the two disagree
136on rule names.
137Marketing keeps `astro check` for Astro files.
138​
139Use `vp run lint:mobile` for native mobile changes. CI owns the full suite; see
140[ci.yml](../../.github/workflows/ci.yml) for its current jobs.
141The [manual Windows lane](../../.github/workflows/windows-tests.yml) is available for focused
142Windows investigation while that suite is not a required gate.
143​
144### Unused code
145​
146`vp run knip:check` checks unused files and dependencies across the repo, then
147unused runtime exports in `apps/server`, `apps/desktop`, `apps/web`, and every internal package under
148`packages/`. CI enforces both checks.
149Exported types and Effect schemas are allowed without consumers. The schema preprocessor
150recognizes schema types, including aliases and schema classes; functions that create or decode
151schemas remain checked. Canonical Effect service construction APIs stay exported with an explicit
152`@public` annotation, which Knip recognizes. Completely unused files remain checked too.
153Named exports in web UI component modules are kept as complete component sets. Knip ignores
154unused exports in `apps/web/src/components/ui/*.tsx`, while still reporting an entire unused file.
155Use `vp run knip --workspace apps/web` to audit one workspace, including exports,
156or `vp run knip:production --workspace apps/web` to find code kept alive only by tests.
157The full export audit still has findings and is not a repo-wide CI gate. Extend the
158export check's workspace selectors as more workspaces become clean. Review callers before
159deleting code; production mode can also report development scripts and test fixtures.
160Runtime-discovered entrypoints and dependency exceptions belong in [knip.jsonc](../../knip.jsonc).
161​
162## Desktop artifacts
163​
164Local artifact builds are unsigned by default and write to `release/`:
165​
166```sh
167vp run dist:desktop:dmg
168vp run dist:desktop:linux
169vp run dist:desktop:win
170```
171​
172DMGs default to the host architecture. Use `--arch` to choose another target and `--keep-stage`
173to retain packaging files for inspection. Run `vp run dist:desktop:artifact --help` for other
174options.
175​
176### Linux AppImage prerequisites
177​
178Build on Linux because the browser-secret helper links against the host's libsecret. Install
179Rust, C/C++ build tools, libsecret development headers, pkg-config, and ImageMagick.
180​
181Ubuntu and Debian:
182​
183```sh
184sudo apt-get update
185sudo apt-get install cargo rustc build-essential libsecret-1-dev pkg-config imagemagick
186```
187​
188Fedora:
189​
190```sh
191sudo dnf install rust cargo gcc gcc-c++ make libsecret-devel pkgconf-pkg-config ImageMagick
192```
193​
194Arch Linux:
195​
196```sh
197sudo pacman -S rust base-devel libsecret pkgconf imagemagick
198```
199​
200The C toolchain, pkg-config, and libsecret headers are also needed for Linux desktop development.
201​
202### macOS DMG prerequisites
203​
204Install the Xcode Command Line Tools with `xcode-select --install` and install Rust.
205For a cross-architecture or universal build, add the requested Rust targets:
206​
207```sh
208rustup target add aarch64-apple-darwin x86_64-apple-darwin
209```
210​
211### Windows installer prerequisites
212​
213Install Rust, Python 3, and Visual Studio Build Tools with **Desktop development with C++**.
214Include the Windows SDK and the MSVC build tools and Spectre-mitigated libraries for the target
215architecture. Add its Rust target:
216​
217```powershell
218rustup target add x86_64-pc-windows-msvc
219# For an ARM64 installer:
220rustup target add aarch64-pc-windows-msvc
221```
222​
223NSIS is downloaded by electron-builder. WSL support additionally needs the Linux CLI archive
224passed as `--wsl-runtime`; see the
225[release runbook](./release.md#windows-payload-topology-and-update-validation).
226​
227### Signing and passkeys
228​
229Add `--signed` after configuring the platform credentials in the
230[release runbook](./release.md). macOS passkeys need a signed, provisioned app; follow the
231[Connect setup](./connect-setup.md#desktop-passkeys) for local signing and renderer HMR.