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 , JsonParseMode , parseJsonAst } from '@angular-devkit/core' ;
8
+ import { JsonAstObject } from '@angular-devkit/core' ;
9
9
import { Rule , Tree , UpdateRecorder } from '@angular-devkit/schematics' ;
10
10
import {
11
11
findPropertyInAstObject ,
12
12
insertPropertyInAstObjectInOrder ,
13
13
removePropertyInAstObject ,
14
14
} from '../../utility/json-utils' ;
15
15
import { Builders } from '../../utility/workspace-models' ;
16
- import { getAllOptions , getTargets , getWorkspace } from './utils' ;
16
+ import { getAllOptions , getTargets , getWorkspace , readJsonFileAsAstObject } from './utils' ;
17
17
18
18
19
19
/**
@@ -52,7 +52,7 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
52
52
}
53
53
54
54
const tsConfigPath = tsConfigOption . value ;
55
- let tsConfigAst = getTsConfigAst ( tree , tsConfigPath ) ;
55
+ let tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
56
56
if ( ! tsConfigAst ) {
57
57
continue ;
58
58
}
@@ -77,7 +77,7 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
77
77
if ( builderName !== Builders . Karma ) {
78
78
// Note: we need to re-read the tsconfig after very commit because
79
79
// otherwise the updates will be out of sync since we are ammending the same node.
80
- tsConfigAst = getTsConfigAst ( tree , tsConfigPath ) as JsonAstObject ;
80
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
81
81
const files = findPropertyInAstObject ( tsConfigAst , 'files' ) ;
82
82
const include = findPropertyInAstObject ( tsConfigAst , 'include' ) ;
83
83
@@ -93,32 +93,17 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
93
93
tree . commitUpdate ( recorder ) ;
94
94
95
95
if ( builderName === Builders . Browser ) {
96
- tsConfigAst = getTsConfigAst ( tree , tsConfigPath ) as JsonAstObject ;
96
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
97
97
recorder = tree . beginUpdate ( tsConfigPath ) ;
98
98
insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'include' , [ `${ rootSrc } **/*.d.ts` ] , 2 ) ;
99
99
tree . commitUpdate ( recorder ) ;
100
100
}
101
101
102
- tsConfigAst = getTsConfigAst ( tree , tsConfigPath ) as JsonAstObject ;
102
+ tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
103
103
recorder = tree . beginUpdate ( tsConfigPath ) ;
104
104
removePropertyInAstObject ( recorder , tsConfigAst , 'exclude' ) ;
105
105
tree . commitUpdate ( recorder ) ;
106
106
}
107
107
}
108
108
}
109
109
}
110
-
111
- function getTsConfigAst ( tree : Tree , path : string ) : JsonAstObject | undefined {
112
- const configBuffer = tree . read ( path ) ;
113
- if ( ! configBuffer ) {
114
- return undefined ;
115
- }
116
-
117
- const content = configBuffer . toString ( ) ;
118
- const tsConfigAst = parseJsonAst ( content , JsonParseMode . Loose ) ;
119
- if ( ! tsConfigAst || tsConfigAst . kind !== 'object' ) {
120
- return undefined ;
121
- }
122
-
123
- return tsConfigAst ;
124
- }
0 commit comments