@@ -554,9 +554,7 @@ export class ConfigSet {
554
554
let basePath = normalizeSlashes ( this . rootDir )
555
555
const ts = this . compilerModule
556
556
// Read project configuration when available.
557
- const configFileName : string | undefined = resolvedConfigFile
558
- ? normalizeSlashes ( resolvedConfigFile )
559
- : ts . findConfigFile ( normalizeSlashes ( this . rootDir ) , ts . sys . fileExists )
557
+ const configFileName : string | undefined = this . _findConfigFile ( resolvedConfigFile )
560
558
if ( configFileName ) {
561
559
this . logger . debug ( { tsConfigFileName : configFileName } , 'readTsConfig(): reading' , configFileName )
562
560
@@ -576,6 +574,51 @@ export class ConfigSet {
576
574
}
577
575
578
576
// parse json, merge config extending others, ...
577
+ return this . _parseJsonConfigFileContent ( config , basePath , configFileName )
578
+ }
579
+
580
+ protected _findConfigFile ( resolvedConfigFile ?: string ) {
581
+ const ts = this . compilerModule
582
+
583
+ const configFileName : string | undefined = resolvedConfigFile
584
+ ? normalizeSlashes ( resolvedConfigFile )
585
+ : ts . findConfigFile ( normalizeSlashes ( this . rootDir ) , ts . sys . fileExists )
586
+
587
+ return this . _findConfigFileInReferences ( configFileName )
588
+ }
589
+
590
+ protected _findConfigFileInReferences ( configFileName ?: string ) {
591
+ const ts = this . compilerModule
592
+ const parsedConfig = this . _parseJsonConfigFileContent ( undefined , this . rootDir , configFileName )
593
+
594
+ if ( this . _checkIfconfigIncludesTestFiles ( parsedConfig ) ) return configFileName
595
+
596
+ if ( parsedConfig . projectReferences ) {
597
+ for ( const ref of parsedConfig . projectReferences ) {
598
+ const filePath = ts . resolveProjectReferencePath ( ref )
599
+
600
+ if ( ts . sys . fileExists ( filePath ) ) {
601
+ const parsedRefConfig = this . _parseJsonConfigFileContent ( undefined , this . rootDir , filePath )
602
+
603
+ if ( this . _checkIfconfigIncludesTestFiles ( parsedRefConfig ) ) {
604
+ return ref . path
605
+ } else {
606
+ return this . _findConfigFileInReferences ( ref . path )
607
+ }
608
+ }
609
+ }
610
+ }
611
+
612
+ return configFileName
613
+ }
614
+
615
+ protected _checkIfconfigIncludesTestFiles ( parsedConfig ?: ts . ParsedCommandLine ) {
616
+ return parsedConfig ? parsedConfig . fileNames . some ( ( path ) => this . isTestFile ( path ) ) : false
617
+ }
618
+
619
+ protected _parseJsonConfigFileContent ( config : unknown , basePath : string , configFileName ?: string ) {
620
+ const ts = this . compilerModule
621
+
579
622
return ts . parseJsonConfigFileContent ( config , ts . sys , basePath , undefined , configFileName )
580
623
}
581
624
0 commit comments