MCPcopy Create free account
hub / github.com/angular/angular / readAngularCompilerOptions

Function readAngularCompilerOptions

packages/compiler-cli/src/perform_compile.ts:176–261  ·  view source on GitHub ↗
(
  configFile: string,
  config: any,
  host: ConfigurationHost,
  fs: FileSystem,
  parseConfigHost: ts.ParseConfigHost,
  extendedConfigCache: Map<string, ts.ExtendedConfigCacheEntry>,
)

Source from the content-addressed store, hash-verified

174}
175
176function readAngularCompilerOptions(
177 configFile: string,
178 config: any,
179 host: ConfigurationHost,
180 fs: FileSystem,
181 parseConfigHost: ts.ParseConfigHost,
182 extendedConfigCache: Map<string, ts.ExtendedConfigCacheEntry>,
183): NgCompilerOptions {
184 const cacheKey = fs.isCaseSensitive() ? configFile : configFile.toLowerCase();
185 const cacheEntry = extendedConfigCache.get(cacheKey);
186 const cachedExtendedConfig = cacheEntry?.extendedConfig as
187 | (ts.ExtendedConfigCacheEntry['extendedConfig'] & {
188 angularCompilerOptions?: NgCompilerOptions;
189 })
190 | undefined;
191
192 // If the merged angularCompilerOptions for this config are already cached, reuse them.
193 if (cachedExtendedConfig?.angularCompilerOptions) {
194 return cachedExtendedConfig.angularCompilerOptions;
195 }
196
197 // Note: In Google, `angularCompilerOptions` are stored in `bazelOptions`.
198 // This function typically doesn't run for actual Angular compilations, but
199 // tooling like Tsurge, or schematics may leverage this helper, so we account
200 // for this here.
201 const angularCompilerOptions =
202 config.angularCompilerOptions ?? config.bazelOptions?.angularCompilerOptions ?? {};
203
204 if (!config.extends) {
205 if (cachedExtendedConfig) {
206 cachedExtendedConfig.angularCompilerOptions = angularCompilerOptions;
207 }
208 return angularCompilerOptions;
209 }
210
211 const resolvedExtendedConfigPath = cachedExtendedConfig?.extendedConfigPath;
212
213 const extendsPaths: string[] = resolvedExtendedConfigPath
214 ? typeof resolvedExtendedConfigPath === 'string'
215 ? [resolvedExtendedConfigPath]
216 : resolvedExtendedConfigPath
217 : typeof config.extends === 'string'
218 ? [config.extends]
219 : Array.isArray(config.extends)
220 ? config.extends
221 : [];
222
223 // Recursively merge extended configurations from base to leaf (left-to-right).
224 const inheritedOptions = extendsPaths.reduce((prevOptions, extendsPath) => {
225 const extendedConfigPath = resolvedExtendedConfigPath
226 ? absoluteFrom(extendsPath)
227 : getExtendedConfigPath(configFile, extendsPath, host, fs, parseConfigHost);
228 if (extendedConfigPath === null) {
229 return prevOptions;
230 }
231
232 const {config: extendedConfig, error} = readConfigFile(
233 extendedConfigPath,

Callers 1

readConfigurationFunction · 0.85

Calls 7

absoluteFromFunction · 0.90
getExtendedConfigPathFunction · 0.85
readConfigFileFunction · 0.85
isArrayMethod · 0.80
reduceMethod · 0.80
isCaseSensitiveMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected