Skip to content

Commit 47041c9

Browse files
committed
Avoid building the template compiler cache key repeatedly
1 parent 72e6a6e commit 47041c9

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-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
@@ -262,10 +262,20 @@ function setup(pluginInfo, options) {
262262
return plugin;
263263
}
264264

265-
function makeCacheKey(templateCompilerPath, pluginInfo, extra) {
265+
function getTemplateCompilerCacheKey(templateCompilerPath) {
266266
let templateCompilerFullPath = require.resolve(templateCompilerPath);
267-
let { templateCompilerCacheKey } = TemplateCompilerCache.get(templateCompilerFullPath);
267+
let cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
268+
269+
if (cacheData === undefined) {
270+
getTemplateCompiler(templateCompilerFullPath);
271+
cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
272+
}
273+
274+
return cacheData.templateCompilerCacheKey;
275+
}
268276

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

271281
// extra may be undefined
@@ -347,4 +357,5 @@ module.exports = {
347357
isInlinePrecompileBabelPluginRegistered,
348358
buildParalleizedBabelPlugin,
349359
getTemplateCompiler,
360+
getTemplateCompilerCacheKey,
350361
};

node-tests/addon-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ describe('ember-cli-htmlbars addon', function () {
7777
let htmlbarsOptions = {
7878
isHTMLBars: true,
7979
templateCompiler: require('ember-source/dist/ember-template-compiler.js'),
80+
templateCompilerPath: require.resolve('ember-source/dist/ember-template-compiler.js'),
8081
};
8182

8283
subject = this.addon.transpileTree(input.path(), htmlbarsOptions);

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
@@ -41,6 +41,7 @@ describe('TemplateCompiler', function () {
4141
ast: [],
4242
},
4343
templateCompiler: require('ember-source/dist/ember-template-compiler.js'),
44+
templateCompilerPath: require.resolve('ember-source/dist/ember-template-compiler.js'),
4445
};
4546

4647
htmlbarsPrecompile = htmlbarsOptions.templateCompiler.precompile;

0 commit comments

Comments
 (0)