mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## 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>
98 lines
3.8 KiB
JavaScript
98 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
|
// Lists every turbo task a workspace package can run (its own turbo.jsonc plus the root's) and
|
|
// whether the matching package.json script is wrapped with maybe-turbo.
|
|
//
|
|
// node .agents/skills/turbo-scripts/scripts/audit.mjs apps/docs
|
|
import { existsSync, readFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
|
|
const dir = process.argv[2]
|
|
if (!dir) {
|
|
console.error('Usage: node audit.mjs <package dir>, for example apps/docs')
|
|
process.exit(1)
|
|
}
|
|
|
|
const readJsonc = (path) =>
|
|
existsSync(path)
|
|
? JSON.parse(
|
|
readFileSync(path, 'utf8')
|
|
.replace(/^\s*\/\/.*$/gm, '')
|
|
.replace(/,(\s*[}\]])/g, '$1')
|
|
)
|
|
: { tasks: {} }
|
|
|
|
const scripts = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).scripts ?? {}
|
|
const local = readJsonc(join(dir, 'turbo.jsonc')).tasks ?? {}
|
|
const root = readJsonc('turbo.jsonc').tasks ?? {}
|
|
|
|
const rows = [...new Set([...Object.keys(local), ...Object.keys(root)])].sort().map((task) => {
|
|
const config = { ...root[task], ...local[task] }
|
|
const script = scripts[task]
|
|
const deps = (config.dependsOn ?? []).filter((dep) => !dep.startsWith('^'))
|
|
const wrapped = script?.startsWith('maybe-turbo') ?? false
|
|
let status = 'ok'
|
|
if (script === undefined) status = deps.length > 0 ? 'no script (aggregate?)' : 'no script'
|
|
else if (deps.length > 0 && !wrapped) status = 'NEEDS maybe-turbo'
|
|
return [
|
|
task,
|
|
local[task] ? 'package' : 'root',
|
|
wrapped ? 'yes' : 'no',
|
|
config.cache === false ? 'no' : 'yes',
|
|
status,
|
|
deps.join(', ') || '-',
|
|
]
|
|
})
|
|
|
|
// pnpm runs `pre<name>`/`post<name>` around `<name>`. `preinstall` is an install hook, not ordering.
|
|
const hooks = Object.keys(scripts).filter((name) => {
|
|
const match = name.match(/^(?:pre|post)(.+)$/)
|
|
return match && match[1] !== 'install' && scripts[match[1]] !== undefined
|
|
})
|
|
|
|
// Scripts that sequence other scripts (`pnpm a && pnpm b`, `run-p a b`) hide steps from turbo.
|
|
// An alias that calls one script with extra args or env (`pnpm run embeddings --refresh`) is fine.
|
|
const names = Object.keys(scripts)
|
|
const matchScripts = (pattern) =>
|
|
pattern.endsWith('*')
|
|
? names.filter((name) => name.startsWith(pattern.slice(0, -1)))
|
|
: names.filter((name) => name === pattern)
|
|
const scriptsCalledBy = (segment) => {
|
|
const words = segment
|
|
.trim()
|
|
.split(/\s+/)
|
|
.filter((word) => !/^\w+=/.test(word))
|
|
if (words[0] === 'pnpm') {
|
|
const rest = words.slice(1).filter((word) => !word.startsWith('-'))
|
|
return matchScripts(rest[0] === 'run' ? (rest[1] ?? '') : (rest[0] ?? ''))
|
|
}
|
|
if (['run-p', 'run-s', 'npm-run-all'].includes(words[0])) {
|
|
return words
|
|
.slice(1)
|
|
.filter((word) => !word.startsWith('-'))
|
|
.flatMap(matchScripts)
|
|
}
|
|
return []
|
|
}
|
|
const chains = Object.entries(scripts)
|
|
.map(([name, command]) => {
|
|
const segments = command.split(/&&|\|\||;/)
|
|
const called = [...new Set(segments.flatMap(scriptsCalledBy))].filter((other) => other !== name)
|
|
const isAlias = segments.length === 1 && called.length === 1
|
|
return called.length > 0 && !isAlias ? `${name} -> ${called.join(', ')}` : null
|
|
})
|
|
.filter(Boolean)
|
|
|
|
const orphans = Object.entries(scripts)
|
|
.filter(([name, command]) => command.startsWith('maybe-turbo') && !local[name] && !root[name])
|
|
.map(([name]) => name)
|
|
|
|
const header = ['task', 'defined in', 'maybe-turbo', 'cached', 'status', 'same-package deps']
|
|
const widths = header.map((_, i) => Math.max(...[header, ...rows].map((row) => row[i].length)))
|
|
for (const row of [header, ...rows])
|
|
console.log(row.map((cell, i) => cell.padEnd(widths[i])).join(' '))
|
|
|
|
if (hooks.length > 0) console.log(`\npre/post hooks to migrate: ${hooks.join(', ')}`)
|
|
if (chains.length > 0) console.log(`\nscripts that call other scripts:\n ${chains.join('\n ')}`)
|
|
if (orphans.length > 0)
|
|
console.log(`\nmaybe-turbo scripts with no turbo task: ${orphans.join(', ')}`)
|