Repository: electron/electron-packager (js)

Issue:
Inferring author for win32 targets does not give a good error when it's not found
### Preflight Checklist

* [x] I have read the [contribution documentation](https://github.com/electron/electron-packager/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] I have searched the issue tracker for a bug that matches the one I want to file, without success.

### Issue Details

* **Electron Packager Version:** 14.1.1 and above
* **Electron Version:** 8.2.2
* **Operating System:** Windows 10 (Version 1909)
* **Last Known Working Electron Packager version:**: 14.1.0

### Expected Behavior
```
# npm run build
Packaging app for platform win32 x64 using electron v8.2.2
Packaging app for platform linux x64 using electron v8.2.2
Packaging app for platform darwin x64 using electron v8.2.2
Wrote new apps to:
..\build\atomic-tweetdeck-win32-x64
..\build\atomic-tweetdeck-linux-x64
..\build\atomic-tweetdeck-darwin-x64
```

### Actual Behavior
```
# npm run build
  electron-packager Electron Packager 14.1.1
  electron-packager Node v12.16.2
  electron-packager Host Operating system: win32 10.0.18363 (x64) +0ms
  electron-packager Packager Options: {"_":[".","atomic-tweetdeck"],"platform":"win32,linux,darwin","arch":"x64","electron-version":"8.2.2","electronVersion":"8.2.2","tmpdir":false,"out":"../build","app-version":"0.13.0","appVersion":"0.13.0","version-string":{"FileDescription":"Atomic TweetDeck","ProductName":"Atomic TweetDeck"},"versionString":{"fileDescription":"Atomic TweetDeck","productName":"Atomic TweetDeck"},"icon":"favicon.ico","overwrite":true,"deref-symlinks":true,"derefSymlinks":true,"download":{"rejectUnauthorized":true,"reject-unauthorized":true},"junk":true,"prune":true,"dir":".","name":"atomic-tweetdeck","protocols":[]} +2ms
  electron-packager Target Platforms: win32, linux, darwin +6ms
  electron-packager Target Architectures: x64 +2ms
  electron-packager Unable to find all properties in parent package.json files. Missing props: "author" +0ms
Could not locate a package.json file in "d:\Projects\Public\atomic-tweetdeck\master" or its parent directories for an Electron app.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! atomic-tweetdeck@0.13.0 build: `build.bat build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the atomic-tweetdeck@0.13.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\dogan\AppData\Roaming\npm-cache\_logs\2020-04-24T03_24_11_127Z-debug.log
```

### To Reproduce
Clone [atomic-tweetdeck](https://github.com/dogancelik/atomic-tweetdeck), remove `author` from `package.json` (currently there is none) and run `npm run build` **or** the following raw command (no NPM required):

```
electron-packager ./ atomic-tweetdeck --platform=win32,linux,darwin --arch=x64 --electron-version=8.2.2 --no-tmpdir --out=../build --app-version="0.13.0" --version-string.FileDescription="Atomic TweetDeck" --version-string.ProductName="Atomic TweetDeck" --icon=favicon.ico --overwrite
```

### Additional Information
It tells you it can't find `package.json` and doesn't tell you why unless you set `DEBUG=electron-packager`. The reason it fails is because my package.json doesn't have an author. Build doesn't fail if I add an author.

If author is required, it should tell you without having to use DEBUG. Author should be optional.

Pull request:
fix(infer): add missing fields to the infer error message
* [x] I have read the [contribution documentation](https://github.com/electron/electron-packager/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:**

Fixes #1144

Patch:
diff --git a/src/infer.js b/src/infer.js
index d97c34b..1975880 100644
--- a/src/infer.js
+++ b/src/infer.js
@@ -152,6 +152,7 @@ module.exports = async function getMetadataFromPackageJSON (platforms, opts, dir
   }
 
   if (platforms.includes('win32') && !(opts.win32metadata && opts.win32metadata.CompanyName)) {
+    debug('Requiring author in package.json, as CompanyName was not specified for win32metadata')
     props.push('author')
   }
 
@@ -166,7 +167,7 @@ module.exports = async function getMetadataFromPackageJSON (platforms, opts, dir
     if (err.missingProps) {
       if (err.missingProps.length === props.length) {
         debug(err.message)
-        err.message = `Could not locate a package.json file in "${path.resolve(opts.dir)}" or its parent directories for an Electron app.`
+        err.message = `Could not locate a package.json file in "${path.resolve(opts.dir)}" or its parent directories for an Electron app with the following fields: ${err.missingProps.join(', ')}`
       } else {
         return handleMissingProperties(opts, err)
       }


Test patch:
diff --git a/test/infer.js b/test/infer.js
index 19a19f9..d0f545e 100644
--- a/test/infer.js
+++ b/test/infer.js
@@ -110,6 +110,16 @@ test('do not infer win32metadata.CompanyName when author is an object without a
 
   return testInferWin32metadataAuthorObject(t, opts, author, expected, 'win32metadata.CompanyName should not have been inferred')
 }))
+test('infer: missing author for win32 target platform', util.testSinglePlatform(async (t, opts) => {
+  opts.dir = await copyFixtureToTempDir(t, 'infer-win32metadata')
+  opts.appVersion = '1.0.0'
+
+  const packageJSONFilename = path.join(opts.dir, 'package.json')
+  const packageJSON = await fs.readJson(packageJSONFilename)
+  delete packageJSON.author
+  await fs.writeJson(packageJSONFilename, packageJSON)
+  await t.throwsAsync(getMetadataFromPackageJSON(['win32'], opts, opts.dir), { message: /following fields: author/ })
+}))
 test('missing name from package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-name', /^Unable to determine application name/))
 test('missing Electron version from package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-electron-version', /^Unable to determine Electron version/))
 test('missing package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-package-json', /^Could not locate a package\.json file/))