Repository: electron-userland/electron-forge
Pull request #320 (2017-09-12 01:05:41)

Use the Electron Packager official platform/arch list
* [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:**

This replaces the broken test on Windows with a set of unit tests that just tests parsing an arch value. Retrieving archs when arch is `all` has been delegated to Electron Packager.

~~This is a WIP because I want to make sure the testsuite passes in AppVeyor.~~

## TODO

* [x] Add API to Electron Packager to get arches for a given platform and version (needed for the arm64 + Linux + Electron >= 1.8.0 case) - https://github.com/electron-userland/electron-packager/pull/727
* [x] Utilize the new API

malept: I should probably document it more but anything exported in Packager is fair game as far as "public API" is concerned. I just need to remember to major version bump more often.

Patch:
diff --git a/package.json b/package.json
index f77764c7b..f2837683c 100644
--- a/package.json
+++ b/package.json
@@ -109,7 +109,7 @@
     "electron-forge-template-react": "^1.0.2",
     "electron-forge-template-react-typescript": "^1.0.3",
     "electron-forge-template-vue": "^1.0.2",
-    "electron-packager": "^9.0.0",
+    "electron-packager": "^9.1.0",
     "electron-rebuild": "^1.6.0",
     "form-data": "^2.1.4",
     "fs-extra": "^4.0.0",
diff --git a/src/api/make.js b/src/api/make.js
index a2f47a142..ac6539dbf 100644
--- a/src/api/make.js
+++ b/src/api/make.js
@@ -1,12 +1,13 @@
 import 'colors';
 import fs from 'fs-extra';
 import path from 'path';
+import { hostArch } from 'electron-packager/targets';
 
 import asyncOra from '../util/ora-handler';
-import electronHostArch from '../util/electron-host-arch';
 import getForgeConfig from '../util/forge-config';
 import runHook from '../util/hook';
 import { info, warn } from '../util/messages';
+import parseArchs from '../util/parse-archs';
 import readPackageJSON from '../util/read-package-json';
 import { requireSearchRaw } from '../util/require-search';
 import resolveDir from '../util/resolve-dir';
@@ -44,7 +45,7 @@ export default async (providedOptions = {}) => {
     dir: process.cwd(),
     interactive: false,
     skipPackage: false,
-    arch: electronHostArch(),
+    arch: hostArch(),
     platform: process.platform,
   }, providedOptions);
 
@@ -116,33 +117,15 @@ export default async (providedOptions = {}) => {
     warn(interactive, 'WARNING: Skipping the packaging step, this could result in an out of date build'.red);
   }
 
-  const declaredArch = arch;
-
   info(interactive, 'Making for the following targets:', `${targets.join(', ')}`.cyan);
 
-  let targetArchs = declaredArch.split(',');
-  if (declaredArch === 'all') {
-    switch (platform) {
-      case 'darwin':
-        targetArchs = ['x64'];
-        break;
-      case 'linux':
-        targetArchs = ['ia32', 'x64', 'armv7l'];
-        break;
-      case 'win32':
-      default:
-        targetArchs = ['ia32', 'x64'];
-        break;
-    }
-  }
-
   const packageJSON = await readPackageJSON(dir);
   const appName = forgeConfig.electronPackagerConfig.name || packageJSON.productName || packageJSON.name;
   let outputs = [];
 
   await runHook(forgeConfig, 'preMake');
 
-  for (const targetArch of targetArchs) {
+  for (const targetArch of parseArchs(platform, arch, packageJSON.devDependencies['electron-prebuilt-compile'])) {
     const packageDir = path.resolve(outDir, `${appName}-${platform}-${targetArch}`);
     if (!(await fs.pathExists(packageDir))) {
       throw new Error(`Couldn't find packaged app at: ${packageDir}`);
diff --git a/src/api/package.js b/src/api/package.js
index 58f89d35b..53791394d 100644
--- a/src/api/package.js
+++ b/src/api/package.js
@@ -5,8 +5,8 @@ import glob from 'glob';
 import path from 'path';
 import pify from 'pify';
 import packager from 'electron-packager';
+import { hostArch } from 'electron-packager/targets';
 
-import electronHostArch from '../util/electron-host-arch';
 import getForgeConfig from '../util/forge-config';
 import runHook from '../util/hook';
 import realOra, { fakeOra } from '../util/ora';
@@ -38,7 +38,7 @@ export default async (providedOptions = {}) => {
   let { dir, interactive, arch, platform } = Object.assign({
     dir: process.cwd(),
     interactive: false,
-    arch: electronHostArch(),
+    arch: hostArch(),
     platform: process.platform,
   }, providedOptions);
 
diff --git a/src/util/electron-host-arch.js b/src/util/electron-host-arch.js
deleted file mode 100644
index 1ed8652f2..000000000
--- a/src/util/electron-host-arch.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export default () => {
-  if (process.arch === 'arm' && process.config.variables.arm_version === '7') {
-    return 'armv7l';
-  }
-
-  return process.arch;
-};
diff --git a/src/util/parse-archs.js b/src/util/parse-archs.js
new file mode 100644
index 000000000..6f6c2073a
--- /dev/null
+++ b/src/util/parse-archs.js
@@ -0,0 +1,9 @@
+import { allOfficialArchsForPlatformAndVersion } from 'electron-packager/targets';
+
+export default function parseArchs(platform, declaredArch, electronVersion) {
+  if (declaredArch === 'all') {
+    return allOfficialArchsForPlatformAndVersion(platform, electronVersion) || ['x64'];
+  }
+
+  return declaredArch.split(',');
+}


Test patch:
diff --git a/test/fast/electron-host-arch_spec.js b/test/fast/electron-host-arch_spec.js
deleted file mode 100644
index faeb9eea6..000000000
--- a/test/fast/electron-host-arch_spec.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { expect } from 'chai';
-
-import electronHostArch from '../../src/util/electron-host-arch';
-
-describe('electron-host-arch', () => {
-  if (process.arch !== 'arm') {
-    describe('on non-arm systems', () => {
-      it('should return the current arch', () => {
-        expect(electronHostArch()).to.equal(process.arch);
-      });
-    });
-  }
-});
diff --git a/test/fast/parse-archs_spec.js b/test/fast/parse-archs_spec.js
new file mode 100644
index 000000000..931b7d3fe
--- /dev/null
+++ b/test/fast/parse-archs_spec.js
@@ -0,0 +1,21 @@
+import { expect } from 'chai';
+
+import parseArchs from '../../src/util/parse-archs';
+
+describe('parse-archs', () => {
+  it('should make an Array out of one arch', () => {
+    expect(parseArchs('linux', 'x64', '1.7.0')).to.deep.equal(['x64']);
+  });
+
+  it('should transform comma-separated values into an Array', () => {
+    expect(parseArchs('linux', 'ia32,x64', '1.7.0')).to.deep.equal(['ia32', 'x64']);
+  });
+
+  it('should use the official Electron arch list when arch is "all"', () => {
+    expect(parseArchs('win32', 'all', '1.7.0')).to.deep.equal(['ia32', 'x64']);
+  });
+
+  it('should default to [x64] when the platform is unknown', () => {
+    expect(parseArchs('nonexistent', 'all', '1.7.0')).to.deep.equal(['x64']);
+  });
+});
diff --git a/test/slow/api_spec_slow.js b/test/slow/api_spec_slow.js
index f377483cf..6e0e7b1e9 100644
--- a/test/slow/api_spec_slow.js
+++ b/test/slow/api_spec_slow.js
@@ -293,17 +293,6 @@ describe(`electron-forge API (with installer=${installer.substr(12)})`, () => {
             skipPackage: true,
           })).to.eventually.be.rejectedWith(/incompatible with this version/);
         });
-
-        it('should succeed when provided comma separated arches', async () => {
-          // Darwin only has x64 so we can't do this test on that platform
-          if (process.platform === 'darwin') return;
-
-          await forge.make({
-            dir,
-            arch: 'ia32,x64',
-            overrideTargets: ['zip'],
-          });
-        });
       });
     });