Skip to content

Commit

Permalink
Support cache busting by AST plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Jackson committed Aug 10, 2016
1 parent f4f644c commit 18b58a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
36 changes: 30 additions & 6 deletions ember-addon-main.js
Expand Up @@ -3,6 +3,7 @@
var path = require('path');
var checker = require('ember-cli-version-checker');
var utils = require('./utils');
var hashForDep = require('hash-for-dep');

module.exports = {
name: 'ember-cli-htmlbars',
Expand Down Expand Up @@ -90,15 +91,19 @@ module.exports = {
delete require.cache[templateCompilerPath];

global.EmberENV = EmberENV; // Needed for eval time feature flag checks
var pluginInfo = this.astPlugins();

var htmlbarsOptions = {
isHTMLBars: true,
EmberENV: EmberENV,
templateCompiler: require(templateCompilerPath),
templateCompilerPath: templateCompilerPath,

plugins: {
ast: this.astPlugins()
}
ast: pluginInfo.plugins
},

pluginCacheKey: pluginInfo.cacheKeys
};

delete require.cache[templateCompilerPath];
Expand All @@ -110,10 +115,29 @@ module.exports = {

astPlugins: function() {
var pluginWrappers = this.parentRegistry.load('htmlbars-ast-plugin');
var plugins = pluginWrappers.map(function(wrapper) {
return wrapper.plugin;
});
var plugins = [];
var cacheKeys = [];

for (var i = 0; i < pluginWrappers.length; i++) {
var wrapper = pluginWrappers[i];

return plugins;
plugins.push(wrapper.plugin);

if (typeof wrapper.baseDir === 'function') {
var pluginHashForDep = hashForDep(wrapper.baseDir());
cacheKeys.push(pluginHashForDep);
} else {
// support for ember-cli < 2.2.0
var log = this.ui.writeDeprecateLine || this.ui.writeLine;

log.call(this.ui, 'ember-cli-htmlbars is opting out of caching due to an AST plugin that does not provide a caching strategy: `' + wrapper.name + '`.');
cacheKeys.push((new Date()).getTime() + '|' + Math.random());
}
}

return {
plugins: plugins,
cacheKeys: cacheKeys
};
}
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"broccoli-persistent-filter": "^1.0.3",
"ember-cli-version-checker": "^1.0.2",
"hash-for-dep": "^1.0.2",
"json-stable-stringify": "^1.0.0",
"strip-bom": "^2.0.0"
}
Expand Down

0 comments on commit 18b58a9

Please sign in to comment.