Skip to content

Commit

Permalink
More fixes for proper babel plugin deduplication. (#324)
Browse files Browse the repository at this point in the history
More fixes for proper babel plugin deduplication.
  • Loading branch information
rwjblue authored Oct 4, 2019
2 parents 16e8b13 + 4b2f2a5 commit edeb553
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
29 changes: 3 additions & 26 deletions lib/ember-addon-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,45 +139,22 @@ dBabelVersion: ${hasValidBabelVersion};`
let pluginInfo = this.astPlugins();
let templateCompilerPath = this.templateCompilerPath();

let modules = {
'ember-cli-htmlbars': 'hbs',
'ember-cli-htmlbars-inline-precompile': 'default',
'htmlbars-inline-precompile': 'default',
};

if (pluginInfo.canParallelize) {
logger.debug('using parallel API with for babel inline precompilation plugin');

let parallelBabelInfo = {
requireFile: path.join(__dirname, 'require-from-worker'),
buildUsing: 'build',
params: {
templateCompilerPath,
parallelConfigs: pluginInfo.parallelConfigs,
modules,
},
};

// parallelBabelInfo will not be used in the cache unless it is explicitly included
let cacheKey = utils.makeCacheKey(
templateCompilerPath,
let htmlbarsInlinePrecompilePlugin = utils.buildParalleizedBabelPlugin(
pluginInfo,
JSON.stringify(parallelBabelInfo)
templateCompilerPath
);

babelPlugins.push({
_parallelBabel: parallelBabelInfo,
baseDir: () => __dirname,
cacheKey: () => cacheKey,
});
babelPlugins.push(htmlbarsInlinePrecompilePlugin);
} else {
logger.debug('NOT using parallel API with for babel inline precompilation plugin');
logger.debug('Prevented by these plugins: ' + pluginInfo.unparallelizableWrappers);

let htmlBarsPlugin = utils.setup(pluginInfo, {
projectConfig: this.projectConfig(),
templateCompilerPath,
modules,
});

babelPlugins.push(htmlBarsPlugin);
Expand Down
30 changes: 29 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const debugGenerator = require('heimdalljs-logger');
const logger = debugGenerator('ember-cli-htmlbars:utils');
const addDependencyTracker = require('./addDependencyTracker');

const INLINE_PRECOMPILE_MODULES = Object.freeze({
'ember-cli-htmlbars': 'hbs',
'ember-cli-htmlbars-inline-precompile': 'default',
'htmlbars-inline-precompile': 'default',
});

function isInlinePrecompileBabelPluginRegistered(plugins) {
return plugins.some(plugin => {
if (Array.isArray(plugin)) {
Expand Down Expand Up @@ -40,6 +46,27 @@ function isColocatedBabelPluginRegistered(plugins) {
);
}

function buildParalleizedBabelPlugin(pluginInfo, templateCompilerPath) {
let parallelBabelInfo = {
requireFile: require.resolve('./require-from-worker'),
buildUsing: 'build',
params: {
templateCompilerPath,
parallelConfigs: pluginInfo.parallelConfigs,
modules: INLINE_PRECOMPILE_MODULES,
},
};

// parallelBabelInfo will not be used in the cache unless it is explicitly included
let cacheKey = makeCacheKey(templateCompilerPath, pluginInfo, JSON.stringify(parallelBabelInfo));

return {
_parallelBabel: parallelBabelInfo,
baseDir: () => __dirname,
cacheKey: () => cacheKey,
};
}

function buildOptions(projectConfig, templateCompilerPath, pluginInfo) {
let EmberENV = projectConfig.EmberENV || {};

Expand Down Expand Up @@ -171,7 +198,7 @@ function setup(pluginInfo, options) {

let plugin = [
require.resolve('babel-plugin-htmlbars-inline-precompile'),
{ precompile, modules: options.modules },
{ precompile, modules: INLINE_PRECOMPILE_MODULES },
'ember-cli-htmlbars:inline-precompile',
];

Expand Down Expand Up @@ -256,4 +283,5 @@ module.exports = {
setupPlugins,
isColocatedBabelPluginRegistered,
isInlinePrecompileBabelPluginRegistered,
buildParalleizedBabelPlugin,
};
19 changes: 6 additions & 13 deletions node-tests/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,12 @@ describe('utils', function() {
'ember-cli-htmlbars:inline-precompile',
];

parallelizablePlugin = {
baseDir: () => __dirname,
cacheKey: () => `${Date.now()}`,
_parallelBabel: {
requireFile: require.resolve('../lib/require-from-worker'),
buildUsing: 'build',
params: {
templateCompilerPath: null,
parallelConfigs: [],
modules,
},
},
};
let pluginInfo = { parallelConfigs: [], cacheKeys: [] };
parallelizablePlugin = utils.buildParalleizedBabelPlugin(
pluginInfo,
require.resolve('ember-source/dist/ember-template-compiler')
);

[
require.resolve('babel-plugin-htmlbars-inline-precompile'),
{ precompile: null, modules },
Expand Down

0 comments on commit edeb553

Please sign in to comment.