clean-turbopack-cache.mjs21 lines · main
| 1 | import { existsSync, readdirSync, rmSync, statSync } from 'fs' |
| 2 | import { join } from 'path' |
| 3 | |
| 4 | // This script cleans up the Turbopack cache by removing files that haven't been modified in the last 3 days. This is to |
| 5 | // prevent the cache from growing indefinitely and consuming too much RAM. |
| 6 | const dir = '.next/dev/cache/turbopack' |
| 7 | const cutoff = Date.now() - 3 * 24 * 60 * 60 * 1000 // 3 days in milliseconds |
| 8 | |
| 9 | function clean(d) { |
| 10 | if (!existsSync(d)) return |
| 11 | for (const entry of readdirSync(d, { withFileTypes: true })) { |
| 12 | const p = join(d, entry.name) |
| 13 | if (entry.isDirectory()) { |
| 14 | clean(p) |
| 15 | } else if (statSync(p).mtimeMs < cutoff) { |
| 16 | rmSync(p) |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | clean(dir) |