Skip to content

Commit daec5b7

Browse files
committed
feat: support tsconfig references
1 parent e4d4d8a commit daec5b7

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/legacy/config/config-set.ts

+42-3
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,7 @@ export class ConfigSet {
554554
let basePath = normalizeSlashes(this.rootDir)
555555
const ts = this.compilerModule
556556
// 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._findTsconfigFile(resolvedConfigFile)
560558
if (configFileName) {
561559
this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName)
562560

@@ -576,6 +574,47 @@ export class ConfigSet {
576574
}
577575

578576
// parse json, merge config extending others, ...
577+
return this._parseTsconfig(config, basePath, configFileName)
578+
}
579+
580+
protected _findTsconfigFile(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._parseTsconfig(undefined, dirname(configFileName), configFileName)
596+
if (this._includesTestFilesInConfig(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 _includesTestFilesInConfig(parsedConfig?: ts.ParsedCommandLine) {
612+
return parsedConfig?.fileNames?.length ? parsedConfig.fileNames.some((path) => this.isTestFile(path)) : false
613+
}
614+
615+
protected _parseTsconfig(config: unknown, basePath: string, configFileName?: string) {
616+
const ts = this.compilerModule
617+
579618
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)
580619
}
581620

0 commit comments

Comments
 (0)