MCPcopy Index your code
hub / github.com/angular/angular / readConfiguration

Function readConfiguration

packages/compiler-cli/src/perform_compile.ts:75–181  ·  view source on GitHub ↗
(
  project: string,
  existingOptions?: api.CompilerOptions,
  host: ConfigurationHost = getFileSystem(),
)

Source from the content-addressed store, hash-verified

73}
74
75export function readConfiguration(
76 project: string,
77 existingOptions?: api.CompilerOptions,
78 host: ConfigurationHost = getFileSystem(),
79): ParsedConfiguration {
80 try {
81 const fs = getFileSystem();
82
83 const readConfigFile = (configFile: string) =>
84 ts.readConfigFile(configFile, (file) => host.readFile(host.resolve(file)));
85 const readAngularCompilerOptions = (
86 configFile: string,
87 parentOptions: NgCompilerOptions = {},
88 ): NgCompilerOptions => {
89 const {config, error} = readConfigFile(configFile);
90
91 if (error) {
92 // Errors are handled later on by 'parseJsonConfigFileContent'
93 return parentOptions;
94 }
95
96 // Note: In Google, `angularCompilerOptions` are stored in `bazelOptions`.
97 // This function typically doesn't run for actual Angular compilations, but
98 // tooling like Tsurge, or schematics may leverage this helper, so we account
99 // for this here.
100 const angularCompilerOptions =
101 config.angularCompilerOptions ?? config.bazelOptions?.angularCompilerOptions;
102
103 // we are only interested into merging 'angularCompilerOptions' as
104 // other options like 'compilerOptions' are merged by TS
105 let existingNgCompilerOptions = {...angularCompilerOptions, ...parentOptions};
106 if (!config.extends) {
107 return existingNgCompilerOptions;
108 }
109
110 const extendsPaths: string[] =
111 typeof config.extends === 'string' ? [config.extends] : config.extends;
112
113 // Call readAngularCompilerOptions recursively to merge NG Compiler options
114 // Reverse the array so the overrides happen from right to left.
115 return [...extendsPaths].reverse().reduce((prevOptions, extendsPath) => {
116 const extendedConfigPath = getExtendedConfigPath(configFile, extendsPath, host, fs);
117
118 return extendedConfigPath === null
119 ? prevOptions
120 : readAngularCompilerOptions(extendedConfigPath, prevOptions);
121 }, existingNgCompilerOptions);
122 };
123
124 const {projectFile, basePath} = calcProjectFileAndBasePath(project, host);
125 const configFileName = host.resolve(host.pwd(), projectFile);
126 const {config, error} = readConfigFile(projectFile);
127
128 if (error) {
129 return {
130 project,
131 errors: [error],
132 rootNames: [],

Callers 5

parseTsconfigOrDieFunction · 0.90
parseNgCompilerOptionsFunction · 0.90
createPerformWatchHostFunction · 0.90

Calls 7

getFileSystemFunction · 0.90
readConfigFileFunction · 0.85
createParseConfigHostFunction · 0.85
resolveMethod · 0.65
pwdMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…