brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
turborepoTurborepo high-performance monorepo build system. Intelligent caching and task orchestration. Use when managing monorepos with complex build dependencies. USE WHEN: user mentions "Turborepo", "turbo.json", "turbo build", asks about "monorepo caching", "Turbo configuration", "remote cache" DO NOT USE FOR: Nx monorepos (use nx skill), single-package project…
Independent GitHub snapshot · Automated classification · Original documentation governs
name: turborepo description: | Turborepo high-performance monorepo build system. Intelligent caching and task orchestration. Use when managing monorepos with complex build dependencies.
USE WHEN: user mentions "Turborepo", "turbo.json", "turbo build", asks about "monorepo caching", "Turbo configuration", "remote cache"
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:turborepofor comprehensive documentation.
nx skill for Nx-specific features# New monorepo
npx create-turbo@latest my-monorepo
# Add to existing monorepo
npm install turbo --save-dev
my-monorepo/
├── turbo.json
├── package.json
├── apps/
│ ├── web/
│ │ └── package.json
│ └── api/
│ └── package.json
└── packages/
├── ui/
│ └── package.json
├── config/
│ └── package.json
└── utils/
└── package.json
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "build/**"]
},
"dev": {
"cache": false,
"persistent": true
},
"lint": {
"dependsOn": ["^build"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
},
"typecheck": {
"dependsOn": ["^build"]
}
}
}
{
"tasks": {
"build": {
// Run dependencies' build first
"dependsOn": ["^build"],
// Files that affect cache
"inputs": [
"src/**",
"package.json",
"tsconfig.json"
],
// Outputs to cache
"outputs": ["dist/**"],
// Environment variables that affect cache
"env": ["NODE_ENV", "API_URL"],
// Pass-through env vars (not cached)
"passThroughEnv": ["CI", "GITHUB_TOKEN"]
},
"dev": {
// Don't cache dev tasks
"cache": false,
// Keep running (watch mode)
"persistent": true
},
"deploy": {
// Run after build
"dependsOn": ["build"],
// No outputs
"outputs": []
}
}
}
# Run task in all packages
turbo build
turbo lint
turbo test
# Run in specific package
turbo build --filter=@myorg/web
turbo build --filter=web
# Run in multiple packages
turbo build --filter=@myorg/web --filter=@myorg/api
# Run with dependencies
turbo build --filter=@myorg/web... # web + its dependencies
turbo build --filter=...@myorg/ui # ui + its dependents
# Since git ref
turbo build --filter=[HEAD^1] # Changed since last commit
turbo build --filter=[origin/main] # Changed since main
# Parallel execution
turbo dev
# Dry run
turbo build --dry-run
turbo build --graph # Output dependency graph
// apps/web/package.json
{
"name": "@myorg/web",
"scripts": {
"build": "next build",
"dev": "next dev",
"lint": "eslint .",
"test": "vitest run"
},
"dependencies": {
"@myorg/ui": "*",
"@myorg/utils": "*"
}
}
// packages/ui/package.json
{
"name": "@myorg/ui",
"scripts": {
"build": "tsup src/index.ts --dts",
"dev": "tsup src/index.ts --watch",
"lint": "eslint ."
}
}
{
"name": "my-monorepo",
"private": true,
"workspaces": ["apps/*", "packages/*"],
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"test": "turbo test",
"typecheck": "turbo typecheck",
"clean": "turbo clean && rm -rf node_modules"
},
"devDependencies": {
"turbo": "^2.0.0"
}
}
# Cache stored in node_modules/.cache/turbo
# Force fresh build
turbo build --force
# View cache status
turbo build --summarize
# Login to Vercel
turbo login
# Link to remote cache
turbo link
# Now builds use remote cache
turbo build
// turbo.json
{
"remoteCache": {
"enabled": true,
"signature": true
}
}
# Use custom remote cache
TURBO_API="https://your-cache-server.com" \
TURBO_TOKEN="your-token" \
TURBO_TEAM="your-team" \
turbo build
// turbo.json
{
"globalEnv": ["CI", "NODE_ENV"],
"globalPassThroughEnv": ["GITHUB_TOKEN"],
"tasks": {
"build": {
"env": ["API_URL", "DATABASE_URL"],
"passThroughEnv": ["VERCEL_URL"]
}
}
}
// turbo.json
{
"globalDotEnv": [".env"],
"tasks": {
"build": {
"dotEnv": [".env.production", ".env.local"]
}
}
}
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Needed for --filter=[HEAD^1]
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install
run: npm ci
- name: Build
run: npx turbo build --filter=[HEAD^1]
- name: Test
run: npx turbo test --filter=[HEAD^1]
- name: Lint
run: npx turbo lint --filter=[HEAD^1]
- name: Build
run: npx turbo build
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
// apps/web/turbo.json
{
"extends": ["//"],
"tasks": {
"build": {
"outputs": [".next/**", "!.next/cache/**"]
}
}
}
# Create generator
turbo gen init
# Run generator
turbo gen workspace
// turbo/generators/config.ts
import { PlopTypes } from "@turbo/gen";
export default function generator(plop: PlopTypes.NodePlopAPI): void {
plop.setGenerator("package", {
description: "Create a new package",
prompts: [
{
type: "input",
name: "name",
message: "Package name?",
},
],
actions: [
{
type: "add",
path: "packages/{{name}}/package.json",
templateFile: "templates/package.json.hbs",
},
],
});
}
{
"tasks": {
// topological: run in dependencies first
"build": {
"dependsOn": ["^build"]
},
// same package: run after
"test": {
"dependsOn": ["build"]
},
// specific package
"deploy": {
"dependsOn": ["@myorg/web#build", "@myorg/api#build"]
},
// no dependencies
"lint": {
"dependsOn": []
}
}
}
# Verbose output
turbo build --verbosity=2
# Dry run
turbo build --dry-run=json
# Graph visualization
turbo build --graph=graph.html
# Summarize
turbo build --summarize
# Profile
turbo build --profile=profile.json
| Feature | Turborepo | Nx |
|---|---|---|
| Setup | Simple | Complex |
| Config | JSON | TypeScript |
| Caching | Excellent | Excellent |
| Task runner | Fast | Fast |
| Generators | Basic | Advanced |
| Plugins | Limited | Extensive |
| Learning curve | Low | Medium |
| Vercel integration | Native | Manual |
| Scenario | Recommendation |
|---|---|
| Simple monorepo | Turborepo |
| Complex enterprise | Nx |
| Vercel deployment | Turborepo |
| Need generators | Nx |
| Quick setup | Turborepo |
--filter for incremental buildsoutputs configuration* in workspace dependencies (use workspace protocol)| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Not using --filter | Rebuilds everything | Use --filter for affected packages |
| Caching side effects | Unreliable deployments | Set cache: false for deploy tasks |
| Missing outputs | Cache doesn't work | Declare all output directories |
| Using * for workspace deps | Version conflicts | Use workspace:* protocol |
| No remote cache in CI | Slow CI builds | Setup Vercel or self-hosted cache |
| Forgetting env in turbo.json | Cache misses | Declare env vars that affect output |
| Issue | Cause | Solution |
|---|---|---|
| Cache always misses | Missing outputs | Add outputs to turbo.json task |
| Task runs when shouldn't | Wrong dependsOn | Check ^build syntax for dependencies |
| Slow builds | Not using cache | Enable remote cache or check outputs |
| Wrong execution order | Missing dependsOn | Add dependsOn: ["^build"] |
| Env vars not working | Not declared | Add to env or passThroughEnv |
| Remote cache not working | Auth issue | Check TURBO_TOKEN and TURBO_TEAM |
^build for topological dependenciesFor advanced configurations:
mcp__documentation__fetch_docs
- Technology:
turborepo- Turborepo Docs