Repository navigation
fix(@angular/cli): also clean the worktree-local cache in a git worktree - #34600
Conversation
in git worktree `path` points to shared cache in main checkout, and since angular#33976 dev-server keeps its Vite cache in worktree own `.angular/cache`, so `ng cache clean` wiped cache of main checkout and left stale Vite prebundles of worktree in place `getCacheConfig` now also returns `localPath`, resolved against workspace like `localBasePath` in @angular/build, and clean removes both. Outside of worktree they are same path
There was a problem hiding this comment.
Code Review
This pull request updates the cache cleaning command to clean both the shared cache and the worktree-local cache when running in a Git worktree. It introduces a new CacheConfig interface to track localPath and updates the cache utility functions and tests accordingly. Feedback is provided to add a safeguard preventing accidental deletion of sensitive directories (like the workspace root or .git directory) if the cache path is misconfigured.
alan-agius4
left a comment
There was a problem hiding this comment.
Thanks for addressing this! The approach is clean and correctly resolves the stale Vite cache issue in Git worktrees.
Please address the inline suggestions before merging:
- Concurrent deletion: Use
Promise.allinclean/cli.tsso deletions run concurrently and a failure in deleting the shared checkout cache doesn't block the worktree-local cache deletion. - Type-only imports: Use
import typeincli_spec.tsfor type annotations. - Test coverage: Add tests for custom
cache.pathand missing cache directories (idempotency) incli_spec.ts, and assertlocalPathin the nested workspace and submodule tests inutilities_spec.ts.
|
thanks, all done in 74f6ef1: |
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
In git worktree
ng cache cleanremoves only shared cache, which since #33519 lives in main checkout. Since #33976 dev-server keeps its Vite cache in worktree itself and purge and watcher handle both paths, but clean was left with shared one onlySo in worktree it wipes cache of main checkout and leaves
.angular/cache/<version>/<project>/dev-server/vite/depsof worktree, the stale prebundles it is usually run for. Repro on 22.3.0-next.3:git worktree add,ng serveand one page request in worktree, thenng cache clean, main checkout cache is gone andvite/depsin worktree is still thereWhat is the new behavior?
getCacheConfigalso returnslocalPath, resolved against workspace same way aslocalBasePathinnormalizeCacheOptions, andng cache cleanremoves both. Outside of worktree both are same path, so nothing changes thereNew
clean/cli_spec.tscovers standard repo and worktree, worktree case fails on mainDoes this PR introduce a breaking change?
Other information
ng cache infostill shows only shared path, left it as is