@@ -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,47 @@ 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 ) : string | undefined {
591
+ const ts = this . compilerModule
592
+
593
+ if ( ! configFileName ) return
594
+
595
+ const parsedConfig = this . _parseJsonConfigFileContent ( undefined , dirname ( configFileName ) , configFileName )
596
+ if ( this . _checkIfconfigIncludesTestFiles ( parsedConfig ) ) return configFileName
597
+
598
+ if ( parsedConfig . projectReferences ) {
599
+ for ( const ref of parsedConfig . projectReferences ) {
600
+ const filePath = ts . resolveProjectReferencePath ( ref )
601
+
602
+ if ( ts . sys . fileExists ( filePath ) ) {
603
+ return this . _findConfigFileInReferences ( ref . path )
604
+ }
605
+ }
606
+ }
607
+
608
+ return
609
+ }
610
+
611
+ protected _checkIfconfigIncludesTestFiles ( parsedConfig ?: ts . ParsedCommandLine ) {
612
+ return parsedConfig ? parsedConfig . fileNames . some ( ( path ) => this . isTestFile ( path ) ) : false
613
+ }
614
+
615
+ protected _parseJsonConfigFileContent ( config : unknown , basePath : string , configFileName ?: string ) {
616
+ const ts = this . compilerModule
617
+
579
618
return ts . parseJsonConfigFileContent ( config , ts . sys , basePath , undefined , configFileName )
580
619
}
581
620
0 commit comments