@@ -74,33 +74,38 @@ function updateTsConfig(tree: Tree, builderConfig: JsonAstObject, builderName: B
74
74
}
75
75
76
76
// Add stricter file inclusions to avoid unused file warning during compilation
77
+ const rootInSrc = tsConfigPath . includes ( 'src/' ) ;
78
+ const rootSrc = rootInSrc ? '' : 'src/' ;
77
79
if ( builderName !== Builders . Karma ) {
78
80
// Note: we need to re-read the tsconfig after very commit because
79
81
// otherwise the updates will be out of sync since we are ammending the same node.
80
82
tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
81
83
const files = findPropertyInAstObject ( tsConfigAst , 'files' ) ;
82
84
const include = findPropertyInAstObject ( tsConfigAst , 'include' ) ;
83
85
84
- if ( ! files && ! include ) {
85
- const rootInSrc = tsConfigPath . includes ( 'src/' ) ;
86
- const rootSrc = rootInSrc ? '' : 'src/' ;
87
- const files = builderName === Builders . Server
88
- ? [ `${ rootSrc } main.server.ts` ]
89
- : [ `${ rootSrc } main.ts` , `${ rootSrc } polyfills.ts` ] ;
90
-
91
- recorder = tree . beginUpdate ( tsConfigPath ) ;
92
- insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'files' , files , 2 ) ;
93
- tree . commitUpdate ( recorder ) ;
94
-
95
- if ( builderName === Builders . Browser ) {
96
- tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
97
- recorder = tree . beginUpdate ( tsConfigPath ) ;
98
- insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'include' , [ `${ rootSrc } **/*.d.ts` ] , 2 ) ;
99
- tree . commitUpdate ( recorder ) ;
86
+ recorder = tree . beginUpdate ( tsConfigPath ) ;
87
+ if ( include && include . kind === 'array' ) {
88
+ const tsInclude = include . elements . find ( ( { value } ) => typeof value === 'string' && value . endsWith ( '**/*.ts' ) ) ;
89
+ if ( tsInclude ) {
90
+ const { start, end } = tsInclude ;
91
+ recorder . remove ( start . offset , end . offset - start . offset ) ;
92
+ // Replace ts includes with d.ts
93
+ recorder . insertLeft ( start . offset , tsInclude . text . replace ( '.ts' , '.d.ts' ) ) ;
100
94
}
95
+ } else {
96
+ insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'include' , [ `${ rootSrc } **/*.d.ts` ] , 2 ) ;
97
+ }
98
+
99
+ tree . commitUpdate ( recorder ) ;
101
100
101
+ if ( ! files ) {
102
102
tsConfigAst = readJsonFileAsAstObject ( tree , tsConfigPath ) ;
103
103
recorder = tree . beginUpdate ( tsConfigPath ) ;
104
+
105
+ const files = builderName === Builders . Server
106
+ ? [ `${ rootSrc } main.server.ts` ]
107
+ : [ `${ rootSrc } main.ts` , `${ rootSrc } polyfills.ts` ] ;
108
+ insertPropertyInAstObjectInOrder ( recorder , tsConfigAst , 'files' , files , 2 ) ;
104
109
removePropertyInAstObject ( recorder , tsConfigAst , 'exclude' ) ;
105
110
tree . commitUpdate ( recorder ) ;
106
111
}
0 commit comments