Repository: ember-cli/ember-cli
Pull request #7702 (2018-03-26 14:54:37)

Don't run `addon-import` blueprint if `project.isModuleUnification()`
Required for https://github.com/emberjs/ember.js/pull/16397#discussion_r177098663. Module unification addons don't have an `/app` path. This PR prevents the default `addon-import` blueprint from running when `project.isModuleUnification() === true`.

TODO:

 * [x] tests (hopefully there are existing tests somewhere)
 * [x] refactor (as the line we're modifying is already too complex)

CI failures look unrelated: https://github.com/ember-cli/ember-cli/issues/7716

GavinJoyce: This is ready for review
mixonic: @GavinJoyce I kicked a build here but I'm not sure why it is failing. Doesn't seem related.

Your change here makes sense to me, and I chatted it over with @Turbo87 as well.

Patch:
diff --git a/lib/tasks/generate-from-blueprint.js b/lib/tasks/generate-from-blueprint.js
index 2086caee3..a43034120 100644
--- a/lib/tasks/generate-from-blueprint.js
+++ b/lib/tasks/generate-from-blueprint.js
@@ -21,9 +21,10 @@ class GenerateTask extends Task {
     let testBlueprint = this.lookupBlueprint(`${name}-test`, true);
     // lookup custom addon blueprint
     let addonBlueprint = this.lookupBlueprint(`${name}-addon`, true);
-    // otherwise, use default addon-import
 
-    if (noAddonBlueprint.indexOf(name) < 0 && !addonBlueprint && (mainBlueprint && mainBlueprint.supportsAddon()) && options.args[1]) {
+    // otherwise, use default addon-import
+    let mainBlueprintSupportsAddon = mainBlueprint && mainBlueprint.supportsAddon() && !this.project.isModuleUnification();
+    if (noAddonBlueprint.indexOf(name) < 0 && !addonBlueprint && mainBlueprintSupportsAddon && options.args[1]) {
       addonBlueprint = this.lookupBlueprint('addon-import', true);
     }
 


Test patch:
diff --git a/tests/acceptance/addon-generate-test.js b/tests/acceptance/addon-generate-test.js
index cb0b19eca..f8d7ce74c 100644
--- a/tests/acceptance/addon-generate-test.js
+++ b/tests/acceptance/addon-generate-test.js
@@ -3,8 +3,10 @@
 const co = require('co');
 const RSVP = require('rsvp');
 const ember = require('../helpers/ember');
-const fs = require('fs-extra');
 const path = require('path');
+const fs = require('fs-extra');
+let outputFile = RSVP.denodeify(fs.outputFile);
+let ensureDir = RSVP.denodeify(fs.ensureDir);
 let remove = RSVP.denodeify(fs.remove);
 let root = process.cwd();
 let tmproot = path.join(root, 'tmp');
@@ -74,6 +76,35 @@ describe('Acceptance: ember generate in-addon', function() {
     }
   }));
 
+  it('runs the `addon-import` bluprint from a classic addon', co.wrap(function *() {
+    yield initAddon('my-addon');
+
+    yield outputFile(
+      'blueprints/service/files/__root__/__path__/__name__.js',
+      "import Service from '@ember/service';\n" +
+      'export default Service.extend({ });\n'
+    );
+
+    yield ember(['generate', 'service', 'session']);
+
+    expect(file('app/services/session.js')).to.exist;
+  }));
+
+  it('does not run the `addon-import` bluprint from a module unification addon', co.wrap(function *() {
+    yield initAddon('my-addon');
+    yield ensureDir('src');
+
+    yield outputFile(
+      'blueprints/service/files/__root__/__path__/__name__.js',
+      "import Service from '@ember/service';\n" +
+      'export default Service.extend({ });\n'
+    );
+
+    yield ember(['generate', 'service', 'session']);
+
+    expect(file('app/services/session.js')).to.not.exist;
+  }));
+
   it('in-addon blueprint foo', co.wrap(function *() {
     yield generateInAddon(['blueprint', 'foo']);