| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d12414d commit b198044
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | 9 | import { existsSync, readFileSync, statSync } from 'node:fs'; | |
| 10 | - import { dirname, isAbsolute, join, resolve } from 'node:path'; | ||
| 10 | + import { dirname, isAbsolute, join, relative, resolve } from 'node:path'; | ||
| 11 | 11 | ||
| 12 | 12 | /** Version placeholder is replaced during the build process with actual package version */ | |
| 13 | 13 | const VERSION = '0.0.0-PLACEHOLDER'; | |
@@ -75,11 +75,16 @@ function getCacheBasePath(workspaceRoot: string, cachePathSetting: string): stri | |||
| 75 | 75 | // It's a git worktree | |
| 76 | 76 | const commondir = readFileSync(commondirPath, 'utf8').trim(); | |
| 77 | 77 | const commonGitDir = resolve(gitdir, commondir); | |
| 78 | - | ||
| 79 | - return resolve(dirname(commonGitDir), cachePathSetting); | ||
| 78 | + const relativeWorkspacePath = relative(currentDir, workspaceRoot); | ||
| 79 | + const mainWorkspaceRoot = resolve(dirname(commonGitDir), relativeWorkspacePath); | ||
| 80 | + if (existsSync(mainWorkspaceRoot)) { | ||
| 81 | + return resolve(mainWorkspaceRoot, cachePathSetting); | ||
| 82 | + } | ||
| 80 | 83 | } | |
| 81 | 84 | } | |
| 82 | 85 | } | |
| 86 | + | ||
| 87 | + break; | ||
| 83 | 88 | } | |
| 84 | 89 | const parentDir = dirname(currentDir); | |
| 85 | 90 | if (parentDir === currentDir) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,16 +6,18 @@ | |||
| 6 | 6 | * found in the LICENSE file at https://angular.dev/license | |
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | + import assert from 'node:assert'; | ||
| 9 | 10 | import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | |
| 10 | - import { tmpdir } from 'node:os'; | ||
| 11 | 11 | import { join, resolve } from 'node:path'; | |
| 12 | 12 | import { normalizeCacheOptions } from './normalize-cache'; | |
| 13 | 13 | ||
| 14 | 14 | describe('normalizeCacheOptions', () => { | |
| 15 | 15 | let tempDir: string; | |
| 16 | 16 | ||
| 17 | 17 | beforeEach(async () => { | |
| 18 | - tempDir = await mkdtemp(join(tmpdir(), 'angular-cache-spec-')); | ||
| 18 | + const baseTmpDir = process.env['TEST_TMPDIR']; | ||
| 19 | + assert(baseTmpDir, 'TEST_TMPDIR is not set'); | ||
| 20 | + tempDir = await mkdtemp(join(baseTmpDir, 'angular-cache-spec-')); | ||
| 19 | 21 | }); | |
| 20 | 22 | ||
| 21 | 23 | afterEach(async () => { | |
@@ -58,6 +60,64 @@ describe('normalizeCacheOptions', () => { | |||
| 58 | 60 | expect(options.localPath).toBe(resolve(worktreeRoot, '.angular/cache', '0.0.0-PLACEHOLDER')); | |
| 59 | 61 | }); | |
| 60 | 62 | ||
| 63 | + it('should resolve cache path relative to corresponding nested workspace in main repository for a git worktree', async () => { | ||
| 64 | + const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| 65 | + const mainGitDir = join(mainRepoRoot, '.git'); | ||
| 66 | + const mainWorkspaceRoot = join(mainRepoRoot, 'Site1/ClientApp'); | ||
| 67 | + const worktreeRoot = join(tempDir, 'worktree'); | ||
| 68 | + const worktreeWorkspaceRoot = join(worktreeRoot, 'Site1/ClientApp'); | ||
| 69 | + | ||
| 70 | + // Create main repo with a nested Angular workspace directory | ||
| 71 | + await mkdir(mainGitDir, { recursive: true }); | ||
| 72 | + await mkdir(mainWorkspaceRoot, { recursive: true }); | ||
| 73 | + | ||
| 74 | + // Create worktree with the same nested Angular workspace structure and a .git file at the worktree root | ||
| 75 | + const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| 76 | + await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| 77 | + await mkdir(worktreeWorkspaceRoot, { recursive: true }); | ||
| 78 | + await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| 79 | + | ||
| 80 | + // Point the worktree metadata back to the main .git directory | ||
| 81 | + await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
| 82 | + | ||
| 83 | + const options = normalizeCacheOptions({}, worktreeWorkspaceRoot); | ||
| 84 | + | ||
| 85 | + expect(options.basePath).toBe(resolve(mainWorkspaceRoot, '.angular/cache')); | ||
| 86 | + expect(options.path).toBe(resolve(mainWorkspaceRoot, '.angular/cache', '0.0.0-PLACEHOLDER')); | ||
| 87 | + expect(options.localBasePath).toBe(resolve(worktreeWorkspaceRoot, '.angular/cache')); | ||
| 88 | + expect(options.localPath).toBe( | ||
| 89 | + resolve(worktreeWorkspaceRoot, '.angular/cache', '0.0.0-PLACEHOLDER'), | ||
| 90 | + ); | ||
| 91 | + }); | ||
| 92 | + | ||
| 93 | + it('should fall back to worktree workspace root when nested workspace does not exist in main repository', async () => { | ||
| 94 | + const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| 95 | + const mainGitDir = join(mainRepoRoot, '.git'); | ||
| 96 | + const worktreeRoot = join(tempDir, 'worktree'); | ||
| 97 | + const worktreeWorkspaceRoot = join(worktreeRoot, 'NewSite/ClientApp'); | ||
| 98 | + | ||
| 99 | + // Create main repo without the 'NewSite/ClientApp' subdirectory (e.g., added only on the worktree branch) | ||
| 100 | + await mkdir(mainGitDir, { recursive: true }); | ||
| 101 | + | ||
| 102 | + // Create worktree with the new nested Angular workspace and link it to the main repo's .git directory | ||
| 103 | + const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| 104 | + await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| 105 | + await mkdir(worktreeWorkspaceRoot, { recursive: true }); | ||
| 106 | + await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| 107 | + await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
| 108 | + | ||
| 109 | + const options = normalizeCacheOptions({}, worktreeWorkspaceRoot); | ||
| 110 | + | ||
| 111 | + expect(options.basePath).toBe(resolve(worktreeWorkspaceRoot, '.angular/cache')); | ||
| 112 | + expect(options.path).toBe( | ||
| 113 | + resolve(worktreeWorkspaceRoot, '.angular/cache', '0.0.0-PLACEHOLDER'), | ||
| 114 | + ); | ||
| 115 | + expect(options.localBasePath).toBe(resolve(worktreeWorkspaceRoot, '.angular/cache')); | ||
| 116 | + expect(options.localPath).toBe( | ||
| 117 | + resolve(worktreeWorkspaceRoot, '.angular/cache', '0.0.0-PLACEHOLDER'), | ||
| 118 | + ); | ||
| 119 | + }); | ||
| 120 | + | ||
| 61 | 121 | it('should resolve local cache path relative to worktree root with custom relative path', async () => { | |
| 62 | 122 | const mainRepoRoot = join(tempDir, 'main-repo'); | |
| 63 | 123 | const mainGitDir = join(mainRepoRoot, '.git'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | import { isJsonObject } from '@angular-devkit/core'; | |
| 10 | 10 | import { existsSync, readFileSync, statSync } from 'node:fs'; | |
| 11 | - import { dirname, isAbsolute, join, resolve } from 'node:path'; | ||
| 11 | + import { dirname, isAbsolute, join, relative, resolve } from 'node:path'; | ||
| 12 | 12 | import { Cache, Environment } from '../../../lib/config/workspace-schema'; | |
| 13 | 13 | import { AngularWorkspace } from '../../utilities/config'; | |
| 14 | 14 | ||
@@ -47,11 +47,16 @@ function getCacheBasePath(workspaceRoot: string, cachePathSetting: string): stri | |||
| 47 | 47 | // It's a git worktree | |
| 48 | 48 | const commondir = readFileSync(commondirPath, 'utf8').trim(); | |
| 49 | 49 | const commonGitDir = resolve(gitdir, commondir); | |
| 50 | - | ||
| 51 | - return resolve(dirname(commonGitDir), cachePathSetting); | ||
| 50 | + const relativeWorkspacePath = relative(currentDir, workspaceRoot); | ||
| 51 | + const mainWorkspaceRoot = resolve(dirname(commonGitDir), relativeWorkspacePath); | ||
| 52 | + if (existsSync(mainWorkspaceRoot)) { | ||
| 53 | + return resolve(mainWorkspaceRoot, cachePathSetting); | ||
| 54 | + } | ||
| 52 | 55 | } | |
| 53 | 56 | } | |
| 54 | 57 | } | |
| 58 | + | ||
| 59 | + break; | ||
| 55 | 60 | } | |
| 56 | 61 | const parentDir = dirname(currentDir); | |
| 57 | 62 | if (parentDir === currentDir) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,8 @@ | |||
| 7 | 7 | */ | |
| 8 | 8 | ||
| 9 | 9 | import { workspaces } from '@angular-devkit/core'; | |
| 10 | + import assert from 'node:assert'; | ||
| 10 | 11 | import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | |
| 11 | - import { tmpdir } from 'node:os'; | ||
| 12 | 12 | import { join, resolve } from 'node:path'; | |
| 13 | 13 | import { AngularWorkspace } from '../../utilities/config'; | |
| 14 | 14 | import { getCacheConfig } from './utilities'; | |
@@ -17,7 +17,9 @@ describe('CLI cache config utilities', () => { | |||
| 17 | 17 | let tempDir: string; | |
| 18 | 18 | ||
| 19 | 19 | beforeEach(async () => { | |
| 20 | - tempDir = await mkdtemp(join(tmpdir(), 'angular-cli-cache-spec-')); | ||
| 20 | + const baseTmpDir = process.env['TEST_TMPDIR']; | ||
| 21 | + assert(baseTmpDir, 'TEST_TMPDIR is not set'); | ||
| 22 | + tempDir = await mkdtemp(join(baseTmpDir, 'angular-cli-cache-spec-')); | ||
| 21 | 23 | }); | |
| 22 | 24 | ||
| 23 | 25 | afterEach(async () => { | |
@@ -67,6 +69,52 @@ describe('CLI cache config utilities', () => { | |||
| 67 | 69 | expect(config.path).toBe(resolve(mainRepoRoot, '.angular/cache')); | |
| 68 | 70 | }); | |
| 69 | 71 | ||
| 72 | + it('should resolve default cache path relative to corresponding nested workspace in main repository for a git worktree', async () => { | ||
| 73 | + const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| 74 | + const mainGitDir = join(mainRepoRoot, '.git'); | ||
| 75 | + const mainWorkspaceRoot = join(mainRepoRoot, 'Site1/ClientApp'); | ||
| 76 | + const worktreeRoot = join(tempDir, 'worktree'); | ||
| 77 | + const worktreeWorkspaceRoot = join(worktreeRoot, 'Site1/ClientApp'); | ||
| 78 | + | ||
| 79 | + // Create main repo with a nested Angular workspace directory | ||
| 80 | + await mkdir(mainGitDir, { recursive: true }); | ||
| 81 | + await mkdir(mainWorkspaceRoot, { recursive: true }); | ||
| 82 | + | ||
| 83 | + // Create worktree with the same nested Angular workspace structure and a .git file at the worktree root | ||
| 84 | + const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| 85 | + await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| 86 | + await mkdir(worktreeWorkspaceRoot, { recursive: true }); | ||
| 87 | + await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| 88 | + | ||
| 89 | + // Point the worktree metadata back to the main .git directory | ||
| 90 | + await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
| 91 | + | ||
| 92 | + const config = getCacheConfig(mockWorkspace(worktreeWorkspaceRoot)); | ||
| 93 | + | ||
| 94 | + expect(config.path).toBe(resolve(mainWorkspaceRoot, '.angular/cache')); | ||
| 95 | + }); | ||
| 96 | + | ||
| 97 | + it('should fall back to worktree workspace basePath when nested workspace does not exist in main repository', async () => { | ||
| 98 | + const mainRepoRoot = join(tempDir, 'main-repo'); | ||
| 99 | + const mainGitDir = join(mainRepoRoot, '.git'); | ||
| 100 | + const worktreeRoot = join(tempDir, 'worktree'); | ||
| 101 | + const worktreeWorkspaceRoot = join(worktreeRoot, 'NewSite/ClientApp'); | ||
| 102 | + | ||
| 103 | + // Create main repo without the 'NewSite/ClientApp' subdirectory (e.g., added only on the worktree branch) | ||
| 104 | + await mkdir(mainGitDir, { recursive: true }); | ||
| 105 | + | ||
| 106 | + // Create worktree with the new nested Angular workspace and link it to the main repo's .git directory | ||
| 107 | + const worktreeMetadataDir = join(mainGitDir, 'worktrees/wt-1'); | ||
| 108 | + await mkdir(worktreeMetadataDir, { recursive: true }); | ||
| 109 | + await mkdir(worktreeWorkspaceRoot, { recursive: true }); | ||
| 110 | + await writeFile(join(worktreeRoot, '.git'), `gitdir: ${worktreeMetadataDir}`); | ||
| 111 | + await writeFile(join(worktreeMetadataDir, 'commondir'), '../..'); | ||
| 112 | + | ||
| 113 | + const config = getCacheConfig(mockWorkspace(worktreeWorkspaceRoot)); | ||
| 114 | + | ||
| 115 | + expect(config.path).toBe(resolve(worktreeWorkspaceRoot, '.angular/cache')); | ||
| 116 | + }); | ||
| 117 | + | ||
| 70 | 118 | it('should resolve custom relative cache path relative to main repository root in a git worktree', async () => { | |
| 71 | 119 | const mainRepoRoot = join(tempDir, 'main-repo'); | |
| 72 | 120 | const mainGitDir = join(mainRepoRoot, '.git'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments