Skill files1 file
SKILL.md372 lines
1
---
2
name: turborepo-caching
3
description: Configure Turborepo for efficient monorepo builds with local and remote caching. Use when setting up Turborepo, optimizing build pipelines, or implementing distributed caching.
4
---
5
6
# Turborepo Caching
7
8
Production patterns for Turborepo build optimization.
9
10
## When to Use This Skill
11
12
- Setting up new Turborepo projects
13
- Configuring build pipelines
14
- Implementing remote caching
15
- Optimizing CI/CD performance
16
- Migrating from other monorepo tools
17
- Debugging cache misses
18
19
## Core Concepts
20
21
### 1. Turborepo Architecture
22
23
```
24
Workspace Root/
25
├── apps/
26
│ ├── web/
27
│ │ └── package.json
28
│ └── docs/
29
│ └── package.json
30
├── packages/
31
│ ├── ui/
32
│ │ └── package.json
33
│ └── config/
34
│ └── package.json
35
├── turbo.json
36
└── package.json
37
```
38
39
### 2. Pipeline Concepts
40
41
| Concept | Description |
42
| -------------- | -------------------------------- |
43
| **dependsOn** | Tasks that must complete first |
44
| **cache** | Whether to cache outputs |
45
| **outputs** | Files to cache |
46
| **inputs** | Files that affect cache key |
47
| **persistent** | Long-running tasks (dev servers) |
48
49
## Templates
50
51
### Template 1: turbo.json Configuration
52
53
```json
54
{
55
"$schema": "https://turbo.build/schema.json",
56
"globalDependencies": [".env", ".env.local"],
57
"globalEnv": ["NODE_ENV", "VERCEL_URL"],
58
"pipeline": {
59
"build": {
60
"dependsOn": ["^build"],
61
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
62
"env": ["API_URL", "NEXT_PUBLIC_*"]
63
},
64
"test": {
65
"dependsOn": ["build"],
66
"outputs": ["coverage/**"],
67
"inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts"]
68
},
69
"lint": {
70
"outputs": [],
71
"cache": true
72
},
73
"typecheck": {
74
"dependsOn": ["^build"],
75
"outputs": []
76
},
77
"dev": {
78
"cache": false,
79
"persistent": true
80
},
81
"clean": {
82
"cache": false
83
}
84
}
85
}
86
```
87
88
### Template 2: Package-Specific Pipeline
89
90
```json
91
// apps/web/turbo.json
92
{
93
"$schema": "https://turbo.build/schema.json",
94
"extends": ["//"],
95
"pipeline": {
96
"build": {
97
"outputs": [".next/**", "!.next/cache/**"],
98
"env": ["NEXT_PUBLIC_API_URL", "NEXT_PUBLIC_ANALYTICS_ID"]
99
},
100
"test": {
101
"outputs": ["coverage/**"],
102
"inputs": ["src/**", "tests/**", "jest.config.js"]
103
}
104
}
105
}
106
```
107
108
### Template 3: Remote Caching with Vercel
109
110
```bash
111
# Login to Vercel
112
npx turbo login
113
114
# Link to Vercel project
115
npx turbo link
116
117
# Run with remote cache
118
turbo build --remote-only
119
120
# CI environment variables
121
TURBO_TOKEN=your-token
122
TURBO_TEAM=your-team
123
```
124
125
```yaml
126
# .github/workflows/ci.yml
127
name: CI
128
129
on:
130
push:
131
branches: [main]
132
pull_request:
133
134
env:
135
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
136
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
137
138
jobs:
139
build:
140
runs-on: ubuntu-latest
141
steps:
142
- uses: actions/checkout@v4
143
144
- uses: actions/setup-node@v4
145
with:
146
node-version: 20
147
cache: "npm"
148
149
- name: Install dependencies
150
run: npm ci
151
152
- name: Build
153
run: npx turbo build --filter='...[origin/main]'
154
155
- name: Test
156
run: npx turbo test --filter='...[origin/main]'
157
```
158
159
### Template 4: Self-Hosted Remote Cache
160
161
```typescript
162
// Custom remote cache server (Express)
163
import express from "express";
164
import { createReadStream, createWriteStream } from "fs";
165
import { mkdir } from "fs/promises";
166
import { join } from "path";
167
168
const app = express();
169
const CACHE_DIR = "./cache";
170
171
// Get artifact
172
app.get("/v8/artifacts/:hash", async (req, res) => {
173
const { hash } = req.params;
174
const team = req.query.teamId || "default";
175
const filePath = join(CACHE_DIR, team, hash);
176
177
try {
178
const stream = createReadStream(filePath);
179
stream.pipe(res);
180
} catch {
181
res.status(404).send("Not found");
182
}
183
});
184
185
// Put artifact
186
app.put("/v8/artifacts/:hash", async (req, res) => {
187
const { hash } = req.params;
188
const team = req.query.teamId || "default";
189
const dir = join(CACHE_DIR, team);
190
const filePath = join(dir, hash);
191
192
await mkdir(dir, { recursive: true });
193
194
const stream = createWriteStream(filePath);
195
req.pipe(stream);
196
197
stream.on("finish", () => {
198
res.json({
199
urls: [`${req.protocol}://${req.get("host")}/v8/artifacts/${hash}`],
200
});
201
});
202
});
203
204
// Check artifact exists
205
app.head("/v8/artifacts/:hash", async (req, res) => {
206
const { hash } = req.params;
207
const team = req.query.teamId || "default";
208
const filePath = join(CACHE_DIR, team, hash);
209
210
try {
211
await fs.access(filePath);
212
res.status(200).end();
213
} catch {
214
res.status(404).end();
215
}
216
});
217
218
app.listen(3000, "127.0.0.1");
219
```
220
221
```json
222
// turbo.json for the local cache demo
223
{
224
"remoteCache": {
225
"signature": false
226
}
227
}
228
```
229
230
```bash
231
# This local demo does not authenticate the dummy token.
232
# Use only disposable artifacts on a trusted machine; do not expose the server.
233
turbo build --api="http://127.0.0.1:3000" --token="my-token" --team="my-team"
234
```
235
236
### Template 5: Filtering and Scoping
237
238
```bash
239
# Build specific package
240
turbo build --filter=@myorg/web
241
242
# Build package and its dependencies
243
turbo build --filter=@myorg/web...
244
245
# Build package and its dependents
246
turbo build --filter=...@myorg/ui
247
248
# Build changed packages since main
249
turbo build --filter='...[origin/main]'
250
251
# Build packages in directory
252
turbo build --filter='./apps/*'
253
254
# Combine filters
255
turbo build --filter=@myorg/web --filter=@myorg/docs
256
257
# Exclude package
258
turbo build --filter='!@myorg/docs'
259
260
# Include dependencies of changed
261
turbo build --filter='...[HEAD^1]...'
262
```
263
264
### Template 6: Advanced Pipeline Configuration
265
266
```json
267
{
268
"$schema": "https://turbo.build/schema.json",
269
"pipeline": {
270
"build": {
271
"dependsOn": ["^build"],
272
"outputs": ["dist/**"],
273
"inputs": ["$TURBO_DEFAULT$", "!**/*.md", "!**/*.test.*"]
274
},
275
"test": {
276
"dependsOn": ["^build"],
277
"outputs": ["coverage/**"],
278
"inputs": ["src/**", "tests/**", "*.config.*"],
279
"env": ["CI", "NODE_ENV"]
280
},
281
"test:e2e": {
282
"dependsOn": ["build"],
283
"outputs": [],
284
"cache": false
285
},
286
"deploy": {
287
"dependsOn": ["build", "test", "lint"],
288
"outputs": [],
289
"cache": false
290
},
291
"db:generate": {
292
"cache": false
293
},
294
"db:push": {
295
"cache": false,
296
"dependsOn": ["db:generate"]
297
},
298
"@myorg/web#build": {
299
"dependsOn": ["^build", "@myorg/db#db:generate"],
300
"outputs": [".next/**"],
301
"env": ["NEXT_PUBLIC_*"]
302
}
303
}
304
}
305
```
306
307
### Template 7: Root package.json Setup
308
309
```json
310
{
311
"name": "my-turborepo",
312
"private": true,
313
"workspaces": ["apps/*", "packages/*"],
314
"scripts": {
315
"build": "turbo build",
316
"dev": "turbo dev",
317
"lint": "turbo lint",
318
"test": "turbo test",
319
"clean": "turbo clean && rm -rf node_modules",
320
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
321
"changeset": "changeset",
322
"version-packages": "changeset version",
323
"release": "turbo build --filter=./packages/* && changeset publish"
324
},
325
"devDependencies": {
326
"turbo": "^1.10.0",
327
"prettier": "^3.0.0",
328
"@changesets/cli": "^2.26.0"
329
},
330
"packageManager": "npm@10.0.0"
331
}
332
```
333
334
## Debugging Cache
335
336
```bash
337
# Dry run to see what would run
338
turbo build --dry-run
339
340
# Verbose output with hashes
341
turbo build --verbosity=2
342
343
# Show task graph
344
turbo build --graph
345
346
# Force no cache
347
turbo build --force
348
349
# Show cache status
350
turbo build --summarize
351
352
# Debug specific task
353
TURBO_LOG_VERBOSITY=debug turbo build --filter=@myorg/web
354
```
355
356
## Best Practices
357
358
### Do's
359
360
- **Define explicit inputs** - Avoid cache invalidation
361
- **Use workspace protocol** - `"@myorg/ui": "workspace:*"`
362
- **Enable remote caching** - Share across CI and local
363
- **Filter in CI** - Build only affected packages
364
- **Cache build outputs** - Not source files
365
366
### Don'ts
367
368
- **Don't cache dev servers** - Use `persistent: true`
369
- **Don't include secrets in env** - Use runtime env vars
370
- **Don't ignore dependsOn** - Causes race conditions
371
- **Don't over-filter** - May miss dependencies
372

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…