Repository: electron-userland/electron-forge
Pull request #426 (2018-01-30 22:44:25)

[BREAKING CHANGE] feat(publisher): add dir to publisher args & convert args from positional to keyword



* [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:**

I added `dir` in preparation for the `snapcraft` publisher, and realized that there are way too many args for publisher modules. It makes more sense to have it be keyword args instead of positional.

BREAKING CHANGE:
Arguments for publisher modules have changed from positional to keyword.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1a65ef0d..c10de4e34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,21 @@
+### [4.3.0](https://github.com/electron-userland/electron-forge/releases/tag/v4.3.0) (2018-01-31)
+
+##### New Features
+
+* **maker:**  add Wix support ([76166af3](https://github.com/electron-userland/electron-forge/commit/76166af3))
+
+##### Bug Fixes
+
+* **maker:**  wix only works on win32 currently ([707a1e33](https://github.com/electron-userland/electron-forge/commit/707a1e33))
+
+##### Other Changes
+
+*  add Wix to PATH ([52a64080](https://github.com/electron-userland/electron-forge/commit/52a64080))
+
+##### Refactors
+
+* **maker:**  extract author name parsing into its own function ([fa80cd3d](https://github.com/electron-userland/electron-forge/commit/fa80cd3d))
+
 #### [4.2.1](https://github.com/electron-userland/electron-forge/releases/tag/v4.2.1) (2018-01-29)
 
 ##### Chores
diff --git a/README.md b/README.md
index c648856ab..5d85d5d3f 100644
--- a/README.md
+++ b/README.md
@@ -280,15 +280,16 @@ Your promise must resolve with an array of the artifacts you generated.
 
 ### API for `publish` targets
 
-You must export a Function that returns a Promise.  Your function will be called with the following parameters.
-
-* artifactPaths - An array of absolute paths to artifacts to publish
-* packageJSON - An object representing the users package.json file
-* forgeConfig - An object representing the users forgeConfig
-* authToken - The value of `--auth-token`
-* tag - The value of `--tag`
-* platform - The platform you are publishing for
-* arch - The arch you are publishing for
+You must export a `Function` that returns a `Promise`.  Your function will be called with the following keyword parameters:
+
+* `dir` - The application directory
+* `artifactPaths` - An array of absolute paths to artifacts to publish
+* `packageJSON` - An object representing the user's `package.json` file
+* `forgeConfig` - An object representing the user's [`forgeConfig`](#config)
+* `authToken` - The value of `--auth-token`
+* `tag` - The value of `--tag`
+* `platform` - The platform you are publishing for
+* `arch` - The arch you are publishing for
 
 You should use `ora` to indicate your publish progress.
 
diff --git a/package.json b/package.json
index ac8564f1f..beb435842 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "electron-forge",
-  "version": "4.2.1",
+  "version": "4.3.0",
   "description": "A complete tool for building modern Electron applications",
   "repository": "https://github.com/electron-userland/electron-forge",
   "main": "dist/api/index.js",
diff --git a/src/api/publish.js b/src/api/publish.js
index 877ad789e..04d8f0958 100644
--- a/src/api/publish.js
+++ b/src/api/publish.js
@@ -139,7 +139,16 @@ const publish = async (providedOptions = {}) => {
       }
     });
 
-    await publisher(artifacts, packageJSON, forgeConfig, authToken, tag, makeOptions.platform || process.platform, makeOptions.arch || process.arch);
+    await publisher({
+      dir,
+      artifacts,
+      packageJSON,
+      forgeConfig,
+      authToken,
+      tag,
+      platform: makeOptions.platform || process.platform,
+      arch: makeOptions.arch || process.arch,
+    });
   }
 };
 
diff --git a/src/makers/win32/wix.js b/src/makers/win32/wix.js
index dfc575271..f5eccb0be 100644
--- a/src/makers/win32/wix.js
+++ b/src/makers/win32/wix.js
@@ -3,9 +3,9 @@ import path from 'path';
 import { ensureDirectory } from '../../util/ensure-output';
 import getNameFromAuthor from '../../util/author-name';
 import configFn from '../../util/config-fn';
-import isInstalled from '../../util/is-installed';
 
-export const isSupportedOnCurrentPlatform = async () => isInstalled('electron-wix-msi');
+// electron-wix-msi doesn't set its 'os' field even though it only runs on win32
+export const isSupportedOnCurrentPlatform = async () => process.platform === 'win32';
 
 export default async ({ dir, appName, targetArch, forgeConfig, packageJSON }) => {
   const { MSICreator } = require('electron-wix-msi');
diff --git a/src/publishers/electron-release-server.js b/src/publishers/electron-release-server.js
index 4395afa2a..8bc693d8d 100644
--- a/src/publishers/electron-release-server.js
+++ b/src/publishers/electron-release-server.js
@@ -21,7 +21,7 @@ const ersPlatform = (platform, arch) => {
   }
 };
 
-export default async (artifacts, packageJSON, forgeConfig, authToken, tag, platform, arch) => {
+export default async ({ artifacts, packageJSON, forgeConfig, platform, arch }) => {
   const ersConfig = forgeConfig.electronReleaseServer;
   if (!(ersConfig.baseUrl && ersConfig.username && ersConfig.password)) {
     throw 'In order to publish to ERS you must set the "electronReleaseServer.baseUrl", "electronReleaseServer.username" and "electronReleaseServer.password" properties in your forge config. See the docs for more info'; // eslint-disable-line
diff --git a/src/publishers/github.js b/src/publishers/github.js
index 4c276e3dd..51b1522e7 100644
--- a/src/publishers/github.js
+++ b/src/publishers/github.js
@@ -5,7 +5,7 @@ import path from 'path';
 import asyncOra from '../util/ora-handler';
 import GitHub from '../util/github';
 
-export default async (artifacts, packageJSON, forgeConfig, authToken, tag) => {
+export default async ({ artifacts, packageJSON, forgeConfig, authToken, tag }) => {
   if (!(forgeConfig.github_repository && typeof forgeConfig.github_repository === 'object' &&
     forgeConfig.github_repository.owner && forgeConfig.github_repository.name)) {
     throw 'In order to publish to github you must set the "github_repository.owner" and "github_repository.name" properties in your forge config. See the docs for more info'; // eslint-disable-line
diff --git a/src/publishers/s3.js b/src/publishers/s3.js
index 46d2ee06d..1e9349acb 100644
--- a/src/publishers/s3.js
+++ b/src/publishers/s3.js
@@ -13,7 +13,7 @@ AWS.util.update(AWS.S3.prototype, {
   },
 });
 
-export default async (artifacts, packageJSON, forgeConfig, authToken, tag) => {
+export default async ({ artifacts, packageJSON, forgeConfig, authToken, tag }) => {
   const s3Config = forgeConfig.s3;
 
   s3Config.secretAccessKey = s3Config.secretAccessKey || authToken;


Test patch:
diff --git a/test/fast/makers_spec.js b/test/fast/makers_spec.js
index fcd8a11b3..63d848d06 100644
--- a/test/fast/makers_spec.js
+++ b/test/fast/makers_spec.js
@@ -10,6 +10,7 @@ describe('makers', () => {
       'linux/rpm': ['darwin', 'linux'],
       'win32/appx': ['win32'],
       'win32/squirrel': ['darwin', 'linux', 'win32'],
+      'win32/wix': ['win32'],
     };
 
     Object.keys(expected).forEach(async (maker) => {
diff --git a/test/fast/publish_spec.js b/test/fast/publish_spec.js
index eeda9a079..503c6a7a3 100644
--- a/test/fast/publish_spec.js
+++ b/test/fast/publish_spec.js
@@ -52,15 +52,16 @@ describe('publish', () => {
       tag: 'my_special_tag',
     });
     expect(publisherSpy.callCount).to.equal(1);
-    expect(publisherSpy.firstCall.args).to.deep.equal([
-      ['artifact1', 'artifact2'],
-      require('../fixture/dummy_app/package.json'),
-      await require('../../src/util/forge-config').default(path.resolve(__dirname, '../fixture/dummy_app')),
-      'my_token',
-      'my_special_tag',
-      process.platform,
-      process.arch,
-    ]);
+    expect(publisherSpy.firstCall.args).to.deep.equal([{
+      dir: resolveStub(),
+      artifacts: ['artifact1', 'artifact2'],
+      packageJSON: require('../fixture/dummy_app/package.json'),
+      forgeConfig: await require('../../src/util/forge-config').default(path.resolve(__dirname, '../fixture/dummy_app')),
+      authToken: 'my_token',
+      tag: 'my_special_tag',
+      platform: process.platform,
+      arch: process.arch,
+    }]);
   });
 
   it('should default to publishing to github', async () => {
@@ -198,28 +199,26 @@ describe('publish', () => {
       it('should successfully restore values and pass them to publisher', () => {
         expect(makeStub.callCount).to.equal(0);
         expect(publisher.callCount).to.equal(2, 'should call once for each platform (make run)');
-        const darwinIndex = publisher.firstCall.args[5] === 'darwin' ? 0 : 1;
+        const darwinIndex = publisher.firstCall.args[0].platform === 'darwin' ? 0 : 1;
         const win32Index = darwinIndex === 0 ? 1 : 0;
-        expect(publisher.getCall(darwinIndex).args[1]).to.deep.equal({ state: 1 });
-        expect(publisher.getCall(darwinIndex).args.slice(3)).to.deep.equal([
-          undefined,
-          null,
-          'darwin',
-          'x64',
-        ]);
-        expect(publisher.getCall(darwinIndex).args[0].sort()).to.deep.equal(
+        const darwinArgs = publisher.getCall(darwinIndex).args[0];
+        expect(darwinArgs.artifacts.sort()).to.deep.equal(
           fakeMake('darwin').reduce((accum, val) => accum.concat(val.artifacts), []).sort()
         );
-        expect(publisher.getCall(win32Index).args[1]).to.deep.equal({ state: 0 });
-        expect(publisher.getCall(win32Index).args.slice(3)).to.deep.equal([
-          undefined,
-          null,
-          'win32',
-          'x64',
-        ]);
-        expect(publisher.getCall(win32Index).args[0].sort()).to.deep.equal(
+        expect(darwinArgs.packageJSON).to.deep.equal({ state: 1 });
+        expect(darwinArgs.authToken).to.equal(undefined);
+        expect(darwinArgs.tag).to.equal(null);
+        expect(darwinArgs.platform).to.equal('darwin');
+        expect(darwinArgs.arch).to.equal('x64');
+        const win32Args = publisher.getCall(win32Index).args[0];
+        expect(win32Args.artifacts.sort()).to.deep.equal(
           fakeMake('win32').reduce((accum, val) => accum.concat(val.artifacts), []).sort()
         );
+        expect(win32Args.packageJSON).to.deep.equal({ state: 0 });
+        expect(win32Args.authToken).to.equal(undefined);
+        expect(win32Args.tag).to.equal(null);
+        expect(win32Args.platform).to.equal('win32');
+        expect(win32Args.arch).to.equal('x64');
       });
     });