Repository: ember-cli/ember-cli
Pull request #5395 (2016-01-26 07:54:11)

Skip bower/npm install on blueprint install if manifests are missing
cc @trek 

stefanpenner: @homu r+
homu: :pushpin: Commit bb4e312 has been approved by `stefanpenner`

<!-- @homu r=stefanpenner bb4e3128c83fb79e7464efc7e0e8ef59a69a612a -->
homu: :hourglass: Testing commit bb4e312 with merge f1084d4...
homu: :broken_heart: Test failed - [status](https://travis-ci.org/ember-cli/ember-cli/builds/104893435)
trek: This is failing even worse than before :(
stefanpenner: @trek its the same problem I believe, this also seems to just break `ember new foo`

Patch:
diff --git a/lib/commands/new.js b/lib/commands/new.js
index 00656b3ba..cb98999f4 100644
--- a/lib/commands/new.js
+++ b/lib/commands/new.js
@@ -87,6 +87,8 @@ module.exports = Command.extend({
         dryRun: commandOptions.dryRun
       })
       .then(function(opts) {
+        initCommand.project.root = process.cwd();
+
         return initCommand
           .run(commandOptions, rawArgs)
           .catch(function(err) {
diff --git a/lib/tasks/bower-install.js b/lib/tasks/bower-install.js
index 8ba6ba82b..bf8e56712 100644
--- a/lib/tasks/bower-install.js
+++ b/lib/tasks/bower-install.js
@@ -1,9 +1,10 @@
 'use strict';
 
 // Runs `bower install` in cwd
-
-var Promise = require('../ext/promise');
-var Task    = require('../models/task');
+var path       = require('path');
+var existsSync = require('exists-sync');
+var Promise    = require('../ext/promise');
+var Task       = require('../models/task');
 
 module.exports = Task.extend({
   init: function() {
@@ -15,11 +16,17 @@ module.exports = Task.extend({
   run: function(options) {
     var chalk          = require('chalk');
     var bower          = this.bower;
+    var bowerJson      = path.join(this.project.root, '/bower.json');
     var bowerConfig    = this.bowerConfig;
     var ui             = this.ui;
     var packages       = options.packages || [];
     var installOptions = options.installOptions || { save: true };
 
+    if (!existsSync(bowerJson)) {
+      ui.writeWarnLine('Skipping bower install: bower.json not found');
+      return;
+    }
+
     ui.startProgress(chalk.green('Installing browser packages via Bower'), chalk.green('.'));
 
     var config = bowerConfig.read();
diff --git a/lib/tasks/npm-install.js b/lib/tasks/npm-install.js
index 40fa58af9..b02234e2b 100644
--- a/lib/tasks/npm-install.js
+++ b/lib/tasks/npm-install.js
@@ -1,11 +1,23 @@
 'use strict';
 
 // Runs `npm install` in cwd
-
-var NpmTask = require('./npm-task');
+var path       = require('path');
+var existsSync = require('exists-sync');
+var NpmTask    = require('./npm-task');
 
 module.exports = NpmTask.extend({
   command: 'install',
   startProgressMessage: 'Installing packages for tooling via npm',
-  completionMessage: 'Installed packages for tooling via npm.'
+  completionMessage: 'Installed packages for tooling via npm.',
+  run: function() {
+    var ui = this.ui;
+    var packageJson = path.join(this.project.root, 'package.json');
+
+    if (!existsSync(packageJson)) {
+      ui.writeWarnLine('Skipping npm install: package.json not found');
+      return;
+    } else {
+      return this._super.run.apply(this, arguments);
+    }
+  }
 });


Test patch:
diff --git a/tests/unit/tasks/bower-install-test.js b/tests/unit/tasks/bower-install-test.js
new file mode 100644
index 000000000..09a1de969
--- /dev/null
+++ b/tests/unit/tasks/bower-install-test.js
@@ -0,0 +1,31 @@
+'use strict';
+
+var BowerInstallTask = require('../../../lib/tasks/bower-install');
+var MockUI           = require('../../helpers/mock-ui');
+var MockProject      = require('../../helpers/mock-project');
+var expect           = require('chai').expect;
+
+describe('bower install task', function() {
+  var bowerInstallTask;
+  var ui;
+
+  beforeEach(function() {
+    var project = new MockProject();
+    ui = new MockUI();
+
+    bowerInstallTask = new BowerInstallTask({
+      ui: ui,
+      project: project
+    });
+  });
+
+  afterEach(function() {
+    ui = undefined;
+    bowerInstallTask = undefined;
+  });
+
+  it('skips bower installs if there is no bower.json', function() {
+    bowerInstallTask.run({});
+    expect(ui.output).to.include('Skipping bower install: bower.json not found');
+  });
+});
diff --git a/tests/unit/tasks/npm-install-test.js b/tests/unit/tasks/npm-install-test.js
new file mode 100644
index 000000000..ea8747c3f
--- /dev/null
+++ b/tests/unit/tasks/npm-install-test.js
@@ -0,0 +1,32 @@
+'use strict';
+
+var NpmInstallTask = require('../../../lib/tasks/npm-install');
+var MockUI         = require('../../helpers/mock-ui');
+var expect         = require('chai').expect;
+
+describe('npm install task', function() {
+  var npmInstallTask;
+  var ui;
+
+  beforeEach(function() {
+    var project = {
+      root: __dirname
+    };
+    ui = new MockUI();
+
+    npmInstallTask = new NpmInstallTask({
+      ui: ui,
+      project: project
+    });
+  });
+
+  afterEach(function() {
+    ui = undefined;
+    npmInstallTask = undefined;
+  });
+
+  it('skips npm installs if there is no package.json', function() {
+    npmInstallTask.run({});
+    expect(ui.output).to.include('Skipping npm install: package.json not found');
+  });
+});