feat(compiler-cli): add support to extend angularCompilerOptions (#22717)

`TypeScript` only supports merging and extending of `compilerOptions`. This is an implementation to support extending and inheriting of `angularCompilerOptions` from multiple files.

Closes: #22684

PR Close #22717
This commit is contained in:
Alan Agius
2018-09-11 09:38:28 +02:00
committed by Kara Erickson
parent a9a81f91cf
commit d7e5bbf2d0
4 changed files with 138 additions and 1 deletions

View File

@ -128,7 +128,37 @@ export function readConfiguration(
try {
const {projectFile, basePath} = calcProjectFileAndBasePath(project);
let {config, error} = ts.readConfigFile(projectFile, ts.sys.readFile);
const readExtendedConfigFile =
(configFile: string, existingConfig?: any): {config?: any, error?: ts.Diagnostic} => {
const {config, error} = ts.readConfigFile(configFile, ts.sys.readFile);
if (error) {
return {error};
}
// we are only interested into merging 'angularCompilerOptions' as
// other options like 'compilerOptions' are merged by TS
const baseConfig = existingConfig || config;
if (existingConfig) {
baseConfig.angularCompilerOptions = {...config.angularCompilerOptions,
...baseConfig.angularCompilerOptions};
}
if (config.extends) {
let extendedConfigPath = path.resolve(path.dirname(configFile), config.extends);
extendedConfigPath = path.extname(extendedConfigPath) ? extendedConfigPath :
`${extendedConfigPath}.json`;
if (fs.existsSync(extendedConfigPath)) {
// Call read config recursively as TypeScript only merges CompilerOptions
return readExtendedConfigFile(extendedConfigPath, baseConfig);
}
}
return {config: baseConfig};
};
const {config, error} = readExtendedConfigFile(projectFile);
if (error) {
return {