## Problem `apps/docs` ordered its build, dev and codegen steps with pnpm `pre`/`post` hooks and `&&` chains. Turbo couldn't see those steps, so it couldn't cache or parallelize them, and running the build through turbo ran the codegen twice. Part of [FE-4948](https://linear.app/supabase/issue/FE-4948/migrate-the-pnpm-scripts-to-use-turbo). ## Solution The ordering now lives in `apps/docs/turbo.jsonc` as `dependsOn`, and every pre/post hook is gone. The new `maybe-turbo` workspace bin runs a script through `turbo run` unless it's already inside turbo, so `pnpm build`, `pnpm dev`, `pnpm codegen:references` and the other entry points keep running their prerequisites. Turbo is bumped to 2.11.10 for its `jit` input mode. Tasks downstream of the uncached remote fetches use it to hash the gitignored files those fetches write after they finish, so a cache hit can't restore output built from older content. Strict-mode env vars are declared. Other changes: - The R2 upload moves from `postbuild` to the `vercel.json` build command, so it still runs when the build is a cache hit. - `codegen:references:new:ensure` re-downloads when any JavaScript TypeDoc dump is missing or empty. - The guides manifest is now sorted, so its output is deterministic. - A new `turbo-scripts` agent skill (listed in `AGENTS.md`) documents these conventions for every app. Its audit script, `node .agents/skills/turbo-scripts/scripts/audit.mjs apps/<name>`, flags scripts that need `maybe-turbo`, leftover `pre`/`post` hooks, script chains, and wrapped scripts without a turbo task. ## Review instructions 1. Read `packages/maybe-turbo/README.md`, `apps/docs/turbo.jsonc` and `.agents/skills/turbo-scripts/SKILL.md`. 2. From `apps/docs`, set `GH_TOKEN=$(gh auth token)` for the federated fetch and run `pnpm run build:markdown` a few times. Once warm, every task except `build:federated-content` and `codegen:references:new:ensure` should hit the cache. 3. Run `pnpm build` from `apps/docs` and check that the docs Vercel preview deploys and renders normally. ## Checklist Check all before review: - [ ] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
4.8 KiB
name, description
| name | description |
|---|---|
| turbo-scripts | Conventions for package.json scripts and turbo.jsonc tasks in the monorepo. Use when adding, changing or reviewing scripts in any apps/* or packages/* package.json, any turbo.jsonc (root or per-package), pre/post hooks, script chains (&&, run-p), maybe-turbo, or turbo task inputs, outputs, env and caching. Includes an audit script that flags scripts that should use maybe-turbo. |
Turbo scripts
Task ordering belongs in turbo.jsonc (dependsOn), not in package.json. pnpm pre/post hooks and &&/run-p chains hide steps from turbo, so it can't cache or parallelize them, and running the script through turbo can run them twice. apps/docs is the reference implementation.
Audit first
Run the audit for every package you touch, before and after your change:
node .agents/skills/turbo-scripts/scripts/audit.mjs apps/docs
It lists each turbo task the package can run (its own turbo.jsonc plus the root's) and reports:
NEEDS maybe-turbo: the task has same-packagedependsOnentries, but the script isn't wrapped.pre/post hooks to migrate:pre<name>/post<name>scripts.preinstallis ignored.scripts that call other scripts: chains such aspnpm a && pnpm borrun-p a b. An alias that calls a single script with extra args or env (pnpm run embeddings --refresh) isn't reported.maybe-turbo scripts with no turbo task:turbo runfails for these withCould not find task.
Fix every finding in the package you're changing, or tell the user why one stays.
Rules
Ordering
- Express ordering as
dependsOnin the package'sturbo.jsonc. Remove the hook or chain it replaces. - Wrap a script with
maybe-turbo(frompackages/maybe-turbo; add"maybe-turbo": "workspace:*"todevDependencies) when its task has same-packagedependsOnentries. Outside turbo,pnpm <script>then runsturbo run <script> --filter=<package>, so prerequisites still run. Leaf scripts with no dependencies don't need it. - Don't split a task into a
turbo run <name>-innerscript plus an inner script. Usemaybe-turbo, so each task has one script name for callers andturbo.jsonc. - Put compound commands in one quoted argument:
"typecheck": "maybe-turbo \"next typegen && tsc --noEmit\"".maybe-turboexits with an error if&&,||,;or|appears outside the quotes. - A task that only groups other tasks gets a bare
"<name>": "maybe-turbo"script, sopnpm <name>still works. - Every wrapped script needs a task in
turbo.jsonc(the package's or the root's). - When you override
dependsOnfor a root task such asbuildortypecheck, keep^build/^typecheck. - Persistent sidecars that must run next to
dev(for examplevelite dev) go in the task'swithkey, notrun-p.
Caching
-
Declare
outputsfor every cacheable task that writes files. If two tasks write into the same directory, list only each task's own files. -
Mark tasks that fetch remote content or check local state as
"cache": false. -
Default
inputsskip gitignored files, and plain globs are hashed whenturbostarts, before any task runs. A task that reads gitignored files written by an uncached task must list them injitmode, or a cache hit can restore output built from stale content:"inputs": ["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["content/guides/**"] }] -
Keep generated output deterministic (sorted keys, stable order). A tracked file that a task rewrites differently on every run invalidates the whole package's cache.
Env
- Turbo runs tasks in strict env mode, which drops undeclared variables. Declare every variable the task reads:
envfor values that change the output,passThroughEnvfor secrets and credentials that don't. - Check what the script and the modules it imports read (
git grep "process.env"), including shared packages.
Side effects
- On a cache hit, turbo restores outputs without running the script. Keep uploads, deploys and database writes in uncached tasks or outside turbo (for example in a
vercel.jsonbuildCommandafterpnpm build).
Callers
- Find everything that runs the scripts you change:
.github/workflows,vercel.json, rootpackage.json, other apps' scripts,e2e/*, and docs/READMEs. A plainpnpm <script>keeps working once the script is wrapped withmaybe-turbo. - A wrapped script called from inside another turbo task sees
TURBO_HASHand runs without its prerequisites. Declare the dependency inturbo.jsoncinstead of calling the script from another script.
Verify
- Run the audit again.
- Check the graph:
pnpm turbo run <task> --filter=<package> --dry=json. - Run the entry point the way callers do, for example
pnpm buildin the package, then run it again and confirm the second run hits the cache. Tasks that usejitinputs reporthash: nullin--dry=json; that's expected.