diff --git a/README.md b/README.md index a0d9c13e..7fd7cce1 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,16 @@ NPM module that builds Windows installers for npm install --save-dev electron-winstaller ``` +## Supported platforms + +Installers can be created on x64 and arm64 build machines (Windows, or +macOS/Linux with Wine and Mono). 32-bit build machines are not supported — +if you are on 64-bit Windows, make sure you are running 64-bit Node.js. + +Apps targeting 32-bit Windows (Electron <= 43) can still be packaged from +a 64-bit machine; the generated installer runs on 32-bit Windows. Electron +44 and later do not ship 32-bit Windows builds. + ## Usage Require the package: diff --git a/script/select-7z-arch.js b/script/select-7z-arch.js index 7be25c8c..4d68ada1 100644 --- a/script/select-7z-arch.js +++ b/script/select-7z-arch.js @@ -5,7 +5,12 @@ const os = require('os'); * Even if we're cross-compiling for a different arch like arm64, * we still need to use the 7-Zip executable for the host arch */ -const arch = os.arch; +const arch = os.arch(); + +if (arch !== 'x64' && arch !== 'arm64') { + console.warn('electron-winstaller: 32-bit build machines are not supported; installer creation will fail on this machine.'); + process.exit(0); +} console.log('Selecting 7-Zip for arch ' + arch); diff --git a/spec/assert-supported-arch-spec.ts b/spec/assert-supported-arch-spec.ts new file mode 100644 index 00000000..04e4a5fa --- /dev/null +++ b/spec/assert-supported-arch-spec.ts @@ -0,0 +1,12 @@ +import test from 'ava'; +import { assertSupportedArch } from '../src/index'; + +test('throws for 32-bit architectures', (t): void => { + t.throws(() => assertSupportedArch('ia32'), { message: '32-bit build machines are not supported' }); + t.throws(() => assertSupportedArch('arm'), { message: '32-bit build machines are not supported' }); +}); + +test('does not throw for 64-bit architectures', (t): void => { + t.notThrows(() => assertSupportedArch('x64')); + t.notThrows(() => assertSupportedArch('arm64')); +}); diff --git a/src/index.ts b/src/index.ts index c3148696..30c1d99e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,6 +47,19 @@ export function sanitizeAuthors(authors: string): string { return authors.replace(/@/g, ''); } +/** + * Asserts that the host architecture is supported. Installer creation + * requires an x64 or arm64 build machine; the bundled 7-Zip, NuGet, and + * Squirrel tooling cannot run on 32-bit hosts. + * + * @param arch The host architecture, as reported by `process.arch` + */ +export function assertSupportedArch(arch: string = process.arch): void { + if (arch !== 'x64' && arch !== 'arm64') { + throw new Error('32-bit build machines are not supported'); + } +} + function checkIfCommandExists(command: string): Promise { const checkCommand = os.platform() === 'win32' ? 'where' : 'which'; return new Promise((resolve) => { @@ -64,6 +77,8 @@ function checkIfCommandExists(command: string): Promise { * @see {@link https://github.com/Squirrel/Squirrel.Windows | Squirrel.Windows} */ export async function createWindowsInstaller(options: SquirrelWindowsOptions): Promise { + assertSupportedArch(); + let useMono = false; const monoExe = 'mono';