mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem `ui-library`, `design-system`, `learn`, `kb`, `www` and `studio` still order their build, dev and typecheck steps with pnpm `pre`/`post` hooks, `&&` chains and `run-p`. Turbo can't see those steps, so it can't cache or parallelize them. Follow-up to #52556, which migrated `apps/docs`. Part of [FE-4977](https://linear.app/supabase/issue/FE-4977/migrate-remaining-apps-pnpm-scripts-to-turbo-tasks). ## Solution The ordering now lives in each app's `turbo.jsonc` as `dependsOn`, the hooks and chains are gone, and scripts with same-package prerequisites are wrapped with `maybe-turbo`. `node .agents/skills/turbo-scripts/scripts/audit.mjs apps/<name>` reports no findings for any of the six apps. - **`ui-library`, `design-system`, `learn`:** content, registry and markdown steps are turbo tasks with declared outputs. `dev:content` uses the `with` key. `build:next` and `dev:next` are folded into `build` and `dev`. `ui-library`'s markdown task now depends on `build:registry`, which the old chain hid. `pnpm --filter library build:registry` still regenerates the committed registry output. - **`kb`:** `fetch:federated-content` is uncached, and the tasks that read its output use `jit` inputs. - **`www`:** - `build` depends on `docs#build:guides-markdown`, so federated content is fetched once instead of twice. - `build:next` is folded into `build`. - `typecheck` runs `next typegen` itself. - `turbo-build.test.ts` is updated for the new task graph. It reads `PATH` through a copy of the env, because `turbo/no-undeclared-env-vars` flags it once the `passThroughEnv: ["*"]` wildcard is gone. - `passThroughEnv: ["*"]` is gone, and the env vars the content scripts read are declared. - **`studio`:** `typecheck` runs `next typegen` inline, and `lint` depends on a new `lint:type-checks` task. The `predev` turbopack cache clean moved into `scripts/dispatch.js`. It's a local side effect, and making it a turbo task would route `dev` through turbo's strict env filtering, which drops `NODE_ENV`, `MODE` and `STUDIO_FRAMEWORK`. ## Review instructions - For each app, check that a second `pnpm build` hits the cache. `www`'s fetch and content tasks re-run by design, since they're uncached. - Not verified: the `www` and `studio` dev servers started from the repo root, a Studio production build, the e2e flow, and runs with real production credentials. - `kb`'s build reads a remote database that turbo can't hash. It stays cached, keyed on `SUPABASE_URL`. Say if you'd rather make it uncached. - Builds rewrite two tracked files, `apps/docs/public/markdown/manifest.json` and `apps/www/public/customers-rss.xml`, so a fresh checkout can miss the cache once. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
70 lines
2.8 KiB
JavaScript
70 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
|
// Dispatch a top-level npm script (dev/build/start) to either the next- or
|
|
// tanstack-flavoured variant based on STUDIO_FRAMEWORK. We parse the env files
|
|
// (via the shared scripts/lib/env.js parser) and pull out only
|
|
// STUDIO_FRAMEWORK — we deliberately don't load the whole file into the
|
|
// child's process.env, because vite and the start script do their own .env
|
|
// loading and would otherwise refuse to override the dispatcher-set values,
|
|
// including NEXT_PUBLIC_IS_PLATFORM which the e2e `.env.test` needs to flip to
|
|
// `false`.
|
|
//
|
|
// Usage: node scripts/dispatch.js <target>
|
|
// target ∈ { dev, build, start }
|
|
//
|
|
// Resolves to `pnpm run <target>:<framework>` where framework is `tanstack`
|
|
// when STUDIO_FRAMEWORK=tanstack (set in the shell env, `.env`, or
|
|
// `.env.local`), otherwise `next`.
|
|
import { spawn } from 'node:child_process'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { cleanTurbopackCache } from './clean-turbopack-cache.mjs'
|
|
import { readEnvFiles } from './lib/env.js'
|
|
|
|
const target = process.argv[2]
|
|
if (!target) {
|
|
console.error('dispatch.js: missing target (expected one of: dev, build, start)')
|
|
process.exit(2)
|
|
}
|
|
|
|
const studioRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
|
|
// Shell env wins, then `.env.local`, then `.env` — the same precedence
|
|
// vite and the start script use, so STUDIO_FRAMEWORK set in either file is
|
|
// picked up (not just `.env.local`).
|
|
const fileEnv = readEnvFiles(studioRoot, ['.env', '.env.local'])
|
|
const studioFramework = process.env.STUDIO_FRAMEWORK ?? fileEnv.STUDIO_FRAMEWORK
|
|
const framework = studioFramework === 'tanstack' ? 'tanstack' : 'next'
|
|
const script = `${target}:${framework}`
|
|
|
|
// Prune stale Turbopack dev cache before the dev server starts. This is a local side effect
|
|
// rather than a build step, so it lives here instead of in a `predev` hook or a turbo task.
|
|
if (target === 'dev') cleanTurbopackCache(studioRoot)
|
|
|
|
// Use async `spawn` rather than `spawnSync` — long-running dev servers
|
|
// (vite dev / next dev) wedge under `spawnSync` because Node holds the
|
|
// event loop and stdin doesn't flow through cleanly. The dev server says
|
|
// "ready" then exits ~1s later. `spawn` + manual forwarding keeps the
|
|
// child interactive and lets the parent exit cleanly when the child does.
|
|
const child = spawn('pnpm', ['run', script], {
|
|
stdio: 'inherit',
|
|
env: process.env,
|
|
})
|
|
|
|
const forwardSignal = (signal) => {
|
|
if (!child.killed) child.kill(signal)
|
|
}
|
|
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT']) {
|
|
process.on(signal, () => forwardSignal(signal))
|
|
}
|
|
|
|
child.on('exit', (code, signal) => {
|
|
if (signal) process.kill(process.pid, signal)
|
|
else process.exit(code ?? 1)
|
|
})
|
|
|
|
child.on('error', (err) => {
|
|
console.error('dispatch.js: failed to spawn child:', err)
|
|
process.exit(1)
|
|
})
|