Skip to content

Commit 147fe4d

Browse files
committed
fixup! fix(@angular/build): scope cache directory by project and builder name
1 parent 431414e commit 147fe4d

5 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎packages/angular/build/src/builders/dev-server/vite/server.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export async function setupServer(
165165
*/
166166
const preTransformRequests =
167167
externalMetadata.explicitBrowser.length === 0 && ssrMode === ServerSsrMode.NoSsr;
168-
const cacheDir = serverOptions.cacheOptions.localPath ?? serverOptions.cacheOptions.path;
168+
const cacheDir = join(
169+
serverOptions.cacheOptions.localPath ?? serverOptions.cacheOptions.path,
170+
'vite',
171+
);
169172

170173
const configuration: Vite.InlineConfig = {
171174
configFile: false,

‎packages/angular/build/src/builders/ng-packagr/builder.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function* execute(
7373
const ngPackagrOptions: NgPackagrOptions = {
7474
cacheEnabled,
7575
poll: options.poll,
76-
cacheDirectory: join(cacheDirectory, 'ng-packagr'),
76+
cacheDirectory: cacheDirectory,
7777
};
7878

7979
try {

‎packages/angular/build/src/builders/unit-test/builder.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export async function* execute(
340340
} satisfies ApplicationBuilderInternalOptions;
341341

342342
const dumpDirectory = normalizedOptions.dumpVirtualFiles
343-
? path.join(normalizedOptions.cacheOptions.path, 'unit-test', 'output-files')
343+
? path.join(normalizedOptions.cacheOptions.path, 'output-files')
344344
: undefined;
345345

346346
yield* runBuildAndTest(

‎packages/angular/build/src/utils/normalize-cache.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ export function normalizeCacheOptions(
140140

141141
const cacheBasePath = getCacheBasePath(workspaceRoot, path);
142142
const localCacheBasePath = isAbsolute(path) ? path : resolve(workspaceRoot, path);
143+
const normalizedBuilderName = builderName.replaceAll(':', '-');
143144

144145
return {
145146
enabled: cacheEnabled,
146147
basePath: cacheBasePath,
147-
path: join(cacheBasePath, VERSION, projectName, builderName),
148+
path: join(cacheBasePath, VERSION, projectName, normalizedBuilderName),
148149
localBasePath: localCacheBasePath,
149-
localPath: join(localCacheBasePath, VERSION, projectName, builderName),
150+
localPath: join(localCacheBasePath, VERSION, projectName, normalizedBuilderName),
150151
};
151152
}

‎packages/angular/build/src/utils/normalize-cache_spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,18 @@ describe('normalizeCacheOptions', () => {
275275
resolve(worktreeRoot, '.angular/cache/0.0.0-PLACEHOLDER/my-app/vite'),
276276
);
277277
});
278+
279+
it('should normalize builderName to avoid invalid path characters', async () => {
280+
const workspaceRoot = join(tempDir, 'project');
281+
await mkdir(join(workspaceRoot, '.git'), { recursive: true });
282+
283+
const options = normalizeCacheOptions({}, workspaceRoot, 'my-app', '@angular/build:unit-test');
284+
285+
expect(options.path).toBe(
286+
resolve(workspaceRoot, '.angular/cache/0.0.0-PLACEHOLDER/my-app/@angular/build-unit-test'),
287+
);
288+
expect(options.localPath).toBe(
289+
resolve(workspaceRoot, '.angular/cache/0.0.0-PLACEHOLDER/my-app/@angular/build-unit-test'),
290+
);
291+
});
278292
});

0 commit comments

Comments
 (0)