next.js
7984e4ab - turbopack-cli: add --persistent-caching flag for filesystem-backed cache (#91657)

Commit
42 days ago
turbopack-cli: add --persistent-caching flag for filesystem-backed cache (#91657) ### What? Adds `--persistent-caching` and `--cache-dir` CLI flags to `turbopack dev` and `turbopack build` in the standalone `turbopack-cli` crate. ### Why? The standalone `turbopack-cli` binary (used independently of `next`) had no way to opt into the filesystem-backed persistent cache that the `next-napi-bindings` integration already supports. Without this, repeated builds always start cold — every incremental run re-computes the full task graph from scratch. ### How? **`build.rs` (new):** A Cargo build script that uses `vergen-gitcl` to emit `VERGEN_GIT_DESCRIBE` and `VERGEN_GIT_DIRTY` as compile-time env vars. These are used to key the cache by git version, matching the same approach as `next-napi-bindings`. The build script embeds the dirty state at compile time rather than runtime to avoid a git subprocess on every startup. The dirty-state caching tradeoff (explained in the build script comment): there's a narrow edge case where the tree becomes newly dirty without triggering a Cargo rebuild, but in practice this is safe — if nothing in the crate changed, the binary is semantically equivalent to a clean build, so using the HEAD hash as the cache key is correct. **`arguments.rs`:** Two new flags on `CommonArguments` (shared by both `dev` and `build` subcommands): - `--persistent-caching` — opt-in flag to enable the filesystem cache - `--cache-dir <PATH>` — override the cache directory (defaults to `.turbopack/cache` in the project root) **`dev/mod.rs` and `build/mod.rs`:** - The `Backend` type alias changes from `TurboTasksBackend<NoopBackingStorage>` to `TurboTasksBackend<Either<TurboBackingStorage, NoopBackingStorage>>` to unify the type without dynamic dispatch. - When `--persistent-caching` is set: initializes `TurboBackingStorage` via `turbo_backing_storage()`, selects `StorageMode::ReadWriteOnShutdown` for CI/short sessions and `StorageMode::ReadWrite` for interactive dev, and prints a warning if the cache was invalidated on startup. - When not set: falls back to `noop_backing_storage()` — identical behavior to before. - Respects the `TURBO_ENGINE_READ_ONLY` env var to force read-only mode. --------- Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Author
Parents
Loading