Skip to content

Commit 3644197

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

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

src/legacy/config/config-set.ts

+46-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._findConfigFile(resolvedConfigFile)
560558
if (configFileName) {
561559
this.logger.debug({ tsConfigFileName: configFileName }, 'readTsConfig(): reading', configFileName)
562560

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

578576
// 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+
579622
return ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName)
580623
}
581624

0 commit comments

Comments
 (0)