Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion script/select-7z-arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions spec/assert-supported-arch-spec.ts
Original file line number Diff line number Diff line change
@@ -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'));
});
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
const checkCommand = os.platform() === 'win32' ? 'where' : 'which';
return new Promise((resolve) => {
Expand All @@ -64,6 +77,8 @@ function checkIfCommandExists(command: string): Promise<boolean> {
* @see {@link https://github.com/Squirrel/Squirrel.Windows | Squirrel.Windows}
*/
export async function createWindowsInstaller(options: SquirrelWindowsOptions): Promise<void> {
assertSupportedArch();

let useMono = false;

const monoExe = 'mono';
Expand Down