Skip to content

Commit

Permalink
Ensure inline compile runs AST plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Sep 28, 2019
1 parent f735a40 commit 0e05534
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
14 changes: 2 additions & 12 deletions lib/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ module.exports = {
// add the babel-plugin-htmlbars-inline-precompile to the list of plugins
// used by `ember-cli-babel` addon
if (!this._isInlinePrecompileBabelPluginRegistered(babelPlugins)) {
let pluginWrappers = this.astPlugins();
let pluginInfo = this.astPlugins();
let templateCompilerPath = this.templateCompilerPath();
let pluginInfo = utils.setupPlugins(pluginWrappers);

let modules = {
'ember-cli-htmlbars': 'hbs',
Expand Down Expand Up @@ -137,16 +136,7 @@ module.exports = {
});
} else {
logger.debug('NOT using parallel API with for babel inline precompilation plugin');

let blockingPlugins = pluginWrappers
.map(wrapper => {
if (wrapper.parallelBabel === undefined) {
return wrapper.name;
}
})
.filter(Boolean);

logger.debug('Prevented by these plugins: ' + blockingPlugins);
logger.debug('Prevented by these plugins: ' + pluginInfo.unparallelizableWrappers);

let htmlBarsPlugin = utils.setup(pluginInfo, {
projectConfig: this.projectConfig(),
Expand Down
8 changes: 6 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function template(templateCompiler, string, options) {
}

function setup(pluginInfo, options) {
// borrowed from ember-cli-htmlbars http://git.io/vJDrW
let projectConfig = options.projectConfig || {};
let templateCompilerPath = options.templateCompilerPath;

Expand All @@ -129,7 +128,9 @@ function setup(pluginInfo, options) {

let cacheKey = makeCacheKey(templateCompilerPath, pluginInfo);

registerPlugins(templateCompiler, pluginInfo.plugins);
registerPlugins(templateCompiler, {
ast: pluginInfo.plugins,
});

let { precompile } = templateCompiler;
precompile.baseDir = () => path.resolve(__dirname, '..');
Expand All @@ -156,6 +157,7 @@ function setupPlugins(wrappers) {
let plugins = [];
let cacheKeys = [];
let parallelConfigs = [];
let unparallelizableWrappers = [];
let dependencyInvalidation = false;
let canParallelize = true;

Expand All @@ -170,6 +172,7 @@ function setupPlugins(wrappers) {
if (wrapper.parallelBabel) {
parallelConfigs.push(wrapper.parallelBabel);
} else {
unparallelizableWrappers.push(wrapper.name);
canParallelize = false;
}

Expand Down Expand Up @@ -203,6 +206,7 @@ function setupPlugins(wrappers) {
cacheKeys,
parallelConfigs,
canParallelize,
unparallelizableWrappers,
hasDependencyInvalidation: !!dependencyInvalidation,
};
}
Expand Down
5 changes: 5 additions & 0 deletions node-tests/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('utils', function() {
cacheKeys: [],
parallelConfigs: [],
canParallelize: true,
unparallelizableWrappers: [],
hasDependencyInvalidation: false,
});
});
Expand Down Expand Up @@ -74,20 +75,23 @@ describe('utils', function() {
cacheKeys: ['something', 'something else'],
parallelConfigs: ['something', 'something else'],
canParallelize: true,
unparallelizableWrappers: [],
hasDependencyInvalidation: false,
});
});

it('canParallelize is false for 1+ plugins without "parallelBabel" property', function() {
let pluginWrappers = [
{
name: 'first',
plugin() {},
cacheKey() {
return this.parallelBabel;
},
parallelBabel: 'something',
},
{
name: 'second',
plugin() {},
cacheKey() {
return 'something else';
Expand All @@ -102,6 +106,7 @@ describe('utils', function() {
cacheKeys: ['something', 'something else'],
parallelConfigs: ['something'],
canParallelize: false,
unparallelizableWrappers: ['second'],
hasDependencyInvalidation: false,
});
});
Expand Down

0 comments on commit 0e05534

Please sign in to comment.