66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { workspaces } from '@angular-devkit/core' ;
9+ import type { workspaces } from '@angular-devkit/core' ;
1010import assert from 'node:assert' ;
1111import { existsSync } from 'node:fs' ;
1212import { mkdir , mkdtemp , rm , writeFile } from 'node:fs/promises' ;
1313import { join } from 'node:path' ;
14- import { CommandContext } from '../../../command-builder/command-module' ;
15- import { AngularWorkspace } from '../../../utilities/config' ;
14+ import type { CommandContext } from '../../../command-builder/command-module' ;
15+ import type { AngularWorkspace } from '../../../utilities/config' ;
1616import { CacheCleanModule } from './cli' ;
1717
1818describe ( 'CacheCleanModule' , ( ) => {
@@ -28,13 +28,13 @@ describe('CacheCleanModule', () => {
2828 await rm ( tempDir , { recursive : true , force : true } ) ;
2929 } ) ;
3030
31- function runClean ( basePath : string ) : Promise < void > {
31+ function runClean ( basePath : string , cliExtension ?: unknown ) : Promise < void > {
3232 const workspace = {
3333 basePath,
34- extensions : { } ,
34+ extensions : cliExtension ? { cli : cliExtension } : { } ,
3535 projects : { } as unknown as workspaces . ProjectDefinitionCollection ,
3636 filePath : join ( basePath , 'angular.json' ) ,
37- getCli : ( ) => undefined ,
37+ getCli : ( ) => cliExtension ,
3838 getProjectCli : ( ) => undefined ,
3939 save : ( ) => Promise . resolve ( ) ,
4040 } as unknown as AngularWorkspace ;
@@ -73,4 +73,32 @@ describe('CacheCleanModule', () => {
7373 expect ( existsSync ( join ( mainRepoRoot , '.angular/cache' ) ) ) . toBeFalse ( ) ;
7474 expect ( existsSync ( join ( worktreeRoot , '.angular/cache' ) ) ) . toBeFalse ( ) ;
7575 } ) ;
76+
77+ it ( 'should succeed when cache directories do not exist' , async ( ) => {
78+ const workspaceRoot = join ( tempDir , 'project' ) ;
79+ await mkdir ( join ( workspaceRoot , '.git' ) , { recursive : true } ) ;
80+
81+ await expectAsync ( runClean ( workspaceRoot ) ) . toBeResolved ( ) ;
82+ } ) ;
83+
84+ it ( 'should delete both the shared and the worktree-local cache with a custom relative path' , async ( ) => {
85+ const mainRepoRoot = join ( tempDir , 'main-repo' ) ;
86+ const mainGitDir = join ( mainRepoRoot , '.git' ) ;
87+ const worktreeRoot = join ( tempDir , 'worktree' ) ;
88+ const worktreeMetadataDir = join ( mainGitDir , 'worktrees/wt-1' ) ;
89+
90+ await mkdir ( worktreeMetadataDir , { recursive : true } ) ;
91+ await mkdir ( worktreeRoot , { recursive : true } ) ;
92+ await writeFile ( join ( worktreeRoot , '.git' ) , `gitdir: ${ worktreeMetadataDir } ` ) ;
93+ await writeFile ( join ( worktreeMetadataDir , 'commondir' ) , '../..' ) ;
94+
95+ const customCachePath = 'custom-cache-dir' ;
96+ await mkdir ( join ( mainRepoRoot , customCachePath , 'app' ) , { recursive : true } ) ;
97+ await mkdir ( join ( worktreeRoot , customCachePath , 'app/dev-server/vite' ) , { recursive : true } ) ;
98+
99+ await runClean ( worktreeRoot , { cache : { path : customCachePath } } ) ;
100+
101+ expect ( existsSync ( join ( mainRepoRoot , customCachePath ) ) ) . toBeFalse ( ) ;
102+ expect ( existsSync ( join ( worktreeRoot , customCachePath ) ) ) . toBeFalse ( ) ;
103+ } ) ;
76104} ) ;
0 commit comments