Skip to content

Commit

Permalink
[BUGFIX beta] Use bower version of ember-data if present.
Browse files Browse the repository at this point in the history
In order to keep backwards compat, we must honor the version of
ember-data that is present in `bower.json` (even though it is not
needed). This is due to the fact that many people update the
`package.json` and `bower.json` versions of Ember Data completely
independently.

If `bower.json` includes `ember-data` a warning will be issued, and that
version will be used.
  • Loading branch information
rwjblue committed Dec 14, 2015
1 parent ec8e22a commit 446d65f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,50 @@
module.exports = {
name: 'ember-data',

_warn: function(message) {
var chalk = require('chalk');
var warning = chalk.yellow('WARNING: ' + message);

if (this.ui && this.ui.writeWarnLine) {
this.ui.writeWarnLine(message);
} else if (this.ui) {
this.ui.writeLine(warning);
} else {
console.log(warning);
}
},

init: function() {
var bowerDeps = this.project.bowerDependencies();

if (bowerDeps['ember-data']) {
this._warn('Please remove `ember-data` from `bower.json`. As of Ember Data 2.3.0, only the NPM package is needed.');
this._forceBowerUsage = true;
} else {
this._forceBowerUsage = false;
}
},

treeForAddon: function(dir) {
if (this._forceBowerUsage) {
// Fakes an empty broccoli tree
return { inputTree: dir, rebuild: function() { return []; } };
}

var version = require('./lib/version');
var merge = require('broccoli-merge-trees');

return this._super.treeForAddon.call(this, merge([version(), dir]));
},

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

if (this._forceBowerUsage) {
this.app.import({
development: app.bowerDirectory + '/ember-data/ember-data.js',
production: app.bowerDirectory + '/ember-data/ember-data.prod.js'
});
}
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"bower": "bower install",
"production": "ember build --environment=production"
},
"repository": "",
"engines": {
"node": ">= 0.10.0"
},
Expand All @@ -24,6 +23,7 @@
"dependencies": {
"broccoli-file-creator": "^1.0.0",
"broccoli-merge-trees": "^1.0.0",
"chalk": "^1.1.1",
"ember-cli-babel": "^5.1.3"
},
"devDependencies": {
Expand Down

0 comments on commit 446d65f

Please sign in to comment.