From 007211810a0c6a6db436fd2df948f5033c6f9fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 11 Jul 2019 12:29:58 +0200 Subject: [PATCH] fix: cache lazy project getter for perf when accessed repeatedly --- packages/cli/src/tools/config/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/tools/config/index.js b/packages/cli/src/tools/config/index.js index c7aa9a691..08afb4e72 100644 --- a/packages/cli/src/tools/config/index.js +++ b/packages/cli/src/tools/config/index.js @@ -64,6 +64,7 @@ function getDependencyConfig( * Loads CLI configuration */ function loadConfig(projectRoot: string = process.cwd()): ConfigT { + let lazyProject; const userConfig = readConfigFromDisk(projectRoot); const initialConfig: ConfigT = { @@ -84,14 +85,19 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT { platforms: Object.keys(userConfig.platforms), }, get project() { - const project = {}; + if (lazyProject) { + return lazyProject; + } + + lazyProject = {}; for (const platform in finalConfig.platforms) { - project[platform] = finalConfig.platforms[platform].projectConfig( + lazyProject[platform] = finalConfig.platforms[platform].projectConfig( projectRoot, userConfig.project[platform] || {}, ); } - return project; + + return lazyProject; }, };