Skip to content

Commit 0614548

Browse files
thymikeeEsemesek
authored andcommitted
fix: cache lazy project getter for perf when accessed repeatedly (#520)
1 parent f81f53b commit 0614548

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/cli/src/tools/config/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function getDependencyConfig(
6464
* Loads CLI configuration
6565
*/
6666
function loadConfig(projectRoot: string = process.cwd()): ConfigT {
67+
let lazyProject;
6768
const userConfig = readConfigFromDisk(projectRoot);
6869

6970
const initialConfig: ConfigT = {
@@ -84,14 +85,19 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
8485
platforms: Object.keys(userConfig.platforms),
8586
},
8687
get project() {
87-
const project = {};
88+
if (lazyProject) {
89+
return lazyProject;
90+
}
91+
92+
lazyProject = {};
8893
for (const platform in finalConfig.platforms) {
89-
project[platform] = finalConfig.platforms[platform].projectConfig(
94+
lazyProject[platform] = finalConfig.platforms[platform].projectConfig(
9095
projectRoot,
9196
userConfig.project[platform] || {},
9297
);
9398
}
94-
return project;
99+
100+
return lazyProject;
95101
},
96102
};
97103

0 commit comments

Comments
 (0)