-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathoptions.ts
39 lines (31 loc) · 923 Bytes
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { json } from '@angular-devkit/core';
import { BuilderInput } from './api';
type OverrideOptions = BuilderInput['options'];
export function mergeOptions(
baseOptions: json.JsonObject,
overrideOptions: OverrideOptions,
): json.JsonObject {
if (!overrideOptions) {
return { ...baseOptions };
}
const options = {
...baseOptions,
...overrideOptions,
};
// For object-object overrides, we merge one layer deep.
for (const key of Object.keys(overrideOptions)) {
const override = overrideOptions[key];
const base = baseOptions[key];
if (json.isJsonObject(base) && json.isJsonObject(override)) {
options[key] = { ...base, ...override };
}
}
return options;
}