From 24fcf98d4970e0808e630516e02729535a789472 Mon Sep 17 00:00:00 2001 From: MeAkib Date: Wed, 4 Nov 2026 15:50:46 +0600 Subject: [PATCH 1/2] fix(@angular/cli): report the worktree-local cache in `ng cache info` In a Git worktree the development server keeps its Vite cache in the worktree's own cache directory while the configured path resolves to the shared cache of the main checkout. `ng cache clean` removes both since the `getCacheConfig` localPath addition, but `ng cache info` still reports only the shared path and its size, so the cache that the development server actually writes to in that checkout is invisible. Print the local path and its size when it differs from the shared path. Outside of a worktree both paths are the same and the output is unchanged. Tested with a unit spec that reproduces the worktree layout; the spec fails without the fix. --- .../cli/src/commands/cache/info/cli.ts | 29 +++++-- .../cli/src/commands/cache/info/cli_spec.ts | 83 +++++++++++++++++++ 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 packages/angular/cli/src/commands/cache/info/cli_spec.ts diff --git a/packages/angular/cli/src/commands/cache/info/cli.ts b/packages/angular/cli/src/commands/cache/info/cli.ts index 6fd2df0414c7..82f1289e5a81 100644 --- a/packages/angular/cli/src/commands/cache/info/cli.ts +++ b/packages/angular/cli/src/commands/cache/info/cli.ts @@ -29,7 +29,7 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu async run(): Promise { const cacheConfig = getCacheConfig(this.context.workspace); - const { path, environment, enabled } = cacheConfig; + const { path, localPath, environment, enabled } = cacheConfig; const effectiveStatus = this.effectiveEnabledStatus(cacheConfig); const sizeOnDisk = await this.getSizeOfDirectory(path); @@ -51,14 +51,29 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu label: 'Size on disk', value: colors.cyan(sizeOnDisk), }, - { - label: 'Effective Status', - value: - (effectiveStatus ? colors.green('Enabled') : colors.red('Disabled')) + - ' (current machine)', - }, ]; + // In a Git worktree, `path` is shared with the main checkout while `localPath` holds the + // development server's Vite cache. Both are the same path outside of a worktree. + if (localPath !== path) { + info.push( + { + label: 'Local path', + value: colors.cyan(localPath), + }, + { + label: 'Local size on disk', + value: colors.cyan(await this.getSizeOfDirectory(localPath)), + }, + ); + } + + info.push({ + label: 'Effective Status', + value: + (effectiveStatus ? colors.green('Enabled') : colors.red('Disabled')) + ' (current machine)', + }); + const maxLabelLength = Math.max(...info.map((l) => l.label.length)); const output = info diff --git a/packages/angular/cli/src/commands/cache/info/cli_spec.ts b/packages/angular/cli/src/commands/cache/info/cli_spec.ts new file mode 100644 index 000000000000..5a0eb1451109 --- /dev/null +++ b/packages/angular/cli/src/commands/cache/info/cli_spec.ts @@ -0,0 +1,83 @@ +/** + * @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 { 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 { CacheInfoCommandModule } from './cli'; + +describe('CacheInfoCommandModule', () => { + 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-info-spec-')); + }); + + afterEach(async () => { + await rm(tempDir, { recursive: true, force: true }); + }); + + async function runInfo(basePath: string): Promise { + const workspace = { + basePath, + extensions: {}, + projects: {} as unknown as workspaces.ProjectDefinitionCollection, + filePath: join(basePath, 'angular.json'), + getCli: () => undefined, + getProjectCli: () => undefined, + save: () => Promise.resolve(), + } as unknown as AngularWorkspace; + + const logs: string[] = []; + const logger = { info: (message: string) => void logs.push(message) }; + + await new CacheInfoCommandModule({ workspace, logger } as unknown as CommandContext).run(); + + return logs.join('\n'); + } + + it('should print only the shared cache path in 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 }); + + const output = await runInfo(workspaceRoot); + + expect(output).toContain(join(workspaceRoot, '.angular/cache')); + expect(output).not.toContain('Local path'); + }); + + it('should also print 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 }); + + const output = await runInfo(worktreeRoot); + + expect(output).toContain(join(mainRepoRoot, '.angular/cache')); + expect(output).toContain('Local path'); + expect(output).toContain(join(worktreeRoot, '.angular/cache')); + expect(output).toContain('Local size on disk'); + }); +}); From dd4a9c321c408c4f825f70adcf1b53a7a59603bd Mon Sep 17 00:00:00 2001 From: MeAkib Date: Thu, 5 Nov 2026 00:12:07 +0600 Subject: [PATCH 2/2] fixup! fix(@angular/cli): report the worktree-local cache in `ng cache info` --- .../angular/cli/src/commands/cache/info/cli.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/angular/cli/src/commands/cache/info/cli.ts b/packages/angular/cli/src/commands/cache/info/cli.ts index 82f1289e5a81..e767eefe637b 100644 --- a/packages/angular/cli/src/commands/cache/info/cli.ts +++ b/packages/angular/cli/src/commands/cache/info/cli.ts @@ -32,7 +32,13 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu const { path, localPath, environment, enabled } = cacheConfig; const effectiveStatus = this.effectiveEnabledStatus(cacheConfig); - const sizeOnDisk = await this.getSizeOfDirectory(path); + + // In a Git worktree, `path` is shared with the main checkout while `localPath` holds the + // development server's Vite cache. Both are the same path outside of a worktree. + const [sizeOnDisk, localSizeOnDisk] = await Promise.all([ + this.getSizeOfDirectory(path), + localPath !== path ? this.getSizeOfDirectory(localPath) : undefined, + ]); const info: { label: string; value: string }[] = [ { @@ -53,9 +59,7 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu }, ]; - // In a Git worktree, `path` is shared with the main checkout while `localPath` holds the - // development server's Vite cache. Both are the same path outside of a worktree. - if (localPath !== path) { + if (localSizeOnDisk !== undefined) { info.push( { label: 'Local path', @@ -63,7 +67,7 @@ export class CacheInfoCommandModule extends CommandModule implements CommandModu }, { label: 'Local size on disk', - value: colors.cyan(await this.getSizeOfDirectory(localPath)), + value: colors.cyan(localSizeOnDisk), }, ); }