Skip to content

Commit

Permalink
Conditionally add Babel 5 or Babel 6 plugin to the host app
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Mar 27, 2017
1 parent 993229b commit 680d432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-env node */

const VersionChecker = require('ember-cli-version-checker');

module.exports = {
name: 'ember-test-selectors',

Expand Down Expand Up @@ -54,11 +56,20 @@ module.exports = {
// add the StripDataTestPropertiesPlugin to the list of plugins used by
// the `ember-cli-babel` addon
if (this._stripTestSelectors && !this._registeredWithBabel) {
let checker = new VersionChecker(this).for('ember-cli-babel', 'npm');

app.options = app.options || {};
app.options.babel = app.options.babel || {};
app.options.babel.plugins = app.options.babel.plugins || [];

app.options.babel.plugins.push(require('./strip-data-test-properties-plugin'));
if (checker.satisfies('^5.0.0')) {
app.options.babel.plugins.push(require('./strip-data-test-properties-plugin'));
} else if (checker.satisfies('^6.0.0')) {
app.options.babel.plugins.push(require('./strip-data-test-properties-plugin6'));
} else {
this.ui.writeWarnLine('ember-test-selectors: You are using an unsupported ember-cli-babel version. data-test' +
'properties are not automatically stripped from your JS code.')
}

this._registeredWithBabel = true;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"test:strip": "STRIP_TEST_SELECTORS=true ember test"
},
"dependencies": {
"ember-cli-babel": "^5.1.7"
"ember-cli-babel": "^5.1.7",
"ember-cli-version-checker": "^1.2.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand Down

0 comments on commit 680d432

Please sign in to comment.