Skip to content

Commit

Permalink
feat: making ember-on-modifier a true polyfill (#57)
Browse files Browse the repository at this point in the history
* Making ember-on-modifier a true polyfill.

Uses ember-cli-version-checker to determine if the modifier should included in the addon tree. If the modifier is not included and ember-event-helpers is installed, a message is displayed that ember-on-modifier can be removed from a project's depenendencies.

* Improving deprecation messaging.

* Fixing typo in tree funnel logic.
  • Loading branch information
Garrett Murphey authored and buschtoens committed May 9, 2019
1 parent 75f2aa6 commit 0c93c82
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 164 deletions.
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

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

module.exports = {
Expand All @@ -8,9 +9,26 @@ module.exports = {
included(...args) {
this._super.included.apply(this, args);

const checker = new VersionChecker(this.project);
const ember = checker.forEmber();

this.hasNativeOnModifier = ember.gte('3.11.0-beta.1');

this.hasEventHelpers = Boolean(
this.project.findAddonByName('ember-event-helpers')
);

if (this.hasNativeOnModifier && this.parent === this.project) {
let message =
'The `{{on}}` modifier is available natively since Ember 3.11.0-beta.1. You can remove `ember-on-modifier` from your `package.json`.';

if (!this.hasEventHelpers) {
message +=
' If you use the `(prevent-default)` helper, please install `ember-event-helpers`.';
}

this.ui.writeDeprecateLine(message);
}
},

treeForApp(...args) {
Expand All @@ -22,10 +40,15 @@ module.exports = {
},

filterTree(tree) {
const exclude = [];

if (this.hasNativeOnModifier) {
exclude.push(/modifiers/);
}
if (this.hasEventHelpers) {
return new Funnel(tree, { exclude: [/helpers/] });
exclude.push(/helpers/);
}

return tree;
return new Funnel(tree, { exclude });
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"broccoli-funnel": "^2.0.2",
"ember-cli-babel": "^7.7.3",
"ember-cli-version-checker": "^3.1.3",
"ember-modifier-manager-polyfill": "^1.0.3"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions tests/helpers/ember-on-modifier-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, skip } from 'qunit';
import { gte } from 'ember-compatibility-helpers';

export const onModifierPolyfilled = !gte('3.11.0-beta.1');

export const testIfOnModifierPolyfilled = onModifierPolyfilled ? test : skip;
Loading

0 comments on commit 0c93c82

Please sign in to comment.