Skip to content

Commit

Permalink
Avoid building the template compiler cache key repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Feb 26, 2021
1 parent 72e6a6e commit 5115d4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/template-compiler-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TemplateCompiler extends Filter {
this._optionsHash = crypto
.createHash('md5')
.update(stringify(this._buildOptionsForHash()), 'utf8')
.update(stringify(this._templateCompilerContents()), 'utf8')
.update(utils.getTemplateCompilerCacheKey(this.options.templateCompilerPath), 'utf8')
.digest('hex');
}

Expand Down
8 changes: 7 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,15 @@ function setup(pluginInfo, options) {
return plugin;
}

function makeCacheKey(templateCompilerPath, pluginInfo, extra) {
function getTemplateCompilerCacheKey(templateCompilerPath) {
let templateCompilerFullPath = require.resolve(templateCompilerPath);
let { templateCompilerCacheKey } = TemplateCompilerCache.get(templateCompilerFullPath);

return templateCompilerCacheKey;
}

function makeCacheKey(templateCompilerPath, pluginInfo, extra) {
let templateCompilerCacheKey = getTemplateCompilerCacheKey(templateCompilerPath);
let cacheItems = [templateCompilerCacheKey, extra].concat(pluginInfo.cacheKeys.sort());

// extra may be undefined
Expand Down Expand Up @@ -347,4 +352,5 @@ module.exports = {
isInlinePrecompileBabelPluginRegistered,
buildParalleizedBabelPlugin,
getTemplateCompiler,
getTemplateCompilerCacheKey,
};

0 comments on commit 5115d4b

Please sign in to comment.