Skip to content

Commit e7030a4

Browse files
hanslZhicheng Wang
authored andcommitted
fix(@angular/cli): cache config by file path. (angular#4902)
On some commands we create multiple configs; this will cache them and reuse the ones that exist already.
1 parent 627a17c commit e7030a4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

packages/@angular/cli/models/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function getUserHome() {
1717
}
1818

1919

20+
const configCacheMap = new Map<string, CliConfigBase<ConfigInterface>>();
21+
22+
2023
export class CliConfig extends CliConfigBase<ConfigInterface> {
2124
static configFilePath(projectPath?: string): string {
2225
// Find the configuration, either where specified, in the Angular CLI project
@@ -36,6 +39,10 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
3639
globalConfigPath = altGlobalConfigPath;
3740
}
3841

42+
if (configCacheMap.has(globalConfigPath)) {
43+
return configCacheMap.get(globalConfigPath);
44+
}
45+
3946
const cliConfig = CliConfigBase.fromConfigPath<ConfigInterface>(globalConfigPath);
4047

4148
const aliases = [
@@ -63,6 +70,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
6370
`));
6471
}
6572

73+
configCacheMap.set(globalConfigPath, cliConfig);
6674
return cliConfig;
6775
}
6876

@@ -71,6 +79,9 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
7179
if (!configPath) {
7280
return null;
7381
}
82+
if (configCacheMap.has(configPath)) {
83+
return configCacheMap.get(configPath);
84+
}
7485

7586
let globalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME);
7687
const altGlobalConfigPath = path.join(getUserHome(), CLI_CONFIG_FILE_NAME_ALT);
@@ -106,6 +117,7 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
106117
`));
107118
}
108119

120+
configCacheMap.set(configPath, cliConfig);
109121
return cliConfig as CliConfig;
110122
}
111123
}

0 commit comments

Comments
 (0)