5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { JsonAstObject } from '@angular-devkit/core' ;
8
+ import { JsonAstObject , logging } from '@angular-devkit/core' ;
9
9
import { Rule , Tree , UpdateRecorder } from '@angular-devkit/schematics' ;
10
10
import { posix } from 'path' ;
11
11
import {
@@ -16,33 +16,32 @@ import {
16
16
import { Builders } from '../../utility/workspace-models' ;
17
17
import { getAllOptions , getTargets , getWorkspace , readJsonFileAsAstObject } from './utils' ;
18
18
19
-
20
19
/**
21
20
* Update the tsconfig files for applications
22
21
* - Removes enableIvy: true
23
22
* - Sets stricter file inclusions
24
23
*/
25
24
export function updateApplicationTsConfigs ( ) : Rule {
26
- return ( tree : Tree ) => {
25
+ return ( tree , context ) => {
27
26
const workspace = getWorkspace ( tree ) ;
28
27
29
28
for ( const { target } of getTargets ( workspace , 'build' , Builders . Browser ) ) {
30
- updateTsConfig ( tree , target , Builders . Browser ) ;
29
+ updateTsConfig ( tree , target , Builders . Browser , context . logger ) ;
31
30
}
32
31
33
32
for ( const { target } of getTargets ( workspace , 'server' , Builders . Server ) ) {
34
- updateTsConfig ( tree , target , Builders . Server ) ;
33
+ updateTsConfig ( tree , target , Builders . Server , context . logger ) ;
35
34
}
36
35
37
36
for ( const { target } of getTargets ( workspace , 'test' , Builders . Karma ) ) {
38
- updateTsConfig ( tree , target , Builders . Karma ) ;
37
+ updateTsConfig ( tree , target , Builders . Karma , context . logger ) ;
39
38
}
40
39
41
40
return tree ;
42
41
} ;
43
42
}
44
43
45
- function updateTsConfig ( tree : Tree , builderConfig : JsonAstObject , builderName : Builders ) {
44
+ function updateTsConfig ( tree : Tree , builderConfig : JsonAstObject , builderName : Builders , logger : logging . LoggerApi ) {
46
45
const options = getAllOptions ( builderConfig ) ;
47
46
for ( const option of options ) {
48
47
let recorder : UpdateRecorder ;
@@ -55,6 +54,7 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
55
54
const tsConfigPath = tsConfigOption . value ;
56
55
let tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
57
56
if ( ! tsConfigAst ) {
57
+ logger . warn ( `Cannot find file: ${ tsConfigPath } ` ) ;
58
58
continue ;
59
59
}
60
60
@@ -78,7 +78,10 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
78
78
if ( builderName !== Builders . Karma ) {
79
79
// Note: we need to re-read the tsconfig after very commit because
80
80
// otherwise the updates will be out of sync since we are ammending the same node.
81
- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
81
+
82
+ // we are already checking that tsconfig exists above!
83
+ // tslint:disable-next-line: no-non-null-assertion
84
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ! ;
82
85
const include = findPropertyInAstObject ( tsConfigAst , 'include' ) ;
83
86
84
87
if ( include && include . kind === 'array' ) {
@@ -109,13 +112,15 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
109
112
110
113
if ( newFiles . length ) {
111
114
recorder = tree . beginUpdate ( tsConfigPath ) ;
112
- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
115
+ // tslint:disable-next-line: no-non-null-assertion
116
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ! ;
113
117
insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'files' , newFiles , 2 ) ;
114
118
tree . commitUpdate ( recorder ) ;
115
119
}
116
120
117
121
recorder = tree . beginUpdate ( tsConfigPath ) ;
118
- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
122
+ // tslint:disable-next-line: no-non-null-assertion
123
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ! ;
119
124
removePropertyInAstObject ( recorder , tsConfigAst , 'exclude' ) ;
120
125
tree . commitUpdate ( recorder ) ;
121
126
}
0 commit comments