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:

committed by
Kara Erickson

parent
a9a81f91cf
commit
d7e5bbf2d0
@ -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 {
|
||||
|
Reference in New Issue
Block a user