Repository: ember-cli/ember-cli
Pull request #7936 (2018-07-23 21:11:40)

Extract url construction in watcher
It would be really nice if we could customize the output that is displayed once the express server is setup. Today, there is a one-to-one coupling between the port/host combination passed to express and what is printed. After talking to @rwjblue we feel this is minimal change that gives override access to what gets printed. However, it is pretty clear that there needs to be a DSL type interface on top of `UI` that allows you to customize the output. Another use case is being able to squelch deprecations for ember-cli-deprecation-workflow.


Patch:
diff --git a/lib/models/addon.js b/lib/models/addon.js
index b32e581f2..67089f1ec 100644
--- a/lib/models/addon.js
+++ b/lib/models/addon.js
@@ -36,6 +36,7 @@ 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');
@@ -364,12 +365,17 @@ let addonProto = {
         return true;
       }
 
-      // 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) {
+      // 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) {
           this.ui.writeWarnLine(
             'Your names in package.json and index.js should match. ' +
-            `You currently have ${parentName} in package.json and ${this.name} in index.js.`);
+            `You currently have ${parsed.name} in package.json and ${this.name} in index.js.`);
 
           this._hasWarnedForMismatchedNames = true;
         }
diff --git a/lib/models/watcher.js b/lib/models/watcher.js
index b0810c0e7..cb5c28eb0 100644
--- a/lib/models/watcher.js
+++ b/lib/models/watcher.js
@@ -38,6 +38,14 @@ class Watcher extends CoreObject {
     return this.watcher.then.apply(this.watcher, arguments);
   }
 
+  serverURL() {
+    let options = this.options;
+    let config = this.options.project.config(options.environment);
+
+    let baseURL = config.rootURL === '' ? '/' : cleanBaseURL(config.rootURL || (config.baseURL || '/'));
+    return `http${options.ssl ? 's' : ''}://${options.host || 'localhost'}:${options.port}${baseURL}`;
+  }
+
   didChange(results) {
     logger.info('didChange %o', results);
 
@@ -47,12 +55,9 @@ class Watcher extends CoreObject {
     this.ui.writeLine('');
 
     if (this.serving) {
-      let options = this.options;
-      let config = this.options.project.config(options.environment);
-
-      let baseURL = config.rootURL === '' ? '/' : cleanBaseURL(config.rootURL || (config.baseURL || '/'));
-      message += ` – Serving on http${options.ssl ? 's' : ''}://${options.host || 'localhost'}:${options.port}${baseURL}`;
+      message += ` – Serving on ${this.serverURL()}`;
     }
+
     this.ui.writeLine(message);
 
     this.analytics.track({


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 f99bee3ff..7ba03a3b1 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 Component.extend({
+export default Ember.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 dde189865..cb634b7df 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 Component from '@ember/component';
+import Ember from 'ember';
 import layout from '../templates/components/simple-component';
 
-export default Component.extend({
+export default Ember.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 17f71fdda..926b61300 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,6 +1,4 @@
-import Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.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 9d49a792e..b584e24b4 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 Component.extend({
+export default Ember.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 f99bee3ff..7ba03a3b1 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 Component.extend({
+export default Ember.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 fee7d8533..b584e24b4 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,7 +1,6 @@
-
+import Ember from 'ember';
 import template from './template';
-import Component from '@ember/component';
 
-export default Component.extend({
+export default Ember.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 0e79c7e4a..d96d2a124 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,6 +1,5 @@
-import Component from '@ember/component';
+import Ember from 'ember';
 <%= importTemplate %>
-
-export default Component.extend({<%= contents %>
+export default Ember.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 b63a51739..657c34cca 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 Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.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 8d9ad15e5..da91a67ee 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 Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.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 8d9ad15e5..da91a67ee 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 Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.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 8d9ad15e5..da91a67ee 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 Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.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 51f426f05..632d6093d 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 Component from '@ember/component';
+import Ember from 'ember';
 
-export default Component.extend({
+export default Ember.Component.extend({
   deep: __PREPROCESSOR_REPLACEMENT_TOKEN__
 });
diff --git a/tests/unit/models/addon-test.js b/tests/unit/models/addon-test.js
index cf28fafa7..b9105f303 100644
--- a/tests/unit/models/addon-test.js
+++ b/tests/unit/models/addon-test.js
@@ -330,21 +330,12 @@ 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;