Repository: ember-cli/ember-cli
Pull request #5977 (2016-06-11 03:57:46)

Cherry-pick core-object warning message.


Patch:
diff --git a/lib/models/addon.js b/lib/models/addon.js
index 287333c78..d695fa582 100644
--- a/lib/models/addon.js
+++ b/lib/models/addon.js
@@ -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;
@@ -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);
   };
@@ -273,7 +279,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);
@@ -282,6 +294,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
diff --git a/package.json b/package.json
index ba919415c..58b510e53 100644
--- a/package.json
+++ b/package.json
@@ -57,7 +57,7 @@
     "clean-base-url": "^1.0.0",
     "compression": "^1.4.4",
     "configstore": "^2.0.0",
-    "core-object": "2.0.1",
+    "core-object": "^2.0.2",
     "debug": "^2.1.3",
     "diff": "^2.2.2",
     "ember-cli-broccoli": "0.16.9",


Test patch:
diff --git a/tests/unit/models/addon-test.js b/tests/unit/models/addon-test.js
index e6a994e16..4557a1783 100644
--- a/tests/unit/models/addon-test.js
+++ b/tests/unit/models/addon-test.js
@@ -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;