Repository: ember-cli/ember-cli
Pull request #7929 (2018-07-20 00:39:06)

Changed the condition to check if addon name is same in index.js and package.json to be generic
Earlier the warning was displayed for addon's with different names only if the addon's had scopes in their names. 


Patch:
diff --git a/lib/models/addon.js b/lib/models/addon.js
index 67089f1ec..b32e581f2 100644
--- a/lib/models/addon.js
+++ b/lib/models/addon.js
@@ -36,7 +36,6 @@ const addonProcessTree = require('../utilities/addon-process-tree');
 const emberCLIBabelConfigKey = require('../utilities/ember-cli-babel-config-key');
 const semver = require('semver');
 const processModulesOnly = require('../broccoli/babel-process-modules-only');
-const npa = require('npm-package-arg');
 const registryHasPreprocessor = require('../utilities/registry-has-preprocessor');
 
 const BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS = Symbol('BUILD_BABEL_OPTIONS_FOR_PREPROCESSORS');
@@ -365,17 +364,12 @@ let addonProto = {
         return true;
       }
 
-      // If package.json and index.js names do not match, we should check for scoped vs non-scoped
-      const parsed = npa(parentName);
-      let parsedName = parsed.name;
-      if (parsed.scope) {
-        parsedName = parsedName.replace(parsed.scope, '').slice(1);
-      }
-      if (parsedName === this.name) {
-        if (!this._hasWarnedForMismatchedNames) {
+      // Addon names in index.js and package.json should be the same at all times whether they have scope or not.
+      if (this.root === this.parent.root) {
+        if (parentName !== this.name && !this._hasWarnedForMismatchedNames) {
           this.ui.writeWarnLine(
             'Your names in package.json and index.js should match. ' +
-            `You currently have ${parsed.name} in package.json and ${this.name} in index.js.`);
+            `You currently have ${parentName} in package.json and ${this.name} in index.js.`);
 
           this._hasWarnedForMismatchedNames = true;
         }


Test patch:
diff --git a/tests/fixtures/addon/component-with-template/addon/components/basic-thing.js b/tests/fixtures/addon/component-with-template/addon/components/basic-thing.js
index 7ba03a3b1..f99bee3ff 100644
--- a/tests/fixtures/addon/component-with-template/addon/components/basic-thing.js
+++ b/tests/fixtures/addon/component-with-template/addon/components/basic-thing.js
@@ -1,6 +1,6 @@
-import Ember from 'ember';
 import template from '../templates/components/basic-thing';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   layout: template
-});
+});
\ No newline at end of file
diff --git a/tests/fixtures/addon/developing-addon/addon/components/simple-component.js b/tests/fixtures/addon/developing-addon/addon/components/simple-component.js
index cb634b7df..dde189865 100644
--- a/tests/fixtures/addon/developing-addon/addon/components/simple-component.js
+++ b/tests/fixtures/addon/developing-addon/addon/components/simple-component.js
@@ -1,6 +1,6 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 import layout from '../templates/components/simple-component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   layout
-});
+});
\ No newline at end of file
diff --git a/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/main/component.js b/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/main/component.js
index 926b61300..17f71fdda 100644
--- a/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/main/component.js
+++ b/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/main/component.js
@@ -1,4 +1,6 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
 });
+
+
diff --git a/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/my-component/component.js b/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/my-component/component.js
index b584e24b4..9d49a792e 100644
--- a/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/my-component/component.js
+++ b/tests/fixtures/addon/kitchen-sink-mu/src/ui/components/my-component/component.js
@@ -1,6 +1,6 @@
-import Ember from 'ember';
 import template from './template';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   layout: template
-});
+});
\ No newline at end of file
diff --git a/tests/fixtures/addon/kitchen-sink/addon/components/basic-thing.js b/tests/fixtures/addon/kitchen-sink/addon/components/basic-thing.js
index 7ba03a3b1..f99bee3ff 100644
--- a/tests/fixtures/addon/kitchen-sink/addon/components/basic-thing.js
+++ b/tests/fixtures/addon/kitchen-sink/addon/components/basic-thing.js
@@ -1,6 +1,6 @@
-import Ember from 'ember';
 import template from '../templates/components/basic-thing';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   layout: template
-});
+});
\ No newline at end of file
diff --git a/tests/fixtures/addon/kitchen-sink/addon/components/my-component/component.js b/tests/fixtures/addon/kitchen-sink/addon/components/my-component/component.js
index b584e24b4..fee7d8533 100644
--- a/tests/fixtures/addon/kitchen-sink/addon/components/my-component/component.js
+++ b/tests/fixtures/addon/kitchen-sink/addon/components/my-component/component.js
@@ -1,6 +1,7 @@
-import Ember from 'ember';
+
 import template from './template';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   layout: template
 });
diff --git a/tests/fixtures/addon/with-blueprint-override/blueprints/component/files/__root__/__path__/__name__.js b/tests/fixtures/addon/with-blueprint-override/blueprints/component/files/__root__/__path__/__name__.js
index d96d2a124..0e79c7e4a 100644
--- a/tests/fixtures/addon/with-blueprint-override/blueprints/component/files/__root__/__path__/__name__.js
+++ b/tests/fixtures/addon/with-blueprint-override/blueprints/component/files/__root__/__path__/__name__.js
@@ -1,5 +1,6 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 <%= importTemplate %>
-export default Ember.Component.extend({<%= contents %>
+
+export default Component.extend({<%= contents %>
 });
 //generated component successfully
\ No newline at end of file
diff --git a/tests/fixtures/preprocessor-tests/app-registry-ordering/app/components/should-be-preprocessed.js b/tests/fixtures/preprocessor-tests/app-registry-ordering/app/components/should-be-preprocessed.js
index 657c34cca..b63a51739 100644
--- a/tests/fixtures/preprocessor-tests/app-registry-ordering/app/components/should-be-preprocessed.js
+++ b/tests/fixtures/preprocessor-tests/app-registry-ordering/app/components/should-be-preprocessed.js
@@ -1,5 +1,5 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   foo: /__SECOND_PREPROCESSOR_REPLACEMENT_TOKEN__/
 });
diff --git a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/app/components/should-not-be-preprocessed.js b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/app/components/should-not-be-preprocessed.js
index da91a67ee..8d9ad15e5 100644
--- a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/app/components/should-not-be-preprocessed.js
+++ b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/app/components/should-not-be-preprocessed.js
@@ -1,5 +1,5 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   foo: __PREPROCESSOR_REPLACEMENT_TOKEN__
 });
diff --git a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/node_modules/ember-cool-addon/addon/components/clitest-example.js b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/node_modules/ember-cool-addon/addon/components/clitest-example.js
index da91a67ee..8d9ad15e5 100644
--- a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/node_modules/ember-cool-addon/addon/components/clitest-example.js
+++ b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-2/node_modules/ember-cool-addon/addon/components/clitest-example.js
@@ -1,5 +1,5 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   foo: __PREPROCESSOR_REPLACEMENT_TOKEN__
 });
diff --git a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/app/components/should-not-be-preprocessed.js b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/app/components/should-not-be-preprocessed.js
index da91a67ee..8d9ad15e5 100644
--- a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/app/components/should-not-be-preprocessed.js
+++ b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/app/components/should-not-be-preprocessed.js
@@ -1,5 +1,5 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   foo: __PREPROCESSOR_REPLACEMENT_TOKEN__
 });
diff --git a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/node_modules/ember-shallow-addon/node_modules/ember-deep-addon/addon/components/clitest-deep-example.js b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/node_modules/ember-shallow-addon/node_modules/ember-deep-addon/addon/components/clitest-deep-example.js
index 632d6093d..51f426f05 100644
--- a/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/node_modules/ember-shallow-addon/node_modules/ember-deep-addon/addon/components/clitest-deep-example.js
+++ b/tests/fixtures/preprocessor-tests/app-with-addon-with-preprocessors-3/node_modules/ember-shallow-addon/node_modules/ember-deep-addon/addon/components/clitest-deep-example.js
@@ -1,5 +1,5 @@
-import Ember from 'ember';
+import Component from '@ember/component';
 
-export default Ember.Component.extend({
+export default Component.extend({
   deep: __PREPROCESSOR_REPLACEMENT_TOKEN__
 });
diff --git a/tests/unit/models/addon-test.js b/tests/unit/models/addon-test.js
index b9105f303..cf28fafa7 100644
--- a/tests/unit/models/addon-test.js
+++ b/tests/unit/models/addon-test.js
@@ -330,12 +330,21 @@ describe('models/addon.js', function() {
 
       it('returns true when the addon name is prefixed in package.json and not in index.js', function() {
         process.env.EMBER_ADDON_ENV = 'development';
-
+        project.root = 'foo';
         project.name = () => ('@foo/my-addon');
         addon.name = 'my-addon';
         expect(addon.isDevelopingAddon(), 'addon is being developed').to.eql(true);
       });
 
+      it('displays warning if addon name is different in package.json and index.js ', function() {
+        process.env.EMBER_ADDON_ENV = 'development';
+        project.root = 'foo';
+        project.name = () => ('foo-my-addon');
+        addon.name = 'my-addon';
+        addon.isDevelopingAddon();
+        expect(project.ui.output).to.match(/WARNING: Your names in package.json and index.js should match*/);
+      });
+
       it('returns false when `EMBER_ADDON_ENV` is not set', function() {
         delete process.env.EMBER_ADDON_ENV;