55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { JsonAstObject } from '@angular-devkit/core' ;
8+ import { JsonAstObject , logging } from '@angular-devkit/core' ;
99import { Rule , Tree , UpdateRecorder } from '@angular-devkit/schematics' ;
1010import { posix } from 'path' ;
1111import {
@@ -16,33 +16,32 @@ import {
1616import { Builders } from '../../utility/workspace-models' ;
1717import { getAllOptions , getTargets , getWorkspace , readJsonFileAsAstObject } from './utils' ;
1818
19-
2019/**
2120 * Update the tsconfig files for applications
2221 * - Removes enableIvy: true
2322 * - Sets stricter file inclusions
2423 */
2524export function updateApplicationTsConfigs ( ) : Rule {
26- return ( tree : Tree ) => {
25+ return ( tree , context ) => {
2726 const workspace = getWorkspace ( tree ) ;
2827
2928 for ( const { target } of getTargets ( workspace , 'build' , Builders . Browser ) ) {
30- updateTsConfig ( tree , target , Builders . Browser ) ;
29+ updateTsConfig ( tree , target , Builders . Browser , context . logger ) ;
3130 }
3231
3332 for ( const { target } of getTargets ( workspace , 'server' , Builders . Server ) ) {
34- updateTsConfig ( tree , target , Builders . Server ) ;
33+ updateTsConfig ( tree , target , Builders . Server , context . logger ) ;
3534 }
3635
3736 for ( const { target } of getTargets ( workspace , 'test' , Builders . Karma ) ) {
38- updateTsConfig ( tree , target , Builders . Karma ) ;
37+ updateTsConfig ( tree , target , Builders . Karma , context . logger ) ;
3938 }
4039
4140 return tree ;
4241 } ;
4342}
4443
45- function updateTsConfig ( tree : Tree , builderConfig : JsonAstObject , builderName : Builders ) {
44+ function updateTsConfig ( tree : Tree , builderConfig : JsonAstObject , builderName : Builders , logger : logging . LoggerApi ) {
4645 const options = getAllOptions ( builderConfig ) ;
4746 for ( const option of options ) {
4847 let recorder : UpdateRecorder ;
@@ -55,6 +54,7 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
5554 const tsConfigPath = tsConfigOption . value ;
5655 let tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
5756 if ( ! tsConfigAst ) {
57+ logger . warn ( `Cannot find file: ${ tsConfigPath } ` ) ;
5858 continue ;
5959 }
6060
@@ -78,7 +78,10 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
7878 if ( builderName !== Builders . Karma ) {
7979 // Note: we need to re-read the tsconfig after very commit because
8080 // 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 ) ! ;
8285 const include = findPropertyInAstObject ( tsConfigAst , 'include' ) ;
8386
8487 if ( include && include . kind === 'array' ) {
@@ -109,13 +112,15 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
109112
110113 if ( newFiles . length ) {
111114 recorder = tree . beginUpdate ( tsConfigPath ) ;
112- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
115+ // tslint:disable-next-line: no-non-null-assertion
116+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ! ;
113117 insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'files' , newFiles , 2 ) ;
114118 tree . commitUpdate ( recorder ) ;
115119 }
116120
117121 recorder = tree . beginUpdate ( tsConfigPath ) ;
118- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
122+ // tslint:disable-next-line: no-non-null-assertion
123+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ! ;
119124 removePropertyInAstObject ( recorder , tsConfigAst , 'exclude' ) ;
120125 tree . commitUpdate ( recorder ) ;
121126 }
0 commit comments