Skip to content

Commit 5d64a3e

Browse files
committed
fix(dev): cap every app's Turbopack cache, not just apps/sim
`apps/docs` is a Next app too (`next dev --port 3001`) and overrides nothing, so it uses the Next default where the dev filesystem cache is on. It already had an uncapped 1.1 GB cache here, and the root `bun run dev` (`turbo run dev`) starts it — so a teammate using the documented command was accumulating a cache nothing would ever prune. The script now resolves its target from the working directory instead of hardcoding `apps/sim`, and each app chains its own cap. Per-app rather than one sweep on purpose: a single pass would let one app's dev start delete a cache another app is holding open, which costs that session its persistence. Verified both: `apps/sim` and `apps/docs` each report and cap their own 1.1 GB cache, and both dev servers start clean (`Ready in 299ms` / `229ms`, docs serving).
1 parent 216d9bc commit 5d64a3e

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

apps/docs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"private": true,
55
"license": "Apache-2.0",
66
"scripts": {
7-
"dev": "next dev --port 3001",
7+
"dev": "bun run dev:cache:cap && next dev --port 3001",
8+
"dev:cache:cap": "bun run ../../scripts/prune-turbopack-cache.ts",
9+
"dev:cache:prune": "bun run ../../scripts/prune-turbopack-cache.ts --force",
810
"build": "fumadocs-mdx && NODE_OPTIONS='--max-old-space-size=8192' next build",
911
"start": "next start",
1012
"postinstall": "fumadocs-mdx",

scripts/prune-turbopack-cache.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ import path from 'node:path'
4646
const DEFAULT_MAX_GB = 20
4747
const BYTES_PER_GB = 1024 ** 3
4848

49-
const CACHE_DIR = path.join(
50-
import.meta.dirname,
51-
'..',
52-
'apps',
53-
'sim',
54-
'.next',
55-
'dev',
56-
'cache',
57-
'turbopack'
58-
)
49+
/**
50+
* Resolved from the working directory, not hardcoded to one app: every Next app
51+
* in the monorepo has its own dev cache (`apps/docs` runs `next dev` too and, with
52+
* no override, uses the Next default where the cache is on). Each app caps its
53+
* own, so one app's dev start never prunes a cache another app is holding open.
54+
*/
55+
const CACHE_DIR = path.resolve(process.cwd(), '.next', 'dev', 'cache', 'turbopack')
5956

6057
/** Sums the size of every regular file under `dir`, skipping symlinks. */
6158
async function directorySize(dir: string): Promise<number> {

0 commit comments

Comments
 (0)