Commit 78f7648 1 parent af6e200 commit 78f7648 Copy full SHA for 78f7648
File tree 3 files changed +111
-4
lines changed
packages/angular_devkit/architect/src
3 files changed +111
-4
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ import {
45
45
SimpleScheduler ,
46
46
createJobHandler ,
47
47
} from './jobs' ;
48
+ import { mergeOptions } from './options' ;
48
49
import { scheduleByName , scheduleByTarget } from './schedule-by-name' ;
49
50
50
51
const inputSchema = require ( './input-schema.json' ) ;
@@ -71,10 +72,7 @@ function _createJobHandlerFromBuilderInfo(
71
72
concatMap ( async ( message ) => {
72
73
if ( message . kind === JobInboundMessageKind . Input ) {
73
74
const v = message . value as BuilderInput ;
74
- const options = {
75
- ...baseOptions ,
76
- ...v . options ,
77
- } ;
75
+ const options = mergeOptions ( baseOptions , v . options ) ;
78
76
79
77
// Validate v against the options schema.
80
78
const validation = await registry . compile ( info . optionSchema ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+
9
+ import { json } from '@angular-devkit/core' ;
10
+
11
+ import { BuilderInput } from './api' ;
12
+
13
+ type OverrideOptions = BuilderInput [ 'options' ] ;
14
+
15
+ export function mergeOptions (
16
+ baseOptions : json . JsonObject ,
17
+ overrideOptions : OverrideOptions ,
18
+ ) : json . JsonObject {
19
+ if ( ! overrideOptions ) {
20
+ return { ...baseOptions } ;
21
+ }
22
+
23
+ const options = {
24
+ ...baseOptions ,
25
+ ...overrideOptions ,
26
+ } ;
27
+
28
+ // For object-object overrides, we merge one layer deep.
29
+ for ( const key of Object . keys ( overrideOptions ) ) {
30
+ const override = overrideOptions [ key ] ;
31
+ const base = baseOptions [ key ] ;
32
+
33
+ if ( json . isJsonObject ( base ) && json . isJsonObject ( override ) ) {
34
+ options [ key ] = { ...base , ...override } ;
35
+ }
36
+ }
37
+
38
+ return options ;
39
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+
9
+ import { mergeOptions } from './options' ;
10
+
11
+ describe ( 'mergeOptions' , ( ) => {
12
+ it ( 'overwrites literal values' , ( ) => {
13
+ expect (
14
+ mergeOptions (
15
+ {
16
+ onlyBase : 'base' ,
17
+ a : 'foo' ,
18
+ b : 42 ,
19
+ c : true ,
20
+ } ,
21
+ {
22
+ onlyOverride : 'override' ,
23
+ a : 'bar' ,
24
+ b : 43 ,
25
+ c : false ,
26
+ } ,
27
+ ) ,
28
+ ) . toEqual ( {
29
+ onlyBase : 'base' ,
30
+ a : 'bar' ,
31
+ b : 43 ,
32
+ c : false ,
33
+ onlyOverride : 'override' ,
34
+ } ) ;
35
+ } ) ;
36
+
37
+ it ( 'merges object values one layer deep' , ( ) => {
38
+ expect (
39
+ mergeOptions (
40
+ {
41
+ obj : {
42
+ nested : {
43
+ fromBase : true ,
44
+ } ,
45
+ fromBase : true ,
46
+ overridden : false ,
47
+ } ,
48
+ } ,
49
+ {
50
+ obj : {
51
+ nested : {
52
+ fromOverride : true ,
53
+ } ,
54
+ overridden : true ,
55
+ fromOverride : true ,
56
+ } ,
57
+ } ,
58
+ ) ,
59
+ ) . toEqual ( {
60
+ obj : {
61
+ nested : {
62
+ fromOverride : true ,
63
+ } ,
64
+ fromBase : true ,
65
+ overridden : true ,
66
+ fromOverride : true ,
67
+ } ,
68
+ } ) ;
69
+ } ) ;
70
+ } ) ;
You can’t perform that action at this time.
0 commit comments