Repository navigation
fix(@angular/cli): also clean the worktree-local cache in a git worktree #34600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+135
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
packages/angular/cli/src/commands/cache/clean/cli_spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import type { workspaces } from '@angular-devkit/core'; | ||
| import assert from 'node:assert'; | ||
| import { existsSync } from 'node:fs'; | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { join } from 'node:path'; | ||
| import type { CommandContext } from '../../../command-builder/command-module'; | ||
| import type { AngularWorkspace } from '../../../utilities/config'; | ||
| import { CacheCleanModule } from './cli'; | ||
|
|
||
| describe('CacheCleanModule', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| const baseTmpDir = process.env['TEST_TMPDIR']; | ||
| assert(baseTmpDir, 'TEST_TMPDIR is not set'); | ||
| tempDir = await mkdtemp(join(baseTmpDir, 'angular-cli-cache-clean-spec-')); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function runClean(basePath: string, cliExtension?: unknown): Promise<void> { | ||
| const workspace = { | ||
| basePath, | ||
| extensions: cliExtension ? { cli: cliExtension } : {}, | ||
| projects: {} as unknown as workspaces.ProjectDefinitionCollection, | ||
| filePath: join(basePath, 'angular.json'), | ||
| getCli: () => cliExtension, | ||
| getProjectCli: () => undefined, | ||
| save: () => Promise.resolve(), | ||
| } as unknown as AngularWorkspace; | ||
|
|
||
| return new CacheCleanModule({ workspace } as unknown as CommandContext).run(); | ||
| } | ||
|
|
||
| it('should delete the cache of a standard repository', async () => { | ||
| const workspaceRoot = join(tempDir, 'project'); | ||
| await mkdir(join(workspaceRoot, '.git'), { recursive: true }); | ||
| await mkdir(join(workspaceRoot, '.angular/cache/app'), { recursive: true }); | ||
|
|
||
| await runClean(workspaceRoot); | ||
|
|
||
| expect(existsSync(join(workspaceRoot, '.angular/cache'))).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should delete both the shared and the worktree-local cache in a git worktree', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const mainGitDir = join(mainRepoRoot, '.git'); | ||
| const worktreeRoot = join(tempDir, 'worktree'); | ||
| const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
|
|
||
| await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| await mkdir(worktreeRoot, { recursive: true }); | ||
| await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
|
|
||
| // The shared cache lives in the main checkout, while the development server keeps | ||
| // its Vite cache in the worktree itself. | ||
| await mkdir(join(mainRepoRoot, '.angular/cache/app'), { recursive: true }); | ||
| await mkdir(join(worktreeRoot, '.angular/cache/app/dev-server/vite'), { recursive: true }); | ||
|
|
||
| await runClean(worktreeRoot); | ||
|
|
||
| expect(existsSync(join(mainRepoRoot, '.angular/cache'))).toBeFalse(); | ||
| expect(existsSync(join(worktreeRoot, '.angular/cache'))).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should succeed when cache directories do not exist', async () => { | ||
| const workspaceRoot = join(tempDir, 'project'); | ||
| await mkdir(join(workspaceRoot, '.git'), { recursive: true }); | ||
|
|
||
| await expectAsync(runClean(workspaceRoot)).toBeResolved(); | ||
| }); | ||
|
|
||
| it('should delete both the shared and the worktree-local cache with a custom relative path', async () => { | ||
| const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| const mainGitDir = join(mainRepoRoot, '.git'); | ||
| const worktreeRoot = join(tempDir, 'worktree'); | ||
| const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
|
|
||
| await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| await mkdir(worktreeRoot, { recursive: true }); | ||
| await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
|
|
||
| const customCachePath = 'custom-cache-dir'; | ||
| await mkdir(join(mainRepoRoot, customCachePath, 'app'), { recursive: true }); | ||
| await mkdir(join(worktreeRoot, customCachePath, 'app/dev-server/vite'), { recursive: true }); | ||
|
|
||
| await runClean(worktreeRoot, { cache: { path: customCachePath } }); | ||
|
|
||
| expect(existsSync(join(mainRepoRoot, customCachePath))).toBeFalse(); | ||
| expect(existsSync(join(worktreeRoot, customCachePath))).toBeFalse(); | ||
| }); | ||
| }); | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.