Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] ease core-object upgrade for addons which lack .project #5972

Merged
merged 2 commits into from
Jun 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions lib/models/addon.js
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
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