Skip to content

Commit

Permalink
fix: compatibility with ember-cli 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
xcambar authored and alexlafroscia committed Aug 8, 2019
1 parent ef10090 commit 3f06969
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions packages/ember-cli-stencil/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
},

included() {
const logDiscovery = debug(`${this.name}:discovery`);
this._super.included.apply(this, arguments);

// Ensure that `ember-auto-import` can handle the dynamic imports
Expand All @@ -49,25 +50,38 @@ module.exports = {
opts.babel.plugins = opts.babel.plugins || [];
opts.babel.plugins.push(require('ember-auto-import/babel-plugin'));

// Find all Stencil collections in the dependencies
const logDiscovery = debug(`${this.name}:discovery`);
this.stencilCollections = this.getParentDependencies()
.map(dep => this.addonDiscovery.resolvePackage(this.parent.root, dep))
.reduce((acc, pathToDep) => {
const packagePath = path.join(pathToDep, 'package.json');
const pkg = require(packagePath);
let parentDepsPackages;
if (this.addonDiscovery) {
// ember-cli < 3.4
parentDepsPackages = this.getParentDependencies()
.map(dep => this.addonDiscovery.resolvePackage(this.parent.root, dep))
.map(pathToDep => {
return {
root: pathToDep,
pkg: require(path.join(pathToDep, 'package.json'))
};
});
} else {
// ember-cli >= 3.4
let packages = this.parent._packageInfo.dependencyPackages;
parentDepsPackages = Object.keys(packages).map(key => {
let { realPath, pkg } = packages[key];
return { root: realPath, pkg };
});
}

// Find all Stencil collections in the dependencies
this.stencilCollections = parentDepsPackages.reduce(
(acc, { root, pkg }) => {
if (StencilCollection.looksLike(pkg)) {
logDiscovery(
'found Stencil collection %o at %o',
pkg.name,
pathToDep
);
acc.push(new StencilCollection(pkg, pathToDep));
logDiscovery('found Stencil collection %o at %o', pkg.name, root);
acc.push(new StencilCollection(pkg, root));
}

return acc;
}, []);
},
[]
);
},

treeForAddon(tree) {
Expand Down

0 comments on commit 3f06969

Please sign in to comment.