Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 6b7b19d

Browse files
unionalnchanged
authored andcommitted
fix: Improving tsConfig, added "extends" support (#1411)
* fix: tsconfig extends support * chore: remove log * chore: remove extra changes * chore: fix style * chore: manually parsing config file * fix: child config should override parent. * fix: add back missing line
1 parent a87c634 commit 6b7b19d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/TypescriptConfig.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class TypescriptConfig {
110110
const configFileRelPath = this.configFile.replace(this.context.appRoot, "");
111111
this.context.log.echoInfo(`Typescript config file: ${configFileRelPath}`);
112112
configFileFound = true;
113-
const res = ts.readConfigFile(this.configFile, p => fs.readFileSync(p).toString());
113+
const res = readConfigFile(this.configFile, this.context.appRoot);
114114
config = res.config;
115115
if (res.error) {
116116
this.context.log.echoError(`Errors in ${configFileRelPath}`);
@@ -148,3 +148,17 @@ export class TypescriptConfig {
148148
}
149149
}
150150
}
151+
152+
function readConfigFile(configFilePath: string, rootDir: string) {
153+
const res = ts.readConfigFile(configFilePath, ts.sys.readFile);
154+
if (res.error || !res.config || !res.config.extends) return res
155+
156+
const extendsFilePath = res.config.extends
157+
const parentRes = readConfigFile(path.isAbsolute(extendsFilePath) ? extendsFilePath : path.join(rootDir, extendsFilePath), rootDir)
158+
if (parentRes.config) {
159+
const config = { ...res.config };
160+
delete config.extends;
161+
res.config = { ...parentRes.config, ...config, compilerOptions: { ...parentRes.config.compilerOptions, ...config.compilerOptions } };
162+
}
163+
return res
164+
}

0 commit comments

Comments
 (0)