Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): use direct type assertions f…
Browse files Browse the repository at this point in the history
…or cache option normalization
  • Loading branch information
clydin committed Mar 12, 2024
1 parent 096aaba commit 01fa047
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/angular_devkit/build_angular/src/utils/normalize-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

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

Expand All @@ -25,14 +24,22 @@ interface CacheMetadata {
path?: string;
}

function hasCacheMetadata(value: unknown): value is { cli: { cache: CacheMetadata } } {
return (
!!value &&
typeof value === 'object' &&
'cli' in value &&
!!value['cli'] &&
typeof value['cli'] === 'object' &&
'cache' in value['cli']
);
}

export function normalizeCacheOptions(
metadata: json.JsonObject,
projectMetadata: unknown,
worspaceRoot: string,
): NormalizedCachedOptions {
const cacheMetadata: CacheMetadata =
json.isJsonObject(metadata.cli) && json.isJsonObject(metadata.cli.cache)
? metadata.cli.cache
: {};
const cacheMetadata = hasCacheMetadata(projectMetadata) ? projectMetadata.cli.cache : {};

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

0 comments on commit 01fa047

Please sign in to comment.