@@ -89,8 +89,8 @@ function _resolveTsConfigFiles(tsConfigPath: string, files: string[]): string[]
8989 if ( location ) {
9090 const destFiles : string [ ] = [ ] ;
9191 if ( files && files . length > 0 ) {
92- files . forEach ( ( theFile ) => {
93- destFiles . push ( location + theFile ) ;
92+ arrForEach ( files , ( theFile ) => {
93+ destFiles . push ( normalizePath ( location + theFile ) ) ;
9494 } ) ;
9595 }
9696
@@ -100,6 +100,27 @@ function _resolveTsConfigFiles(tsConfigPath: string, files: string[]): string[]
100100 return files ;
101101}
102102
103+ /**
104+ * Merge the files from the merge array into the target array but only add unique values
105+ *
106+ * @param target - The target array to merge into
107+ * @param merge - The array to merge into the target
108+ * @returns - The target array
109+ */
110+ function _mergeFiles ( target : string [ ] , merge : string [ ] ) : string [ ] {
111+ if ( isNullOrUndefined ( target ) || target . length === 0 ) {
112+ return merge ;
113+ }
114+
115+ arrForEach ( merge , ( val ) => {
116+ if ( target . indexOf ( val ) === - 1 ) {
117+ target . push ( val ) ;
118+ }
119+ } ) ;
120+
121+ return target ;
122+ }
123+
103124function _mergeConfigs ( target : any , merge : any ) : any {
104125 if ( isNullOrUndefined ( target ) ) {
105126 return merge ;
@@ -174,7 +195,7 @@ function _createTsConfigDetails(grunt: IGruntWrapper, tsConfigOrOption: string |
174195 let compilerOptions = tsConfig . compilerOptions = tsConfig . compilerOptions || { } ;
175196
176197 if ( compilerOptions . rootDir ) {
177- projectRootDir = path . resolve ( findCommonPath ( [ details . name || "." ] ) , compilerOptions . rootDir ) ;
198+ projectRootDir = normalizePath ( path . resolve ( findCommonPath ( [ details . name || "." ] ) , compilerOptions . rootDir ) ) ;
178199
179200 // eslint-disable-next-line security/detect-non-literal-fs-filename
180201 if ( ! fs . existsSync ( path . resolve ( projectRootDir ) ) ) {
@@ -230,7 +251,7 @@ function _createTsConfigDetails(grunt: IGruntWrapper, tsConfigOrOption: string |
230251 grunt . logDebug ( "-----------------------------------------------------------------------------------------------------" ) ;
231252 }
232253
233- tsFiles . forEach ( ( theFile ) => {
254+ arrForEach ( tsFiles , ( theFile ) => {
234255 let excludePath = false ;
235256
236257 if ( theFile . startsWith ( "!" ) ) {
@@ -270,8 +291,16 @@ function _createTsConfigDetails(grunt: IGruntWrapper, tsConfigOrOption: string |
270291 if ( excludePath ) {
271292 destContainer = tsConfig . exclude = tsConfig . exclude || [ ] ;
272293 } else if ( ! tsConfig . exclude && theResolvedFile . indexOf ( "*" ) === - 1 ) {
294+ if ( grunt . isDebug ) {
295+ grunt . logDebug ( "Using files as the container" ) ;
296+ }
297+
273298 destContainer = tsConfig . files = tsConfig . files || [ ] ;
274299 } else {
300+ if ( grunt . isDebug ) {
301+ grunt . logDebug ( "Using include as the container" ) ;
302+ }
303+
275304 destContainer = tsConfig . include = tsConfig . include || [ ] ;
276305 }
277306
@@ -282,16 +311,28 @@ function _createTsConfigDetails(grunt: IGruntWrapper, tsConfigOrOption: string |
282311 grunt . logDebug ( "-----------------------------------------------------------------------------------------------------" ) ;
283312
284313 if ( tsConfig . files && tsConfig . files . length === 0 ) {
314+ if ( grunt . isDebug ) {
315+ grunt . logDebug ( "Removing empty files" ) ;
316+ }
317+
285318 details . modified = true ;
286319 delete tsConfig . files ;
287320 }
288321
289322 if ( tsConfig . include && tsConfig . include . length === 0 ) {
323+ if ( grunt . isDebug ) {
324+ grunt . logDebug ( "Removing empty include" ) ;
325+ }
326+
290327 details . modified = true ;
291328 delete tsConfig . include ;
292329 }
293330
294331 if ( tsConfig . exclude && tsConfig . exclude . length === 0 ) {
332+ if ( grunt . isDebug ) {
333+ grunt . logDebug ( "Removing empty exclude" ) ;
334+ }
335+
295336 details . modified = true ;
296337 delete tsConfig . exclude ;
297338 }
@@ -307,16 +348,30 @@ function _createTsConfigDetails(grunt: IGruntWrapper, tsConfigOrOption: string |
307348 let tsConfig = details . tsConfig ;
308349 //grunt.log.writeln("Using tsconfig: " + tsProject);
309350 if ( tsConfig . files ) {
310- tsConfigFiles = _resolveTsConfigFiles ( details . name , tsConfig . files ) ;
311- } else if ( tsConfig . include ) {
312- tsConfigFiles = _resolveTsConfigFiles ( details . name , tsConfig . include ) ;
351+ if ( grunt . isDebug ) {
352+ grunt . logDebug ( "Adding Files: " + JSON . stringify ( tsConfig . files ) ) ;
353+ }
354+
355+ tsConfigFiles = _mergeFiles ( tsConfigFiles , _resolveTsConfigFiles ( details . name , tsConfig . files ) ) ;
356+ }
357+
358+ if ( tsConfig . include ) {
359+ if ( grunt . isDebug ) {
360+ grunt . logDebug ( "Adding Include: " + JSON . stringify ( tsConfig . include ) ) ;
361+ }
362+
363+ tsConfigFiles = _mergeFiles ( tsConfigFiles , _resolveTsConfigFiles ( details . name , tsConfig . include ) ) ;
313364 }
314365
315366 // if (tsConfig.exclude) {
316367 // exclude = _resolveTsConfigFiles(details.name, tsConfig.exclude);
317368 // //grunt.log.writeln("Excluding: " + JSON.stringify(exclude));
318369 // }
319370 }
371+
372+ if ( grunt . isDebug ) {
373+ grunt . logDebug ( "getFiles (" + details . name + "): " + JSON . stringify ( tsConfigFiles ) ) ;
374+ }
320375
321376 return tsConfigFiles ;
322377 }
0 commit comments