Skip to content

Commit a9bfb01

Browse files
committed
Fix missing support for tsconfig file path references. Ref:#125
1 parent c12d7b3 commit a9bfb01

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

typescript/src/core/utils/project.utils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ProjectUtils {
4343
const projectRoot = dirsToScan[0];
4444
const tsConfigPath = path.join(projectRoot, "tsconfig.json");
4545
if(fs.existsSync(tsConfigPath)) {
46-
result.push(...this.getProjectInfo(projectRoot));
46+
result.push(...this.getProjectInfo(projectRoot, 'tsconfig.json'));
4747
} else {
4848
// add all subdirectories as potential project candidates
4949
fs.readdirSync(projectRoot).forEach(file => {
@@ -69,15 +69,22 @@ export class ProjectUtils {
6969
});
7070
}
7171

72-
private static getProjectInfo(projectPath: string): LCEProjectInfo[] {
72+
private static getConfigFileName(rawConfigPath : string) {
73+
const pathIsADirectory = fs.statSync(rawConfigPath).isDirectory();
74+
const defaultConfigFileName = 'tsconfig.json';
75+
return pathIsADirectory? path.join(rawConfigPath, defaultConfigFileName) : rawConfigPath;
76+
}
77+
78+
private static getProjectInfo(projectPath: string, configFileName: string): LCEProjectInfo[] {
7379
const result: LCEProjectInfo[] = [];
74-
const tsConfig = this.parseTsConfig(projectPath);
80+
const tsConfig = this.parseTsConfig(projectPath, configFileName);
7581

7682
const subProjectPaths: string[] = [];
7783

7884
if(tsConfig.projectReferences) {
7985
for (const ref of tsConfig.projectReferences) {
80-
const subProjectInfos = this.getProjectInfo(ref.path);
86+
const referencedConfigFileName = this.getConfigFileName(ref.path);
87+
const subProjectInfos = this.getProjectInfo(path.dirname(referencedConfigFileName), path.basename(referencedConfigFileName));
8188
subProjectPaths.push(...subProjectInfos.map(spi => FileUtils.normalizePath(spi.projectPath)));
8289
result.push(...subProjectInfos);
8390
}
@@ -99,11 +106,11 @@ export class ProjectUtils {
99106
return result;
100107
}
101108

102-
private static parseTsConfig(projectRoot: string): ParsedCommandLine {
103-
const tsConfigPath = path.join(projectRoot, "tsconfig.json");
109+
private static parseTsConfig(projectRoot: string, configFile: string): ParsedCommandLine {
110+
const tsConfigPath = path.join(projectRoot, configFile);
104111
const configFileText = fs.readFileSync(tsConfigPath, 'utf8');
105112
const configFileSourceFile = createSourceFile(
106-
'tsconfig.json', configFileText, ScriptTarget.JSON
113+
configFile, configFileText, ScriptTarget.JSON
107114
);
108115

109116
// Parse the tsconfig.json

0 commit comments

Comments
 (0)