Skip to content

Commit

Permalink
fix(@angular/cli): cache config by file path. (#4902)
Browse files Browse the repository at this point in the history
On some commands we create multiple configs; this will cache them and reuse the ones that exist already.
  • Loading branch information
hansl authored and filipesilva committed Feb 22, 2017
1 parent b521ae5 commit 198d27a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/@angular/cli/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down Expand Up @@ -63,6 +70,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
`));
}

configCacheMap.set(globalConfigPath, cliConfig);
return cliConfig;
}

Expand All @@ -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);
Expand Down Expand Up @@ -106,6 +117,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
`));
}

configCacheMap.set(configPath, cliConfig);
return cliConfig as CliConfig;
}
}

0 comments on commit 198d27a

Please sign in to comment.