From a8c3398f7fc518c9ff21717431a0f4b036620e99 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 5 Feb 2021 17:23:07 -0500 Subject: [PATCH] Make cacheKey calculation lazy Co-authored-by: Kris Selden --- index.js | 13 ++++++++++--- lib/ast-plugins.js | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b91d8ed6..9d6555de 100644 --- a/index.js +++ b/index.js @@ -78,12 +78,19 @@ module.exports = { parallelConfig } }; - // parallelBabelInfo will not be used in the cache unless it is explicitly included - let cacheKey = AstPlugins.makeCacheKey(templateCompilerPath, pluginInfo, JSON.stringify(parallelBabelInfo)); + + let cacheKey; babelPlugins.push({ _parallelBabel: parallelBabelInfo, baseDir: () => __dirname, - cacheKey: () => cacheKey, + cacheKey: () => { + if (cacheKey === undefined) { + // parallelBabelInfo will not be used in the cache unless it is explicitly included + cacheKey = AstPlugins.makeCacheKey(templateCompilerPath, pluginInfo, JSON.stringify(parallelBabelInfo)); + } + + return cacheKey; + }, }); } else { diff --git a/lib/ast-plugins.js b/lib/ast-plugins.js index 72fd9ba5..de72593c 100644 --- a/lib/ast-plugins.js +++ b/lib/ast-plugins.js @@ -53,7 +53,7 @@ module.exports = { global.EmberENV = clonedEmberENV; let Compiler = require(templateCompilerPath); - let cacheKey = this.makeCacheKey(templateCompilerPath, pluginInfo); + let cacheKey; let precompileInlineHTMLBarsPlugin; @@ -61,7 +61,13 @@ module.exports = { let precompile = Compiler.precompile; precompile.baseDir = () => path.resolve(__dirname, '..'); - precompile.cacheKey = () => cacheKey; + precompile.cacheKey = () => { + if (cacheKey === undefined) { + cacheKey = this.makeCacheKey(templateCompilerPath, pluginInfo); + } + + return cacheKey; + }; let modulePaths = ['ember-cli-htmlbars-inline-precompile', 'htmlbars-inline-precompile']; precompileInlineHTMLBarsPlugin = [HTMLBarsInlinePrecompilePlugin, { precompile, modulePaths }];