Repository navigation
fix(@angular/build): keep dev-server Vite cache worktree-local - #33976
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
28af968 to
35af069
Compare
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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