Skip to content

Commit 64448c0

Browse files
rwjblueRobert Jackson
authored andcommitted
Avoid building the template compiler cache key repeatedly
(cherry picked from commit 47041c9)
1 parent 2798c0b commit 64448c0

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

lib/template-compiler-plugin.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const fs = require('fs');
43
const path = require('path');
54
const utils = require('./utils');
65
const Filter = require('broccoli-persistent-filter');
@@ -105,20 +104,16 @@ class TemplateCompiler extends Filter {
105104
return strippedOptions;
106105
}
107106

108-
_templateCompilerContents() {
109-
if (this.options.templateCompilerPath) {
110-
return fs.readFileSync(this.options.templateCompilerPath, { encoding: 'utf8' });
111-
} else {
112-
return '';
113-
}
114-
}
115-
116107
optionsHash() {
117108
if (!this._optionsHash) {
109+
let templateCompilerCacheKey = utils.getTemplateCompilerCacheKey(
110+
this.options.templateCompilerPath
111+
);
112+
118113
this._optionsHash = crypto
119114
.createHash('md5')
120115
.update(stringify(this._buildOptionsForHash()), 'utf8')
121-
.update(stringify(this._templateCompilerContents()), 'utf8')
116+
.update(templateCompilerCacheKey, 'utf8')
122117
.digest('hex');
123118
}
124119

lib/utils.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,20 @@ function setup(pluginInfo, options) {
225225
return plugin;
226226
}
227227

228-
function makeCacheKey(templateCompilerPath, pluginInfo, extra) {
228+
function getTemplateCompilerCacheKey(templateCompilerPath) {
229229
let templateCompilerFullPath = require.resolve(templateCompilerPath);
230-
let { templateCompilerCacheKey } = TemplateCompilerCache.get(templateCompilerFullPath);
230+
let cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
231+
232+
if (cacheData === undefined) {
233+
getTemplateCompiler(templateCompilerFullPath);
234+
cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
235+
}
236+
237+
return cacheData.templateCompilerCacheKey;
238+
}
231239

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

234244
// extra may be undefined
@@ -306,4 +316,5 @@ module.exports = {
306316
isInlinePrecompileBabelPluginRegistered,
307317
buildParalleizedBabelPlugin,
308318
getTemplateCompiler,
319+
getTemplateCompilerCacheKey,
309320
};

node-tests/ast_plugins_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('AST plugins', function() {
2626
htmlbarsOptions = {
2727
isHTMLBars: true,
2828
templateCompiler: templateCompiler,
29+
templateCompilerPath: require.resolve('ember-source/dist/ember-template-compiler.js'),
2930
};
3031
})
3132
);

node-tests/template_compiler_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('TemplateCompiler', function() {
3838
htmlbarsOptions = {
3939
isHTMLBars: true,
4040
templateCompiler: require('ember-source/dist/ember-template-compiler.js'),
41+
templateCompilerPath: require.resolve('ember-source/dist/ember-template-compiler.js'),
4142
};
4243

4344
htmlbarsPrecompile = htmlbarsOptions.templateCompiler.precompile;

0 commit comments

Comments
 (0)