@@ -197,4 +197,82 @@ describe('normalizeCacheOptions', () => {
197197 expect ( options . localBasePath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' ) ) ;
198198 expect ( options . localPath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' , '0.0.0-PLACEHOLDER' ) ) ;
199199 } ) ;
200+
201+ it ( 'should scope path and localPath to projectName when provided' , async ( ) => {
202+ const workspaceRoot = join ( tempDir , 'project' ) ;
203+ await mkdir ( join ( workspaceRoot , '.git' ) , { recursive : true } ) ;
204+
205+ const options = normalizeCacheOptions ( { } , workspaceRoot , 'my-app' ) ;
206+
207+ expect ( options . basePath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' ) ) ;
208+ expect ( options . path ) . toBe ( resolve ( workspaceRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app' ) ) ;
209+ expect ( options . localBasePath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' ) ) ;
210+ expect ( options . localPath ) . toBe (
211+ resolve ( workspaceRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app' ) ,
212+ ) ;
213+ } ) ;
214+
215+ it ( 'should scope path and localPath to projectName in a git worktree' , async ( ) => {
216+ const mainRepoRoot = join ( tempDir , 'main-repo' ) ;
217+ const mainGitDir = join ( mainRepoRoot , '.git' ) ;
218+ const worktreeRoot = join ( tempDir , 'worktree' ) ;
219+
220+ await mkdir ( mainGitDir , { recursive : true } ) ;
221+
222+ const worktreeMetadataDir = join ( mainGitDir , 'worktrees/wt-1' ) ;
223+ await mkdir ( worktreeMetadataDir , { recursive : true } ) ;
224+ await mkdir ( worktreeRoot , { recursive : true } ) ;
225+ await writeFile ( join ( worktreeRoot , '.git' ) , `gitdir: ${ worktreeMetadataDir } ` ) ;
226+ await writeFile ( join ( worktreeMetadataDir , 'commondir' ) , '../..' ) ;
227+
228+ const options = normalizeCacheOptions ( { } , worktreeRoot , 'my-lib' ) ;
229+
230+ expect ( options . basePath ) . toBe ( resolve ( mainRepoRoot , '.angular/cache' ) ) ;
231+ expect ( options . path ) . toBe ( resolve ( mainRepoRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-lib' ) ) ;
232+ expect ( options . localBasePath ) . toBe ( resolve ( worktreeRoot , '.angular/cache' ) ) ;
233+ expect ( options . localPath ) . toBe (
234+ resolve ( worktreeRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-lib' ) ,
235+ ) ;
236+ } ) ;
237+
238+ it ( 'should scope path and localPath to projectName and builderName when provided' , async ( ) => {
239+ const workspaceRoot = join ( tempDir , 'project' ) ;
240+ await mkdir ( join ( workspaceRoot , '.git' ) , { recursive : true } ) ;
241+
242+ const options = normalizeCacheOptions ( { } , workspaceRoot , 'my-app' , 'vite' ) ;
243+
244+ expect ( options . basePath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' ) ) ;
245+ expect ( options . path ) . toBe (
246+ resolve ( workspaceRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app/vite' ) ,
247+ ) ;
248+ expect ( options . localBasePath ) . toBe ( resolve ( workspaceRoot , '.angular/cache' ) ) ;
249+ expect ( options . localPath ) . toBe (
250+ resolve ( workspaceRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app/vite' ) ,
251+ ) ;
252+ } ) ;
253+
254+ it ( 'should scope path and localPath to projectName and builderName in a git worktree' , async ( ) => {
255+ const mainRepoRoot = join ( tempDir , 'main-repo' ) ;
256+ const mainGitDir = join ( mainRepoRoot , '.git' ) ;
257+ const worktreeRoot = join ( tempDir , 'worktree' ) ;
258+
259+ await mkdir ( mainGitDir , { recursive : true } ) ;
260+
261+ const worktreeMetadataDir = join ( mainGitDir , 'worktrees/wt-1' ) ;
262+ await mkdir ( worktreeMetadataDir , { recursive : true } ) ;
263+ await mkdir ( worktreeRoot , { recursive : true } ) ;
264+ await writeFile ( join ( worktreeRoot , '.git' ) , `gitdir: ${ worktreeMetadataDir } ` ) ;
265+ await writeFile ( join ( worktreeMetadataDir , 'commondir' ) , '../..' ) ;
266+
267+ const options = normalizeCacheOptions ( { } , worktreeRoot , 'my-app' , 'vite' ) ;
268+
269+ expect ( options . basePath ) . toBe ( resolve ( mainRepoRoot , '.angular/cache' ) ) ;
270+ expect ( options . path ) . toBe (
271+ resolve ( mainRepoRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app/vite' ) ,
272+ ) ;
273+ expect ( options . localBasePath ) . toBe ( resolve ( worktreeRoot , '.angular/cache' ) ) ;
274+ expect ( options . localPath ) . toBe (
275+ resolve ( worktreeRoot , '.angular/cache/0.0.0-PLACEHOLDER/my-app/vite' ) ,
276+ ) ;
277+ } ) ;
200278} ) ;
0 commit comments