fix(@angular/cli): cache config by file path. (#4902)

On some commands we create multiple configs; this will cache them and reuse the ones that exist already.
This commit is contained in:
Hans 2017-02-22 03:50:01 -08:00 committed by Filipe Silva
parent b521ae5db2
commit 198d27a88e

View File

@ -17,6 +17,9 @@ function getUserHome() {
}
const configCacheMap = new Map<string, CliConfigBase<ConfigInterface>>();
export class CliConfig extends CliConfigBase<ConfigInterface> {
static configFilePath(projectPath?: string): string {
// Find the configuration, either where specified, in the Angular CLI project
@ -36,6 +39,10 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
globalConfigPath = altGlobalConfigPath;
}
if (configCacheMap.has(globalConfigPath)) {
return configCacheMap.get(globalConfigPath);
}
const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(globalConfigPath);
const aliases = [
@ -63,6 +70,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
`));
}
configCacheMap.set(globalConfigPath, cliConfig);
return cliConfig;
}
@ -71,6 +79,9 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
if (!configPath) {
return null;
}
if (configCacheMap.has(configPath)) {
return configCacheMap.get(configPath);
}
let globalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME);
const altGlobalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME_ALT);
@ -106,6 +117,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
`));
}
configCacheMap.set(configPath, cliConfig);
return cliConfig as CliConfig;
}
}