Skip to content

Commit

Permalink
Merge pull request #124 from PrinceCornNM/master
Browse files Browse the repository at this point in the history
fixed a couple cases where the addon didn't work in an engine
  • Loading branch information
eriktrom authored Apr 27, 2019
2 parents 8cbc56a + 59009a4 commit 9f41a7f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
69 changes: 44 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,67 @@

const path = require('path');
const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const map = require('broccoli-stew').map;
const BroccoliMergeTrees = require('broccoli-merge-trees');
const fastbootTransform = require('fastboot-transform');
const resolve = require('resolve');

module.exports = {

name: 'ember-gestures',

included(app) {
this._super.apply(this, arguments);
included() {
this._super.included.apply(this, arguments);
let app;

// see: https://github.com/ember-cli/ember-cli/issues/3718
while (typeof app.import !== 'function' && app.app) {
app = app.app;
// If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just
// use that.
if (typeof this._findHost === 'function') {
app = this._findHost();
} else {
// Otherwise, we'll use this implementation borrowed from the _findHost()
// method in ember-cli.
let current = this;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
}

if (typeof app.import !== 'function') {
throw new Error('ember-gestures is being used within another addon or engine '
+ 'and is having trouble registering itself to the parent application.');
}

app.import('vendor/hammer.js');
app.import('vendor/AnimationFrame.js');
app.import('vendor/hammerjs/hammer.js');
app.import('vendor/animation-frame/AnimationFrame.js');
},

treeForVendor(vendorTree) {
treeForVendor(tree) {
let trees = [];
let hammerTree = new Funnel(path.dirname(require.resolve('hammerjs')), {
files: ['hammer.js']
});
hammerTree = map(hammerTree, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);

let animationFrameTree = new Funnel(path.dirname(require.resolve('animation-frame/AnimationFrame.js')), {
let hammerJs = fastbootTransform(new Funnel(this.pathBase('hammerjs'), {
files: ['hammer.js'],
destDir: 'hammerjs'
}));

let animationFrame = fastbootTransform(new Funnel(this.pathBase('animation-frame'), {
files: ['AnimationFrame.js'],
});
destDir: 'animation-frame'
}));

if (vendorTree !== undefined) {
trees.push(vendorTree);
trees = trees.concat([hammerJs, animationFrame]);

if (tree) {
trees.push(tree);
}

trees.push(hammerTree, animationFrameTree);
return new BroccoliMergeTrees(trees);
},

return new MergeTrees(trees);
/*
Rely on the `resolve` package to mimic node's resolve algorithm.
It finds the modules in a manner that works for npm 2.x,
3.x, and yarn in both the addon itself and projects that depend on this addon.
This is an edge case b/c some modules do not have a main
module we can require.resolve through node itself and similarily ember-cli
does not have such a hack for the same reason.
*/
pathBase(packageName) {
return path.dirname(resolve.sync(`${packageName}/package.json`, { basedir: __dirname }));
},

isDevelopingAddon() {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
"bugs": "https://github.com/html-next/ember-gestures/issues",
"dependencies": {
"animation-frame": "~0.2.4",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^2.0.0",
"broccoli-stew": "^1.5.0",
"broccoli-funnel": "^2.0.2",
"broccoli-merge-trees": "^3.0.2",
"ember-cli-babel": "^6.8.2",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-version-checker": "^2.1.0",
"ember-copy": "^1.0.0",
"ember-getowner-polyfill": "^2.2.0",
"fastboot-transform": "^0.1.3",
"hammerjs": "^2.0.8",
"rsvp": "^3.1.0"
"resolve": "^1.10.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand Down

0 comments on commit 9f41a7f

Please sign in to comment.