Skip to content

Commit 4b2f2a5

Browse files
author
Robert Jackson
committed
More fixes for proper babel plugin deduplication.
Ensure that the actual output used by the `included` hook when parallelizable returns `true` for `isInlinePrecompileBabelPluginRegistered`. Previously, we had a mismatch between `path.join(__dirname, 'require-from-worker')` and `require.resolve('./require-from-worker')` because `require.resolve` includes the extension.
1 parent 46d7ae4 commit 4b2f2a5

3 files changed

Lines changed: 38 additions & 40 deletions

File tree

lib/ember-addon-main.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,45 +139,22 @@ dBabelVersion: ${hasValidBabelVersion};`
139139
let pluginInfo = this.astPlugins();
140140
let templateCompilerPath = this.templateCompilerPath();
141141

142-
let modules = {
143-
'ember-cli-htmlbars': 'hbs',
144-
'ember-cli-htmlbars-inline-precompile': 'default',
145-
'htmlbars-inline-precompile': 'default',
146-
};
147-
148142
if (pluginInfo.canParallelize) {
149143
logger.debug('using parallel API with for babel inline precompilation plugin');
150144

151-
let parallelBabelInfo = {
152-
requireFile: path.join(__dirname, 'require-from-worker'),
153-
buildUsing: 'build',
154-
params: {
155-
templateCompilerPath,
156-
parallelConfigs: pluginInfo.parallelConfigs,
157-
modules,
158-
},
159-
};
160-
161-
// parallelBabelInfo will not be used in the cache unless it is explicitly included
162-
let cacheKey = utils.makeCacheKey(
163-
templateCompilerPath,
145+
let htmlbarsInlinePrecompilePlugin = utils.buildParalleizedBabelPlugin(
164146
pluginInfo,
165-
JSON.stringify(parallelBabelInfo)
147+
templateCompilerPath
166148
);
167149

168-
babelPlugins.push({
169-
_parallelBabel: parallelBabelInfo,
170-
baseDir: () => __dirname,
171-
cacheKey: () => cacheKey,
172-
});
150+
babelPlugins.push(htmlbarsInlinePrecompilePlugin);
173151
} else {
174152
logger.debug('NOT using parallel API with for babel inline precompilation plugin');
175153
logger.debug('Prevented by these plugins: ' + pluginInfo.unparallelizableWrappers);
176154

177155
let htmlBarsPlugin = utils.setup(pluginInfo, {
178156
projectConfig: this.projectConfig(),
179157
templateCompilerPath,
180-
modules,
181158
});
182159

183160
babelPlugins.push(htmlBarsPlugin);

lib/utils.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const debugGenerator = require('heimdalljs-logger');
77
const logger = debugGenerator('ember-cli-htmlbars:utils');
88
const addDependencyTracker = require('./addDependencyTracker');
99

10+
const INLINE_PRECOMPILE_MODULES = Object.freeze({
11+
'ember-cli-htmlbars': 'hbs',
12+
'ember-cli-htmlbars-inline-precompile': 'default',
13+
'htmlbars-inline-precompile': 'default',
14+
});
15+
1016
function isInlinePrecompileBabelPluginRegistered(plugins) {
1117
return plugins.some(plugin => {
1218
if (Array.isArray(plugin)) {
@@ -40,6 +46,27 @@ function isColocatedBabelPluginRegistered(plugins) {
4046
);
4147
}
4248

49+
function buildParalleizedBabelPlugin(pluginInfo, templateCompilerPath) {
50+
let parallelBabelInfo = {
51+
requireFile: require.resolve('./require-from-worker'),
52+
buildUsing: 'build',
53+
params: {
54+
templateCompilerPath,
55+
parallelConfigs: pluginInfo.parallelConfigs,
56+
modules: INLINE_PRECOMPILE_MODULES,
57+
},
58+
};
59+
60+
// parallelBabelInfo will not be used in the cache unless it is explicitly included
61+
let cacheKey = makeCacheKey(templateCompilerPath, pluginInfo, JSON.stringify(parallelBabelInfo));
62+
63+
return {
64+
_parallelBabel: parallelBabelInfo,
65+
baseDir: () => __dirname,
66+
cacheKey: () => cacheKey,
67+
};
68+
}
69+
4370
function buildOptions(projectConfig, templateCompilerPath, pluginInfo) {
4471
let EmberENV = projectConfig.EmberENV || {};
4572

@@ -171,7 +198,7 @@ function setup(pluginInfo, options) {
171198

172199
let plugin = [
173200
require.resolve('babel-plugin-htmlbars-inline-precompile'),
174-
{ precompile, modules: options.modules },
201+
{ precompile, modules: INLINE_PRECOMPILE_MODULES },
175202
'ember-cli-htmlbars:inline-precompile',
176203
];
177204

@@ -256,4 +283,5 @@ module.exports = {
256283
setupPlugins,
257284
isColocatedBabelPluginRegistered,
258285
isInlinePrecompileBabelPluginRegistered,
286+
buildParalleizedBabelPlugin,
259287
};

node-tests/utils_test.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,12 @@ describe('utils', function() {
128128
'ember-cli-htmlbars:inline-precompile',
129129
];
130130

131-
parallelizablePlugin = {
132-
baseDir: () => __dirname,
133-
cacheKey: () => `${Date.now()}`,
134-
_parallelBabel: {
135-
requireFile: require.resolve('../lib/require-from-worker'),
136-
buildUsing: 'build',
137-
params: {
138-
templateCompilerPath: null,
139-
parallelConfigs: [],
140-
modules,
141-
},
142-
},
143-
};
131+
let pluginInfo = { parallelConfigs: [], cacheKeys: [] };
132+
parallelizablePlugin = utils.buildParalleizedBabelPlugin(
133+
pluginInfo,
134+
require.resolve('ember-source/dist/ember-template-compiler')
135+
);
136+
144137
[
145138
require.resolve('babel-plugin-htmlbars-inline-precompile'),
146139
{ precompile: null, modules },

0 commit comments

Comments
 (0)