From 198d27a88eae3c29e5fc7ef5cfa360c5d0d0b401 Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 22 Feb 2017 03:50:01 -0800 Subject: [PATCH] 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. --- packages/@angular/cli/models/config.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/@angular/cli/models/config.ts b/packages/@angular/cli/models/config.ts index e856e3336ae7..ce30348ae169 100644 --- a/packages/@angular/cli/models/config.ts +++ b/packages/@angular/cli/models/config.ts @@ -17,6 +17,9 @@ function getUserHome() { } +const configCacheMap = new Map>(); + + export class CliConfig extends CliConfigBase { 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 { globalConfigPath = altGlobalConfigPath; } + if (configCacheMap.has(globalConfigPath)) { + return configCacheMap.get(globalConfigPath); + } + const cliConfig = CliConfigBase.fromConfigPath(globalConfigPath); const aliases = [ @@ -63,6 +70,7 @@ export class CliConfig extends CliConfigBase { `)); } + configCacheMap.set(globalConfigPath, cliConfig); return cliConfig; } @@ -71,6 +79,9 @@ export class CliConfig extends CliConfigBase { 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 { `)); } + configCacheMap.set(configPath, cliConfig); return cliConfig as CliConfig; } }