|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {assertNoErrors, getConfig} from '../../utils/config'; |
| 9 | +import {assertNoErrors, ConfigValidationError, getConfig} from '../../utils/config'; |
10 | 10 |
|
11 | 11 | /** Interface describing a built package. */ |
12 | 12 | export interface BuiltPackage { |
@@ -49,25 +49,26 @@ export interface ReleaseNotesConfig { |
49 | 49 | export type DevInfraReleaseConfig = {release: ReleaseConfig}; |
50 | 50 |
|
51 | 51 | /** Retrieve and validate the config as `ReleaseConfig`. */ |
52 | | -export function getReleaseConfig( |
53 | | - config: Partial<DevInfraReleaseConfig> = getConfig(), |
54 | | -): ReleaseConfig { |
| 52 | +export function assertValidReleaseConfig<T>( |
| 53 | + config: T & Partial<DevInfraReleaseConfig>, |
| 54 | +): asserts config is T & DevInfraReleaseConfig { |
55 | 55 | // List of errors encountered validating the config. |
56 | 56 | const errors: string[] = []; |
57 | 57 |
|
58 | 58 | if (config.release === undefined) { |
59 | | - errors.push(`No configuration defined for "release"`); |
| 59 | + throw new ConfigValidationError('No configuration provided for `release`'); |
60 | 60 | } |
61 | | - if (config.release?.npmPackages === undefined) { |
| 61 | + |
| 62 | + if (config.release.npmPackages === undefined) { |
62 | 63 | errors.push(`No "npmPackages" configured for releasing.`); |
63 | 64 | } |
64 | | - if (config.release?.buildPackages === undefined) { |
| 65 | + if (config.release.buildPackages === undefined) { |
65 | 66 | errors.push(`No "buildPackages" function configured for releasing.`); |
66 | 67 | } |
67 | | - if (config.release?.releaseNotes === undefined) { |
| 68 | + if (config.release.releaseNotes === undefined) { |
68 | 69 | errors.push(`No "releaseNotes" configured for releasing.`); |
69 | 70 | } |
70 | | - |
71 | | - assertNoErrors(errors); |
72 | | - return config.release!; |
| 71 | + if (errors.length) { |
| 72 | + throw new ConfigValidationError('Invalid `release` configuration', errors); |
| 73 | + } |
73 | 74 | } |
0 commit comments