Skip to content

fix(@angular/cli): also clean the worktree-local cache in a git worktree - #34600

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
thekhegay:fix-cache-clean-worktree
Oct 30, 2026
Merged

alan-agius4 merged 2 commits into
angular:mainfrom
thekhegay:fix-cache-clean-worktree

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

In git worktree ng cache clean removes 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 only

So in worktree it wipes cache of main checkout and leaves .angular/cache/<version>/<project>/dev-server/vite/deps of worktree, the stale prebundles it is usually run for. Repro on 22.3.0-next.3: git worktree add, ng serve and one page request in worktree, then ng cache clean, main checkout cache is gone and vite/deps in worktree is still there

What is the new behavior?

getCacheConfig also returns localPath, resolved against workspace same way as localBasePath in normalizeCacheOptions, and ng cache clean removes both. Outside of worktree both are same path, so nothing changes there

New clean/cli_spec.ts covers standard repo and worktree, worktree case fails on main

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

ng cache info still shows only shared path, left it as is

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Concurrent deletion: Use Promise.all in clean/cli.ts so deletions run concurrently and a failure in deleting the shared checkout cache doesn't block the worktree-local cache deletion.
  2. Type-only imports: Use import type in cli_spec.ts for type annotations.
  3. Test coverage: Add tests for custom cache.path and missing cache directories (idempotency) in cli_spec.ts, and assert localPath in the nested workspace and submodule tests in utilities_spec.ts.

@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Oct 30, 2026
@thekhegay

Copy link
Copy Markdown
Contributor Author

thanks, all done in 74f6ef1: Promise.all in clean, type-only imports, custom path and missing cache tests in cli_spec.ts, and localPath asserts in nested, fallback and submodule cases

@thekhegay
thekhegay requested a review from alan-agius4 October 30, 2026 09:16
@alan-agius4 alan-agius4 removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Oct 30, 2026
@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Oct 30, 2026
@alan-agius4
alan-agius4 merged commit c770609 into angular:main Oct 30, 2026
40 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/cli target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants