Skip to content

Commit e04afd2

Browse files
authored
Merge pull request #36 from typetorch/feat/goblox-compiler
build: use goblox as the compiler when installed, else rbxtsc
2 parents 0a714e3 + 45d2c36 commit e04afd2

13 files changed

Lines changed: 533 additions & 61 deletions

‎README.md‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ What the commands call:
3535
- **git**, and **Rojo 7.7.x** (plus **Lune** for `kernel deploy`) through [Rokit](https://github.com/rojo-rbx/rokit):
3636
pin `rojo-rbx/rojo@7.7.0-rc.1` in the game's `rokit.toml`.
3737
- **Bun** for `typetorch build` / `deploy` / `upload`: the game repo is a Bun project and the build runs
38-
`bun run build` (or `bun run rbxtsc`) in it. Commands that don't build (`approve`, `promote`, `rollback`,
38+
`bun run build` (or `bun run rbxtsc`, or `bun run goblox`: see "Compiler") in it. Commands that don't build (`approve`, `promote`, `rollback`,
3939
`deployments`, `keys`, `pin`, `assets status`, `doctor`) don't need it.
4040
- **zstd** for hot assets (`assets sync` / `status`, which read Roblox-serialized exports): Bun, or Node 22.15+.
4141
`typetorch doctor` reports the runtime, Bun and zstd.
@@ -136,7 +136,7 @@ get an allowlisted environment without any key. Keys are never printed.
136136
Old names, read in CLI 0.9 only, with a warning naming the new one: `TYPETORCH_FLEET_TOKEN` (= `TYPETORCH_ADMIN_TOKEN`),
137137
`TYPETORCH_FLEET_INGEST_TOKEN` (= `TYPETORCH_API_KEY`).
138138

139-
Other settings: `TYPETORCH_STATE_DIR` (where the logs live, default `.typetorch/`), `TYPETORCH_PROPOSED_BY`, `TYPETORCH_ROJO` / `TYPETORCH_LUNE` (tool paths), `TYPETORCH_BUILD_CACHE=0` (turns the build cache off), `TYPETORCH_CHILD_ENV=NAME,NAME` (extra
139+
Other settings: `TYPETORCH_STATE_DIR` (where the logs live, default `.typetorch/`), `TYPETORCH_PROPOSED_BY`, `TYPETORCH_ROJO` / `TYPETORCH_LUNE` (tool paths), `TYPETORCH_BUILD_CACHE=0` (turns the build cache off), `TYPETORCH_COMPILER=goblox|rbxtsc` (the compiler; see "Compiler"), `TYPETORCH_CHILD_ENV=NAME,NAME` (extra
140140
non-secret variables for child processes), `TYPETORCH_KEY_FILE` / `TYPETORCH_FALLBACK_KEY_FILE` (the signing key files;
141141
read from the real environment only, never from an env file, and never passed to a child process).
142142

@@ -211,7 +211,7 @@ show whether signing is ready, with placeholders instead of real signatures. Any
211211
| Command | Does |
212212
|---|---|
213213
| `typetorch init [--dir <folder>] [--phase <name>] [--answers <file>] [--agent] [--teardown]` | the guided setup, from an empty folder to a live game (see "Setup"); `--agent` prints `AGENT_PROMPT.md` again; `--teardown` removes the backend step 6 installed (asks first; its data only when you say so) |
214-
| `typetorch build [--branch <b>] [--channel prod\|dev] [--clean]` | writes `src/shared/build.ts`, runs rbxtsc (`bun run build` if the repo has a build script), and rojo-builds `.typetorch/payload.rbxm` with the identity stamped on the root; checks it holds only Folders and ModuleScripts; writes `.typetorch/payload.json`. `--clean`: `git clean -fdX` out/ and include/ first, then restore the build cache |
214+
| `typetorch build [--branch <b>] [--channel prod\|dev] [--clean]` | writes `src/shared/build.ts`, runs the compiler (goblox when installed, else rbxtsc; `bun run build` if the repo has a build script), and rojo-builds `.typetorch/payload.rbxm` with the identity stamped on the root; checks it holds only Folders and ModuleScripts; writes `.typetorch/payload.json`. `--clean`: `git clean -fdX` out/ and include/ first, then restore the build cache |
215215
| `typetorch upload [--no-build]` | clean build, upload as a new Model asset, wait for moderation; no deploy (then `promote` it) |
216216
| `typetorch deploy [--branch] [--channel] [--no-build] [--dry-run] [--message <text>] [--force] [--propose] [--proposed-by <who>] [--test] [--skip-test <reason>] [--wait [s]] [--no-wait] [--rollout <1-99>]` | clean build, upload, wait until Approved, log "uploaded"; the cloud test (always for prod-channel branches); then approve here (a person at a terminal) or write a proposal; on approval: deploy message, durable head, log "published"; then (prod: by default) wait for the servers' reports. Per-stage timings |
217217
| `typetorch deploy --widen <1-100> [--branch]` | re-send the branch's live deploy (same seq) to more servers; dev-channel branches only (see "Rollouts") |
@@ -254,7 +254,7 @@ show whether signing is ready, with placeholders instead of real signatures. Any
254254
| `typetorch mcp` | an MCP server on stdio with `serve` and `studio` as tools, for agents |
255255
| `typetorch migrate --from flamework [--dry-run] [--net compat\|native] [--report <file>] [--allow-dirty]` | the mechanical part of moving a Flamework 1.x game (see "Migrating from Flamework"); local only, no keys |
256256
| `typetorch update [<version>] [--check] [--yes]` | updates this CLI to the newest `@typetorch/cli` on npm (or `<version>`) the way it was installed: in the game's `package.json` with its package manager (bun, pnpm, yarn or npm, from the lockfile; a devDependency stays one), or globally (`npm i -g`, `bun add -g`, pnpm, yarn). Asks y/N first (`--yes` skips; without a terminal it prints the command). npx needs nothing (`npx @typetorch/cli@latest`); a git checkout gets the `git pull` to run. `--check` only shows the versions and the command. After any other command at a terminal, the CLI checks npm at most once a day (1.5 s timeout, cached in `~/.typetorch/update-check.json`) and, when a newer version is out, asks once whether to update now; after a no it reminds once a day. Never in CI, `--json` or non-interactive runs; `TYPETORCH_UPDATE_CHECK=off` turns it off |
257-
| `typetorch doctor [--show-ok]` | prints the **Config** section (every value the CLI reads and where it came from: typetorch.json, the game repo's `.env`, the environment, the settings record; secrets only as set / unset), then checks the runtime, bun, zstd, git, rojo 7.7.x, roblox-ts, `typetorch.json`, the env file, each job's key, the approval policy, the state dir, the health window per channel and the auto-rollback threshold, the signing keys (key files vs typetorch.json, the key asset, the place; the place and the key asset's content through one Luau Execution task with the assets key; the same task warns when the place still holds `ServerStorage.TypeTorchDev`, the Studio local payload folder that live servers ignore), the backend (typetorch.json `backend.url` with your keys: url, `/healthz`, the game key's and the admin token's roles; the record's own backend section; a stale tunnel or a wrong key is a FAIL with the fix), the backend's owner list against the signed record, **live servers** (FAIL when the published place has the kernel, the default branch has no verified head in the DataStore heads or the kernel's BootstrapHeads, and the place has no backup build: kernel 0.3.6+ then moves every player out after 15 s and kicks after 3 bounces; the fix names the git branch mapped to the default branch and `kernel restore --version <n>`), **old game build** (warn when a roblox-ts build such as `ServerScriptService.TS` or `ReplicatedStorage.rbxts_include` runs next to the kernel), and probes each key's scopes with harmless calls. Only problems and info lines print; `--show-ok` lists the passed checks too (`--json` always has every check) |
257+
| `typetorch doctor [--show-ok]` | prints the **Config** section (every value the CLI reads and where it came from: typetorch.json, the game repo's `.env`, the environment, the settings record; secrets only as set / unset), then checks the runtime, bun, zstd, git, rojo 7.7.x, the compiler (goblox or rbxtsc and why; a warning when goblox is selected and the tsconfig lists a JS plugin other than `@typetorch/transformer`, which goblox ignores; with rbxtsc it suggests `bun add -d goblox`), roblox-ts, `typetorch.json`, the env file, each job's key, the approval policy, the state dir, the health window per channel and the auto-rollback threshold, the signing keys (key files vs typetorch.json, the key asset, the place; the place and the key asset's content through one Luau Execution task with the assets key; the same task warns when the place still holds `ServerStorage.TypeTorchDev`, the Studio local payload folder that live servers ignore), the backend (typetorch.json `backend.url` with your keys: url, `/healthz`, the game key's and the admin token's roles; the record's own backend section; a stale tunnel or a wrong key is a FAIL with the fix), the backend's owner list against the signed record, **live servers** (FAIL when the published place has the kernel, the default branch has no verified head in the DataStore heads or the kernel's BootstrapHeads, and the place has no backup build: kernel 0.3.6+ then moves every player out after 15 s and kicks after 3 bounces; the fix names the git branch mapped to the default branch and `kernel restore --version <n>`), **old game build** (warn when a roblox-ts build such as `ServerScriptService.TS` or `ReplicatedStorage.rbxts_include` runs next to the kernel), and probes each key's scopes with harmless calls. Only problems and info lines print; `--show-ok` lists the passed checks too (`--json` always has every check) |
258258

259259
Every command takes `--json` (one JSON document on stdout; human lines go to stderr), `--verbose`, `--config <path>`
260260
and `--env-file <path>` (`remote-claude` passes everything to the dev-server). Under Node, an `--env-file` naming a
@@ -288,7 +288,8 @@ and writes nothing.
288288
outside a trove, `@flamework/components`, `Dependency<T>()` before construction, `loadstring`, remotes,
289289
MessagingService, DataStore / ProfileService code, BindToClose, Scripts left in the source tree, toolchain leftovers.
290290
- **Output:** `typetorch-migrate-report.md` (`--report`): a summary, every flag by kind with file, line and the fix,
291-
and what was rewritten; plus a short summary on the terminal (`--json` for both as data).
291+
and what was rewritten; plus a short summary on the terminal (`--json` for both as data). Both suggest the optional
292+
fast compiler, `bun add -d goblox` (see "Compiler"; it ignores JS tsconfig plugins other than `@typetorch/transformer`).
292293

293294
`typetorch build` warns while the game still uses `createFlameworkCompat` (its calls are part of the protocol hash).
294295

@@ -333,6 +334,28 @@ and writes nothing.
333334
compile skips unchanged files). Repo build scripts that write build.ts themselves should skip it when
334335
`TYPETORCH_SKIP_BUILD_INFO=1`.
335336

337+
### Compiler
338+
339+
`typetorch build` (and deploy / upload) compiles with **goblox** when it is installed in the game repo, else with
340+
**rbxtsc** (roblox-ts), as before. goblox is roblox-ts ported to Go on typescript-go (TypeScript 7): the same CLI flags,
341+
out/ layout and tsbuildinfo-based incremental builds, several times faster. Optional:
342+
343+
```sh
344+
bun add -d goblox
345+
```
346+
347+
(`@typetorch/goblox` is an alias package for the same `goblox` bin.) Which compiler runs, first match wins:
348+
349+
1. `TYPETORCH_COMPILER=goblox|rbxtsc` (environment or `.env`), then `"compiler": "goblox" | "rbxtsc"` in typetorch.json;
350+
2. goblox when `node_modules/.bin/goblox` (`goblox.exe` / `goblox.cmd` on Windows) exists;
351+
3. rbxtsc.
352+
353+
goblox asked for explicitly but not installed fails the build (it never falls back silently); any other value is an
354+
error. `--verbose` shows the compiler and why it was picked, and the timing line names it (`goblox 1.9 s`).
355+
goblox runs `@typetorch/transformer` natively (a Go port, from the same tsconfig `plugins` entry, debug-macro stripping
356+
included) and **ignores every other JS tsconfig plugin** (`rbxts-transform-debug` too): `typetorch doctor` warns when
357+
goblox is selected and the tsconfig lists one. Set `"compiler": "rbxtsc"` to keep such a plugin.
358+
336359
### Builds
337360

338361
- **Clean deploys:** `deploy` and `upload` run `git clean -fdX` on out/ and include/ (ignored files only) before
@@ -342,7 +365,8 @@ and writes nothing.
342365
`.typetorch/build-cache/<channel>/` with a sha256 per file. The next clean build cleans out/ as above, puts the cache
343366
back, and rbxtsc recompiles only what changed (a one-file edit: seconds instead of a full compile). The cache is
344367
dropped when any file fails its hash or when tsconfig.json, package.json or a lockfile changed; outputs whose source
345-
is gone are removed first; dev and prod never share one. Needs `"incremental": true` with the tsbuildinfo inside
368+
is gone are removed first; dev and prod never share one. Switching to goblox, or to another goblox version, is a full
369+
compile (the compiler is in the cache key; rbxtsc's keys are what they were before goblox). Needs `"incremental": true` with the tsbuildinfo inside
346370
outDir. `TYPETORCH_BUILD_CACHE=0` turns it off.
347371
- **Payload check:** the built `.rbxm` must be one `Model` holding only `Folder`s and `ModuleScript`s; anything else
348372
(Scripts, values from `.txt` files, models from `.rbxm` files...) fails the build with its path.
@@ -355,8 +379,10 @@ and writes nothing.
355379
transformer's when it ships `macros.d.ts`). Prod builds compile with a generated `.tsconfig.typetorch.json` (deleted
356380
afterwards): once `rbxts-transform-debug` is uninstalled it only adds `debugMacros: false` to the transformer's
357381
plugin entry (a different plugin list, so rbxtsc's incremental state never reuses dev outputs for prod); while it is
358-
still installed, the first plugin is a CLI transformer doing the same stripping. The CLI appends
359-
`-p .tsconfig.typetorch.json` to a build script that ends with `rbxtsc` (else it runs rbxtsc directly).
382+
still installed (rbxtsc only: goblox runs no JS transformer), the first plugin is a CLI transformer doing the same
383+
stripping. The CLI appends `-p .tsconfig.typetorch.json` to a build script that ends with the compiler (`rbxtsc` or
384+
`goblox`), else it runs the compiler directly; a build script that ends with the other compiler is skipped the same
385+
way (with a warning).
360386

361387
### Deploy message
362388

‎src/build-cache.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* - one cache per channel: prod compiles with a different plugin list (debug macros stripped, S-L7) that rbxtsc's
1111
* buildinfo does not track, so a dev output must never be reused in a prod build;
1212
* - the cache key hashes everything rbxtsc's buildinfo can't see: tsconfig.json, package.json, the lockfiles (the
13-
* transformer plugins' code), the strip transformer version and the CLI's cache version; any change = full build;
13+
* transformer plugins' code), the strip transformer version, the CLI's cache version and, for goblox, the
14+
* compiler and its version (compiler.ts; rbxtsc adds nothing, so its keys are what they were before goblox);
15+
* any change = full build. goblox writes the same out/ and tsbuildinfo layout, so the rest applies to it as is;
1416
* - every restored file must match its recorded sha256, or the whole cache is dropped;
1517
* - restored outputs whose source no longer exists are removed before rbxtsc runs (rbxtsc never deletes them);
1618
* - the post-compile checks (compiled build.ts carries the commit, every output has a tracked source) run as before.
@@ -20,6 +22,7 @@
2022
import { createHash } from "node:crypto";
2123
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2224
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
25+
import type { CompilerKey } from "./compiler.ts";
2326
import { STRIP_TRANSFORMER_VERSION } from "./debug-macros.ts";
2427
import { settings } from "./env.ts";
2528
import { isRecord, parseJsonc } from "./json.ts";
@@ -117,9 +120,14 @@ export function removeStrayBuildInfo(root: string, layout: CacheLayout) {
117120
} catch {}
118121
}
119122

120-
/** Hash of everything that changes rbxtsc's output but is not in its buildinfo. */
121-
export function buildCacheKey(root: string, channel: Channel): string {
123+
/**
124+
* Hash of everything that changes the compiler's output but is not in its buildinfo. The compiler is part of it only
125+
* when it isn't rbxtsc: switching to goblox (or between goblox versions) is a full compile, and an rbxtsc key is the
126+
* same as before goblox existed (roblox-ts's own version is already in the lockfile).
127+
*/
128+
export function buildCacheKey(root: string, channel: Channel, compiler?: CompilerKey): string {
122129
const parts = [`v${BUILD_CACHE_VERSION}`, `channel ${channel}`, `strip ${STRIP_TRANSFORMER_VERSION}`];
130+
if (compiler && compiler.name !== "rbxtsc") parts.push(`compiler ${compiler.name} ${compiler.version}`);
123131
for (const file of KEY_FILES) {
124132
const path = join(root, file);
125133
parts.push(`${file} ${existsSync(path) ? sha256(readFileSync(path)) : "-"}`);
@@ -141,6 +149,7 @@ export function restoreBuildCache(
141149
layout: CacheLayout,
142150
channel: Channel,
143151
candidates: (rel: string) => string[],
152+
compiler?: CompilerKey,
144153
): RestoreResult {
145154
const dir = cacheDir(root, channel);
146155
const manifestPath = join(dir, MANIFEST);
@@ -156,7 +165,7 @@ export function restoreBuildCache(
156165
return drop("unreadable manifest");
157166
}
158167
if (manifest?.v !== BUILD_CACHE_VERSION || typeof manifest.files !== "object" || manifest.files === null) return drop("old cache format");
159-
if (manifest.key !== buildCacheKey(root, channel)) return drop("tsconfig, package.json, a lockfile or the CLI changed");
168+
if (manifest.key !== buildCacheKey(root, channel, compiler)) return drop("tsconfig, package.json, a lockfile, the compiler or the CLI changed");
160169
const entries = Object.entries(manifest.files);
161170
const files = join(dir, FILES);
162171
const onDisk = listFiles(files).map((path) => posix(relative(files, path)));
@@ -177,12 +186,12 @@ export function restoreBuildCache(
177186
}
178187

179188
/** Replaces the channel's cache with the current outDir (call after a successful, checked build). */
180-
export function saveBuildCache(root: string, layout: CacheLayout, channel: Channel): number {
189+
export function saveBuildCache(root: string, layout: CacheLayout, channel: Channel, compiler?: CompilerKey): number {
181190
const dir = cacheDir(root, channel);
182191
const files = join(dir, FILES);
183192
rmSync(dir, { recursive: true, force: true });
184193
mkdirSync(files, { recursive: true });
185-
const manifest: Manifest = { v: BUILD_CACHE_VERSION, key: buildCacheKey(root, channel), files: {} };
194+
const manifest: Manifest = { v: BUILD_CACHE_VERSION, key: buildCacheKey(root, channel, compiler), files: {} };
186195
for (const path of listFiles(layout.outDir)) {
187196
const rel = posix(relative(layout.outDir, path));
188197
const bytes = readFileSync(path);

0 commit comments

Comments
 (0)