Repository: bustlelabs/shep
Pull request #173 (2017-01-25 17:08:36)

use execa.shell so npm and build commands get an env
This provides the local env to webpack which is needed for some webpack plugins. Like anything that wants to run commands, read env vars, etc. This also lets people use proxies with npm.

Smoke tested a build with `webpack-shell-plugin` and a `shep new`


Patch:
diff --git a/src/new/index.js b/src/new/index.js
index bcb6f15..1f7966a 100644
--- a/src/new/index.js
+++ b/src/new/index.js
@@ -82,6 +82,6 @@ function createFiles ({ path, arn, region }) {
 }
 
 function npmInstall ({ path }) {
-  return exec('npm', ['install'], { cwd: path })
+  return exec('npm install', { cwd: path })
 }
 
diff --git a/src/util/build-functions.js b/src/util/build-functions.js
index b0d4d49..5addfc1 100644
--- a/src/util/build-functions.js
+++ b/src/util/build-functions.js
@@ -2,16 +2,11 @@ import exec from './modules/exec'
 import { pkg } from './load'
 
 export default function (PATTERN, NODE_ENV) {
-  const buildCommand = pkg().shep && pkg().shep.buildCommand ? pkg().shep.buildCommand : 'webpack --bail'
-  const [command, args] = parseBuildCommand(buildCommand)
-  return exec(command, args, { env: { PATTERN, NODE_ENV } })
+  const { shep } = pkg()
+  const buildCommand = shep && shep.buildCommand || 'webpack --bail'
+  return exec(buildCommand, { env: { ...process.env, PATTERN, NODE_ENV } })
   .catch({ code: 'ENOENT' }, (e) => {
     console.warn('No locally installed webpack found. Verify that webpack is installed')
     throw e
   })
 }
-
-function parseBuildCommand (command) {
-  const [com, ...args] = command.split(' ')
-  return [com, args]
-}
diff --git a/src/util/modules/exec.js b/src/util/modules/exec.js
index ea795a2..16900f4 100644
--- a/src/util/modules/exec.js
+++ b/src/util/modules/exec.js
@@ -1,3 +1,3 @@
 import execa from 'execa'
 import Promise from 'bluebird'
-export default Promise.method(execa)
+export default Promise.method(execa.shell)


Test patch:
diff --git a/test/build/index-custom.js b/test/build/index-custom.js
index 753f490..d89d664 100644
--- a/test/build/index-custom.js
+++ b/test/build/index-custom.js
@@ -2,9 +2,7 @@ import test from 'ava'
 import { exec, didExec } from '../helpers/exec'
 import td from '../helpers/testdouble'
 
-const command = 'custom-build'
-const args = ['--cool-flag', '-x', '6']
-const buildCommand = `${command} ${args.join(' ')}`
+const buildCommand = 'custom-build --cool-flag -x 6'
 
 const load = td.replace('../../src/util/load')
 td.when(load.pkg()).thenReturn({ shep: { buildCommand } })
@@ -16,4 +14,4 @@ test.before(() => {
   return shep.build({ quiet: true })
 })
 
-test(didExec, command, args)
+test(didExec, buildCommand)
diff --git a/test/build/index-no-webpack.js b/test/build/index-no-webpack.js
index bd64a74..355f6dd 100644
--- a/test/build/index-no-webpack.js
+++ b/test/build/index-no-webpack.js
@@ -5,7 +5,7 @@ import td from '../helpers/testdouble'
 let error = new Error()
 error.code = 'ENOENT'
 
-td.when(exec('webpack', ['--bail']), { ignoreExtraArgs: true }).thenReject(error)
+td.when(exec('webpack --bail'), { ignoreExtraArgs: true }).thenReject(error)
 td.replace(console, 'warn')
 
 test('Logs to console when no webpack found', async (t) => {
diff --git a/test/build/index.js b/test/build/index.js
index 1265baa..47d125a 100644
--- a/test/build/index.js
+++ b/test/build/index.js
@@ -2,11 +2,11 @@ import test from 'ava'
 import { exec, didExec } from '../helpers/exec'
 import td from '../helpers/testdouble'
 
-td.when(exec('webpack', ['--bail']), { ignoreExtraArgs: true }).thenReturn(Promise.resolve())
+td.when(exec('webpack --bail'), { ignoreExtraArgs: true }).thenReturn(Promise.resolve())
 
 test.before(() => {
   const shep = require('../../src')
   return shep.build({ quiet: true })
 })
 
-test(didExec, 'webpack', ['--bail'])
+test(didExec, 'webpack --bail')
diff --git a/test/helpers/exec.js b/test/helpers/exec.js
index 70c9da9..5df4a9b 100644
--- a/test/helpers/exec.js
+++ b/test/helpers/exec.js
@@ -2,8 +2,8 @@ import td from 'testdouble'
 
 const exec = td.replace('../../src/util/modules/exec')
 
-function didExec (t, cmd, args, options = {}) {
-  td.verify(exec(cmd, args, td.matchers.contains(options)))
+function didExec (t, cmd, options = {}) {
+  td.verify(exec(cmd, td.matchers.contains(options)))
 }
 
 didExec.title = (providedTitle, cmd, subcmd) => `Executed ${cmd} ${subcmd || ''}`
diff --git a/test/new/index.js b/test/new/index.js
index f4f743d..312fe28 100644
--- a/test/new/index.js
+++ b/test/new/index.js
@@ -27,5 +27,5 @@ test(wroteFile, `${path}/.gitignore`)
 test(wroteFile, `${path}/README.md`)
 test(wroteFile, `${path}/webpack.config.js`)
 
-test(didExec, 'npm', ['install'])
+test(didExec, 'npm install')