Repository: bustlelabs/shep
Pull request #154 (2017-01-11 19:54:24)

Better error when webpack is missing


Patch:
diff --git a/package.json b/package.json
index fd33259..ad9b998 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "shep",
-  "version": "3.0.1",
+  "version": "3.0.0",
   "description": "A framework for building JavaScript APIs with AWS API Gateway and Lambda",
   "main": "lib/index.js",
   "scripts": {
@@ -41,7 +41,7 @@
     "bluebird": "^3.4.7",
     "chalk": "^1.1.3",
     "cliui": "^3.2.0",
-    "execa": "^0.6.0",
+    "execa": "^0.5.0",
     "fs-extra-promise": "^0.4.1",
     "inquirer": "^2.0.0",
     "listr": "^0.9.0",
@@ -60,7 +60,7 @@
     "babel-plugin-add-module-exports": "^0.2.1",
     "babel-plugin-transform-async-to-module-method": "^6.16.0",
     "babel-plugin-transform-object-rest-spread": "^6.20.2",
-    "babel-preset-env": "^1.1.8",
+    "babel-preset-es2015-node4": "^2.1.1",
     "babel-register": "^6.18.0",
     "np": "^2.12.0",
     "standard": "^8.6.0",
@@ -68,17 +68,7 @@
   },
   "babel": {
     "presets": [
-      [
-        "env",
-        {
-          "targets": {
-            "node": 4.3
-          },
-          "exclude": [
-            "transform-regenerator"
-          ]
-        }
-      ]
+      "es2015-node4"
     ],
     "plugins": [
       "add-module-exports",
diff --git a/src/util/build-functions.js b/src/util/build-functions.js
index 7aeb533..6793e8e 100644
--- a/src/util/build-functions.js
+++ b/src/util/build-functions.js
@@ -2,4 +2,8 @@ import exec from './modules/exec'
 
 export default function (PATTERN, NODE_ENV) {
   return exec('webpack', ['--bail'], { env: { PATTERN, NODE_ENV } })
+  .catch({ code: 'ENOENT' }, (e) => {
+    console.warn('No locally installed webpack found. Verify that webpack is installed')
+    throw e
+  })
 }
diff --git a/src/util/load.js b/src/util/load.js
index 8258eb7..3b8dd7b 100644
--- a/src/util/load.js
+++ b/src/util/load.js
@@ -48,12 +48,7 @@ export function api () {
 }
 
 export function envVars (env) {
-  let envConfig
-  try {
-    envConfig = readJSONSync(`environments/${env}.json`)
-  } catch (e) {
-    return {}
-  }
+  const envConfig = readJSONSync(`environments/${env}.json`)
 
   Object.keys(envConfig).forEach(key => {
     let val = envConfig[key]
diff --git a/src/util/modules/exec.js b/src/util/modules/exec.js
index 7b2c886..ea795a2 100644
--- a/src/util/modules/exec.js
+++ b/src/util/modules/exec.js
@@ -1,2 +1,3 @@
 import execa from 'execa'
-export default execa
+import Promise from 'bluebird'
+export default Promise.method(execa)


Test patch:
diff --git a/test/build/index-no-webpack.js b/test/build/index-no-webpack.js
new file mode 100644
index 0000000..bd64a74
--- /dev/null
+++ b/test/build/index-no-webpack.js
@@ -0,0 +1,17 @@
+import test from 'ava'
+import { exec } from '../helpers/exec'
+import td from '../helpers/testdouble'
+
+let error = new Error()
+error.code = 'ENOENT'
+
+td.when(exec('webpack', ['--bail']), { ignoreExtraArgs: true }).thenReject(error)
+td.replace(console, 'warn')
+
+test('Logs to console when no webpack found', async (t) => {
+  const shep = require('../../src')
+  const error = await t.throws(shep.build({ quiet: true }))
+  t.is(error.code, 'ENOENT')
+  td.verify(console.warn(), { ignoreExtraArgs: true })
+})
+
diff --git a/test/build/index.js b/test/build/index.js
index 66405f1..1265baa 100644
--- a/test/build/index.js
+++ b/test/build/index.js
@@ -1,5 +1,8 @@
 import test from 'ava'
-import { didExec } from '../helpers/exec'
+import { exec, didExec } from '../helpers/exec'
+import td from '../helpers/testdouble'
+
+td.when(exec('webpack', ['--bail']), { ignoreExtraArgs: true }).thenReturn(Promise.resolve())
 
 test.before(() => {
   const shep = require('../../src')