Skip to content

Commit eca93f2

Browse files
author
Robert Jackson
committed
Move check for colocated babel plugin to utils
* extract for easier testing * remove unused utility package ember-cli-babel-plugin-helpers * add tests (these previously failed 😭)
1 parent 1f79c89 commit eca93f2

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

lib/ember-addon-main.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,8 @@ dBabelVersion: ${hasValidBabelVersion};`
184184
}
185185
}
186186

187-
if (this._shouldColocateTemplates()) {
188-
const { hasPlugin, addPlugin } = require('ember-cli-babel-plugin-helpers');
189-
let colocatedPluginPath = require.resolve('./colocated-babel-plugin');
190-
191-
if (!hasPlugin(babelPlugins, colocatedPluginPath)) {
192-
addPlugin(babelPlugins, colocatedPluginPath);
193-
}
187+
if (this._shouldColocateTemplates() && !utils.isColocatedBabelPluginRegistered(babelPlugins)) {
188+
babelPlugins.push(require.resolve('./colocated-babel-plugin'));
194189
}
195190
},
196191

lib/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function isInlinePrecompileBabelPluginRegistered(plugins) {
3434
});
3535
}
3636

37+
function isColocatedBabelPluginRegistered(plugins) {
38+
return plugins.some(
39+
plugin => typeof plugin === 'string' && plugin === require.resolve('./colocated-babel-plugin')
40+
);
41+
}
42+
3743
function buildOptions(projectConfig, templateCompilerPath, pluginInfo) {
3844
let EmberENV = projectConfig.EmberENV || {};
3945

@@ -248,5 +254,6 @@ module.exports = {
248254
setup,
249255
makeCacheKey,
250256
setupPlugins,
257+
isColocatedBabelPluginRegistered,
251258
isInlinePrecompileBabelPluginRegistered,
252259
};

node-tests/utils_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,18 @@ describe('utils', function() {
166166
assert.strictEqual(utils.isInlinePrecompileBabelPluginRegistered(plugins), true);
167167
});
168168
});
169+
170+
describe('isColocatedBabelPluginRegistered', function() {
171+
it('is false when no plugins exist', function() {
172+
let plugins = [];
173+
174+
assert.strictEqual(utils.isColocatedBabelPluginRegistered(plugins), false);
175+
});
176+
177+
it('detects when the plugin exists', function() {
178+
let plugins = [require.resolve('../lib/colocated-babel-plugin')];
179+
180+
assert.strictEqual(utils.isColocatedBabelPluginRegistered(plugins), true);
181+
});
182+
});
169183
});

0 commit comments

Comments
 (0)