Skip to content

Commit 01fa047

Browse files
committed
refactor(@angular-devkit/build-angular): use direct type assertions for cache option normalization
1 parent 096aaba commit 01fa047

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/angular_devkit/build_angular/src/utils/normalize-cache.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { json } from '@angular-devkit/core';
109
import { join, resolve } from 'path';
1110
import { VERSION } from './package-version';
1211

@@ -25,14 +24,22 @@ interface CacheMetadata {
2524
path?: string;
2625
}
2726

27+
function hasCacheMetadata(value: unknown): value is { cli: { cache: CacheMetadata } } {
28+
return (
29+
!!value &&
30+
typeof value === 'object' &&
31+
'cli' in value &&
32+
!!value['cli'] &&
33+
typeof value['cli'] === 'object' &&
34+
'cache' in value['cli']
35+
);
36+
}
37+
2838
export function normalizeCacheOptions(
29-
metadata: json.JsonObject,
39+
projectMetadata: unknown,
3040
worspaceRoot: string,
3141
): NormalizedCachedOptions {
32-
const cacheMetadata: CacheMetadata =
33-
json.isJsonObject(metadata.cli) && json.isJsonObject(metadata.cli.cache)
34-
? metadata.cli.cache
35-
: {};
42+
const cacheMetadata = hasCacheMetadata(projectMetadata) ? projectMetadata.cli.cache : {};
3643

3744
const { enabled = true, environment = 'local', path = '.angular/cache' } = cacheMetadata;
3845
const isCI = process.env['CI'] === '1' || process.env['CI']?.toLowerCase() === 'true';

0 commit comments

Comments
 (0)