Repository: electron-userland/electron-forge (ts)

Issue:
When running "start", app does not start when app version is not present
**Steps to reproduce**: in a working project, delete the "version" field in package.json.
**Steps to reproduce II**: import an existing project wich has no version field in package.json.

**Stack trace**:
```
Exception has occurred: TypeError
TypeError: Error processing argument at index 0, conversion failure from undefined
    at main (d:\dev\joint_examples\node_modules\electron-prebuilt-compile\src\es6-init.js:37:7)
    at Object.<anonymous> (d:\dev\joint_examples\node_modules\electron-prebuilt-compile\src\es6-init.js:48:1)
    at Object.<anonymous> (d:\dev\joint_examples\node_modules\electron-prebuilt-compile\lib\es6-init.js:61:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at loadApplicationPackage (d:\dev\joint_examples\node_modules\electron-prebuilt-compile\node_modules\electron\dist\resources\default_app.asar\main.js:283:12)
    at Object.<anonymous> (d:\dev\joint_examples\node_modules\electron-prebuilt-compile\node_modules\electron\dist\resources\default_app.asar\main.js:325:5)
```

Pull request:
Throw error/warn when no app version exists in start/import
* [x] I have read the [contribution documentation](https://github.com/electron-userland/electron-forge/blob/master/CONTRIBUTING.md) for this project.
* [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project follows, as appropriate.
* [x] The changes are appropriately documented (if applicable).
* [x] The changes have sufficient test coverage (if applicable).
* [x] The testsuite passes successfully on my local machine (if applicable).

**Summarize your changes:**

* In `start`, throws an error when no app version exists.
* In `import`, warns when no app version exists.

Fixes #351.

Patch:
diff --git a/src/api/import.js b/src/api/import.js
index 7f9238058..c7756d6f4 100644
--- a/src/api/import.js
+++ b/src/api/import.js
@@ -184,6 +184,10 @@ export default async (providedOptions = {}) => {
 
   packageJSON = await readPackageJSON(dir);
 
+  if (!packageJSON.version) {
+    warn(interactive, "Please set the 'version' in your application's package.json".yellow);
+  }
+
   packageJSON.config = packageJSON.config || {};
   const templatePackageJSON = await readPackageJSON(path.resolve(__dirname, '../../tmpl'));
   packageJSON.config.forge = templatePackageJSON.config.forge;
diff --git a/src/api/package.js b/src/api/package.js
index 53791394d..8ba9bfff3 100644
--- a/src/api/package.js
+++ b/src/api/package.js
@@ -9,6 +9,7 @@ import { hostArch } from 'electron-packager/targets';
 
 import getForgeConfig from '../util/forge-config';
 import runHook from '../util/hook';
+import { warn } from '../util/messages';
 import realOra, { fakeOra } from '../util/ora';
 import packagerCompileHook from '../util/compile-hook';
 import readPackageJSON from '../util/read-package-json';
@@ -111,6 +112,11 @@ export default async (providedOptions = {}) => {
     throw new Error('electron-compile does not support asar.unpack yet.  Please use asar.unpackDir');
   }
 
+  if (!packageJSON.version && !packageOpts.appVersion) {
+    // eslint-disable-next-line max-len
+    warn(interactive, "Please set 'version' or 'config.forge.electronPackagerConfig.appVersion' in your application's package.json so auto-updates work properly".yellow);
+  }
+
   await runHook(forgeConfig, 'generateAssets');
   await runHook(forgeConfig, 'prePackage');
 
diff --git a/src/api/start.js b/src/api/start.js
index 937290a30..e9305c4f6 100644
--- a/src/api/start.js
+++ b/src/api/start.js
@@ -46,6 +46,10 @@ export default async (providedOptions = {}) => {
 
   const packageJSON = await readPackageJSON(dir);
 
+  if (!packageJSON.version) {
+    throw `Please set your application's 'version' in '${dir}/package.json'.`;
+  }
+
   await rebuild(dir, packageJSON.devDependencies['electron-prebuilt-compile'], process.platform, process.arch);
 
   const spawnOpts = {


Test patch:
diff --git a/test/fast/start_spec.js b/test/fast/start_spec.js
index d0a2562b0..7433e9b62 100644
--- a/test/fast/start_spec.js
+++ b/test/fast/start_spec.js
@@ -8,16 +8,19 @@ chai.use(chaiAsPromised);
 
 describe('start', () => {
   let start;
+  let packageJSON;
   let resolveStub;
   let spawnStub;
 
   beforeEach(() => {
     resolveStub = sinon.stub();
     spawnStub = sinon.stub();
+    packageJSON = require('../fixture/dummy_app/package.json');
+
     start = proxyquire.noCallThru().load('../../src/api/start', {
       '../util/forge-config': async () => ({}),
       '../util/resolve-dir': async dir => resolveStub(dir),
-      '../util/read-package-json': () => Promise.resolve(require('../fixture/dummy_app/package.json')),
+      '../util/read-package-json': () => Promise.resolve(packageJSON),
       '../util/rebuild': () => Promise.resolve(),
       child_process: {
         spawn: spawnStub,
@@ -104,6 +107,18 @@ describe('start', () => {
     );
   });
 
+  it('should throw if no version is in package.json', async () => {
+    resolveStub.returnsArg(0);
+    packageJSON = Object.assign({}, packageJSON);
+    delete packageJSON.version;
+    await expect(start({
+      dir: __dirname,
+      interactive: false,
+    })).to.eventually.be.rejectedWith(
+      `Please set your application's 'version' in '${__dirname}/package.json'.`
+    );
+  });
+
   it('should pass all args through to the spawned Electron instance', async () => {
     const args = ['magic_arg', 123, 'thingy'];
     resolveStub.returnsArg(0);