Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #408 from ember-cli/cache-lazily
Browse files Browse the repository at this point in the history
Make cacheKey calculation lazy
  • Loading branch information
rwjblue authored Feb 5, 2021
2 parents 4a5c196 + a8c3398 commit 795cb9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions lib/ast-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ module.exports = {
global.EmberENV = clonedEmberENV;

let Compiler = require(templateCompilerPath);
let cacheKey = this.makeCacheKey(templateCompilerPath, pluginInfo);
let cacheKey;

let precompileInlineHTMLBarsPlugin;

pluginInfo.plugins.forEach((plugin) => Compiler.registerPlugin('ast', plugin));

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 }];
Expand Down

0 comments on commit 795cb9a

Please sign in to comment.