Skip to content

Commit d764651

Browse files
author
Robert Jackson
committed
Move check for already registred plugin to utils.
This makes it much easier to test (as it doesn't require any state from the addon instance).
1 parent ca0653f commit d764651

2 files changed

Lines changed: 29 additions & 36 deletions

File tree

lib/ember-addon-main.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ dBabelVersion: ${hasValidBabelVersion};`
135135

136136
// add the babel-plugin-htmlbars-inline-precompile to the list of plugins
137137
// used by `ember-cli-babel` addon
138-
if (!this._isInlinePrecompileBabelPluginRegistered(babelPlugins)) {
138+
if (!utils.isInlinePrecompileBabelPluginRegistered(babelPlugins)) {
139139
let pluginInfo = this.astPlugins();
140140
let templateCompilerPath = this.templateCompilerPath();
141141

@@ -194,41 +194,6 @@ dBabelVersion: ${hasValidBabelVersion};`
194194
}
195195
},
196196

197-
/**
198-
* This function checks if 'babel-plugin-htmlbars-inline-precompile' is already present in babelPlugins.
199-
* The plugin object will be different for non parallel API and parallel API.
200-
* For parallel api, check the `baseDir` of a plugin to see if it has current dirname
201-
* For non parallel api, check the 'modules' to see if it contains the babel plugin
202-
* @param {*} plugins
203-
*/
204-
_isInlinePrecompileBabelPluginRegistered(plugins) {
205-
return plugins.some(plugin => {
206-
if (Array.isArray(plugin)) {
207-
let [pluginPathOrInstance, options] = plugin;
208-
209-
return (
210-
pluginPathOrInstance === require.resolve('babel-plugin-htmlbars-inline-precompile') &&
211-
typeof options.modules === 'object' &&
212-
options.modules['ember-cli-htmlbars'] === 'hbs'
213-
);
214-
} else if (
215-
plugin !== null &&
216-
typeof plugin === 'object' &&
217-
plugin._parallelBabel !== undefined
218-
) {
219-
return (
220-
plugin._parallelBabel.requireFile ===
221-
path.resolve(__dirname, 'lib/require-from-worker') &&
222-
typeof plugin._parallelBabel.params === 'object' &&
223-
typeof plugin._parallelBabel.params.modules === 'object' &&
224-
plugin._parallelBabel.params.modules['ember-cli-htmlbars'] === 'hbs'
225-
);
226-
} else {
227-
return false;
228-
}
229-
});
230-
},
231-
232197
projectConfig() {
233198
return this.project.config(process.env.EMBER_ENV);
234199
},

lib/utils.js

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

10+
function isInlinePrecompileBabelPluginRegistered(plugins) {
11+
return plugins.some(plugin => {
12+
if (Array.isArray(plugin)) {
13+
let [pluginPathOrInstance, options] = plugin;
14+
15+
return (
16+
pluginPathOrInstance === require.resolve('babel-plugin-htmlbars-inline-precompile') &&
17+
typeof options.modules === 'object' &&
18+
options.modules['ember-cli-htmlbars'] === 'hbs'
19+
);
20+
} else if (
21+
plugin !== null &&
22+
typeof plugin === 'object' &&
23+
plugin._parallelBabel !== undefined
24+
) {
25+
return (
26+
plugin._parallelBabel.requireFile === path.resolve(__dirname, 'lib/require-from-worker') &&
27+
typeof plugin._parallelBabel.params === 'object' &&
28+
typeof plugin._parallelBabel.params.modules === 'object' &&
29+
plugin._parallelBabel.params.modules['ember-cli-htmlbars'] === 'hbs'
30+
);
31+
} else {
32+
return false;
33+
}
34+
});
35+
}
36+
1037
function buildOptions(projectConfig, templateCompilerPath, pluginInfo) {
1138
let EmberENV = projectConfig.EmberENV || {};
1239

@@ -221,4 +248,5 @@ module.exports = {
221248
setup,
222249
makeCacheKey,
223250
setupPlugins,
251+
isInlinePrecompileBabelPluginRegistered,
224252
};

0 commit comments

Comments
 (0)