## 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>
maybe-turbo
Runs a package script through Turborepo unless it's already running inside Turborepo.
TL;DR: In the script "<script>": "maybe-turbo <command>", maybe-turbo is shorthand for:
if [ -n "$TURBO_HASH" ]; then <command>; else turbo run <script> --filter=<package>; fi
Prefix a script with maybe-turbo, and pnpm run <script> gets the task's dependsOn prerequisites and caching from turbo.jsonc, without pnpm pre/post hooks.
// package.json
"scripts": {
"build": "maybe-turbo next build --webpack"
}
// turbo.jsonc
"tasks": {
"build": {
"dependsOn": ["^build", "codegen"],
"outputs": [".next/**", "!.next/cache/**"]
}
}
Running pnpm build now runs codegen first and restores build from the cache when its inputs haven't changed.
Why
Pre/post hooks and && chains hide task ordering from Turborepo, so it can't cache or parallelize the steps. Moving the ordering into dependsOn fixes that. However, a script run directly (pnpm build in the package, a Vercel build command, a CI step) then skips its prerequisites. maybe-turbo keeps those entry points working.
It also leaves one definition of the pipeline. Root scripts such as pnpm dev:docs and pnpm build:docs already go through Turborepo, so with hooks the same ordering lived in two places: turbo.jsonc for root commands and prebuild/predev for commands run in the package. A step added to one and not the other only broke one of the paths. With maybe-turbo, pnpm dev in apps/docs, pnpm dev --filter=docs and pnpm dev:docs from the root all run the same task graph.
Why not call turbo from the script directly?
Turborepo runs a task by running the package script with the same name, so a script can't call turbo run on itself. Without maybe-turbo, every task with prerequisites needs two scripts:
"build:whatever": "turbo run build:whatever-inner",
"build:whatever-inner": "node scripts/build-whatever.mjs"
The turbo.jsonc task is then defined for the inner name, and callers have to know which name to use. maybe-turbo keeps a single script:
"build:whatever": "maybe-turbo node scripts/build-whatever.mjs"
How it works
Turborepo sets TURBO_HASH in the environment of every task it runs.
- Outside Turborepo (
TURBO_HASHisn't set),maybe-turborunsturbo run <script> --filter=<package>. Turborepo runs the prerequisites, then runs the same script again. - Inside Turborepo (
TURBO_HASHis set),maybe-turboruns the wrapped command directly.
The script name and package come from the npm_lifecycle_event and npm_package_name variables that pnpm sets, so maybe-turbo only works when run from a package.json script.
Setup
Add the package to the workspace package that uses it:
"devDependencies": {
"maybe-turbo": "workspace:*"
}
Then define a task in turbo.jsonc (the package's or the root's) for every script you wrap. Otherwise turbo run fails with Could not find task.
Usage
Simple commands
Write the command after maybe-turbo as you normally would. Quoted arguments are preserved:
"test:smoke": "maybe-turbo vitest -t \"prod smoke test\""
Compound commands
Put commands that use &&, ||, ; or | in one quoted argument. maybe-turbo runs it through the shell:
"typecheck": "maybe-turbo \"next typegen && tsc --noEmit\""
maybe-turbo exits with an error if it finds an operator outside the quotes. Otherwise the shell would run the rest of the chain twice: once inside Turborepo and once after it.
Tasks that only group dependencies
With no command, maybe-turbo does nothing inside Turborepo. Use it for scripts that exist only to run other tasks:
"codegen": "maybe-turbo"
"codegen": {
"dependsOn": ["codegen:graphql", "codegen:types"]
}
Extra arguments
Arguments added after the script name are forwarded to the wrapped command, outside Turborepo through turbo run … -- <args>:
pnpm run embeddings --refresh
Turborepo passes these arguments only to the task you ran, not to its dependencies.
Things to know
- Strict env mode. Turborepo only passes environment variables that are declared in the task's
envorpassThroughEnv. A script that worked with a pnpm hook can fail under Turborepo if it reads an undeclared variable. - Cache hits skip side effects. On a cache hit, Turborepo restores outputs and logs without running the command. Keep side effects such as uploads and deploys in uncached tasks (
"cache": false) or outside Turborepo entirely. - Nested runs execute directly. A wrapped script called from inside another Turborepo task (for example
pnpm --filter=docs run build:guides-markdownfrom another package's build) seesTURBO_HASHand runs without its prerequisites. Declare the dependency inturbo.jsoncinstead. - Gitignored generated files. Turborepo's default inputs skip gitignored files, and plain
inputsglobs are hashed whenturbostarts, before any task runs. If a task reads files written by an uncached task, list them injitmode so they're hashed after that task finishes (for example["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["content/generated/**"] }]). Otherwise a cache hit can restore output built from stale content.