title: child_process.exec/spawn triggers callback/close with npm install command (via Gulp / Shipit)
body: <ul>
  <li>I'm using <a href="https://github.com/shipitjs/shipit" rel="nofollow noreferrer">Shipit</a> for deployment.</li>
  <li>On deploy, Shipit checks out the current Git Sha, to a tmp directory, then  I run <code>npm install</code> followed by <code>gulp build</code>, then proceed with the deploy.</li>
  <li>Shipit uses Orchestrator for it's task flow, as Gulp does.</li>
  <li>Shipit has it's own CLI, so I can deploy with <code>shipit development deploy</code>.</li>
  </ul>
  
  <p>Everything thing above works. What I'm trying to do is create a <code>gulp deploy</code> task that will initialize Shipit directly, instead of using the CLI. Looks something like this:</p>
  
  <pre><code>gulp.task('shipit:deploy', function() {
    var deployToEnv = argv['deploy-to'] || false;
    var shipit;
    return inquirer.prompt([{
      type: 'list',
      name: 'deployToEnv',
      default: deployToEnv,
      message: 'Deploy to environment:',
      choices: envs
    }]).then(function(answers) {
      deployToEnv = answers.deployToEnv;
      shipit = new Shipit({environment: deployToEnv});
      shipit.initialize();
      shipit.start('deploy');
    });
  });
  </code></pre>
  
  <p>Corresponding shipit config:</p>
  
  <pre><code>  shipit.initConfig(config);
    shipit.blTask('build', function() {
      return shipit.local('npm install --silent', {
        cwd: shipit.config.workspace
      }).then(function() {
        return shipit.local('gulp build', {
          cwd: shipit.config.workspace
        });
      });
    });
  
    shipit.on('fetched', function() {
      shipit.start('build');
    });
  </code></pre>
  
  <p>Things appear to work with one problem: it doesn't actually perform the <code>npm install</code>!</p>
  
  <p><code>Running "npm install --silent" on local.
  Running "gulp build" on local.</code> </p>
  
  <p>So, it would seem something in the <code>npm install</code> command is prematurely resolving the promise, but I'm not sure how or why.</p>
  
  <p>I had a similar problem (just using shipit cli) with npm warnings, which is when I discovered using the --silent arg solved that.</p>
  
  <p>As a test, I left the code as is, but replaced <code>npm install --silent</code> with <code>sleep 10</code>. Sure enough, it waited for 10 seconds before executing <code>gulp build</code>. So, it would seem it is something specific with the <code>npm install</code> command.</p>
  
  <p>Any help is appreciated!</p>
  
  <h2>Update #1:</h2>
  
  <p><code>shipit.local</code> uses <code>child_process.exec</code>. I tried converting this to use <code>child_process.spawn</code>, but had the same result.</p>
  
  <h2>Update #2:</h2>
  
  <p>If I change the command to <code>sudo npm install</code>, things work as expected! So...what does this mean, and how can I avoid running it with <code>sudo</code>?</p>
  
  <h2>Update #3:</h2>
  
  <p>Still unable to do this without sudo, but I tried adding the <code>--verbose</code> flag with these results:</p>
  
  <p>Without <code>sudo</code>:</p>
  
  <pre><code>@ npm info it worked if it ends with ok
  @ npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
  @ npm verb cli   '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
  @ npm verb cli   'install',
  @ npm verb cli   '--verbose' ]
  @ npm info using npm@2.5.1
  @ npm info using node@v0.12.0
  @ npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
  @ npm verb install where, peers [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
  @ npm info preinstall edwards-garment-website@1.1.0
  @ npm info build /Users/timkelty/tmp/edwards-garment-website
  @ npm verb linkStuff [ false, false, false, '/Users/timkelty/tmp' ]
  @ npm info linkStuff edwards-garment-website@1.1.0
  @ npm verb linkBins edwards-garment-website@1.1.0
  @ npm verb linkMans edwards-garment-website@1.1.0
  @ npm verb rebuildBundles edwards-garment-website@1.1.0
  @ npm info install edwards-garment-website@1.1.0
  @ npm info postinstall edwards-garment-website@1.1.0
  @ npm verb exit [ 0, true ]
  @ npm info ok
  Running "gulp build" on local.
  @ [15:14:32] Local gulp not found in ~/tmp/edwards-garment-website
  @ [15:14:32] Try running: npm install gulp
  'build' errored after 755 ms
  Error: Command failed: /bin/sh -c gulp build
  </code></pre>
  
  <p>With <code>sudo</code>:</p>
  
  <pre><code>Running "sudo npm install --verbose" on local.
  @ npm info it worked if it ends with ok
  @ npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
  @ npm verb cli   '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
  @ npm verb cli   'install',
  @ npm verb cli   '--verbose' ]
  @ npm info using npm@2.5.1
  @ npm info using node@v0.12.0
  @ npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website',
  @ npm verb install   [ 'Select2',
  @ npm verb install     'autoprefixer-core',
  @ npm verb install     'babel',
  </code></pre>
  
  <p>...so for some reason, when running without sudo, the npm install command seems to think it doesn't have any dependencies to install, so it finishes without error and continues to my next task.</p>