fix(@angular/build): keep dev-server Vite cache worktree-local - #33976
Open
clydin wants to merge 1 commit into
Open
fix(@angular/build): keep dev-server Vite cache worktree-local#33976clydin wants to merge 1 commit into
clydin wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces workspace-local cache options (localPath and localBasePath) to support environments like Git worktrees where the cache should resolve relative to the current worktree root rather than the main repository root. It updates the build watcher, Vite dev server, cache normalization, and cache purging logic to handle these new local paths. A critical bug was identified in the cache purging logic (purge-cache.ts) where an undefined localPath could fall back to path, leading to the accidental deletion of the active local cache directory. A fix was suggested to skip purging if currentPath is not defined.
When running within a Git worktree, the persistent build cache is shared across worktrees by resolving relative to the common Git directory (main repository root). While this works for location-agnostic compilation caches (such as `ng build`'s SourceFileCache), it breaks `ng serve` when server-side rendering (SSR) is enabled. In SSR mode, Vite prebundles dependencies into `deps_ssr/`. Any external or unbundled dependencies inside those prebundles contain bare imports (e.g., `firebase-admin/data-connect`). Because Node.js resolves bare imports relative to the prebundled file's location, placing `cacheDir` under the main repository root causes Node.js to resolve imports against the main repository's `node_modules` instead of the worktree's `node_modules`, resulting in `Cannot find module` errors and HTTP 500 responses. To resolve this, `NormalizedCachedOptions` now exposes `localBasePath` and `localPath` which always resolve relative to the active workspace root. The dev-server's Vite configuration now uses `localPath` for `cacheDir`, ensuring prebundles remain within the worktree hierarchy where Node.js can resolve the worktree's dependencies. Additionally, cache purging and watcher ignore lists are updated to handle both shared and local cache paths when they diverge. Fixes angular#33968
clydin
force-pushed
the
fix-worktree-dev-server-cache
branch
from
August 31, 2026 14:29
28af968 to
35af069
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When running within a Git worktree, the persistent build cache is shared across worktrees by resolving relative to the common Git directory (main repository root). While this works for location-agnostic compilation caches (such as
ng build's SourceFileCache), it breaksng servewhen server-side rendering (SSR) is enabled.In SSR mode, Vite prebundles dependencies into
deps_ssr/. Any external or unbundled dependencies inside those prebundles contain bare imports (e.g.,firebase-admin/data-connect). Because Node.js resolves bare imports relative to the prebundled file's location, placingcacheDirunder the main repository root causes Node.js to resolve imports against the main repository'snode_modulesinstead of the worktree'snode_modules, resulting inCannot find moduleerrors and HTTP 500 responses.To resolve this,
NormalizedCachedOptionsnow exposeslocalBasePathandlocalPathwhich always resolve relative to the active workspace root. The dev-server's Vite configuration now useslocalPathforcacheDir, ensuring prebundles remain within the worktree hierarchy where Node.js can resolve the worktree's dependencies. Additionally, cache purging and watcher ignore lists are updated to handle both shared and local cache paths when they diverge.Fixes #33968