Skip to content

Commit

Permalink
Auto merge of #5972 - ember-cli:ease-core-object-upgrade, r=nathanham…
Browse files Browse the repository at this point in the history
…mond

[BUGFIX release] ease core-object upgrade for addons which lack .project
  • Loading branch information
homu committed Jun 11, 2016
2 parents d86501b + 6cb0713 commit a72decc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/models/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var walkSync = require('walk-sync');
var WatchedDir = require('broccoli-source').WatchedDir;
var UnwatchedDir = require('broccoli-source').UnwatchedDir;

var chalk = require('chalk');

function mergeTrees(inputTree, options) {
options = options || {};
options.description = options.annotation;
Expand All @@ -39,16 +41,20 @@ function mergeTrees(inputTree, options) {
return tree;
}

function warn(message) {
if (this.ui) {
this.ui.writeDeprecateLine(message);
} else {
console.log(chalk.yellow('DEPRECATION: ' + message));
}
}

function deprecatedAddonFilters(addon, name, insteadUse, fn) {
return function(tree, options) {
var message = name + ' is deprecated, please use ' +
insteadUse + ' directly instead [addon: ' + addon.name + ']';

this.ui && this.ui.writeDeprecateLine(message);

if (!this.ui) {
console.warn(message);
}
warn(this, message);

return fn(tree, options);
};
Expand Down Expand Up @@ -283,7 +289,13 @@ var Addon = CoreObject.extend({
*/
treeGenerator: function(dir) {
var tree;
if (this.project._watchmanInfo.canNestRoots || this.isDevelopingAddon()) {

if (!this.project) {
this._warn('Addon: `' + this.name + '` is missing addon.project, this may be the result of an addon forgetting to invoke `super` in its init.');
}
// TODO: fix law of demeter `_watchmanInfo.canNestRoots` is obviously a poor idea
if ((this.project && this.project._watchmanInfo.canNestRoots) ||
this.isDevelopingAddon()) {
tree = new WatchedDir(dir);
} else {
tree = new UnwatchedDir(dir);
Expand All @@ -292,6 +304,11 @@ var Addon = CoreObject.extend({
return tree;
},

/* @private
* @method _warn
*/
_warn: warn,

/**
Returns a given type of tree (if present), merged with the
application tree. For each of the trees available using this
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/models/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ describe('models/addon.js', function() {
});
});

describe('old core object compat', function() {
it('treeGenerator works without .project', function() {
var warning;
var TheAddon = Addon.extend({
name: 'such name',
root: path.resolve(fixturePath, 'simple'),
_warn: function(message) {
warning = '' + message;
}
});
var addon = new TheAddon();
expect(function() {
addon.treeGenerator('foo');
}).to.not.throw();
expect(warning).to.match(/Addon: `such name` is missing addon.project/);
});
});

describe('treePaths and treeForMethods', function() {
var FirstAddon, SecondAddon;

Expand Down

0 comments on commit a72decc

Please sign in to comment.