Skip to content

Commit 2fb8e5c

Browse files
authored
fix: corrected the verification of Mono and Wine installation status (#488)
* fix: correct Mono and Wine existence checks * refactor: Add Promise.all based on review feedback
1 parent 155c2c1 commit 2fb8e5c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { createTempDir } from './temp-utils';
33
import * as fs from 'fs-extra';
44
import { Metadata, SquirrelWindowsOptions, PersonMetadata } from './options';
55
import * as path from 'path';
6+
import * as os from 'os';
7+
import { exec } from 'child_process';
68
import spawn from './spawn-promise';
79
import template from 'lodash.template';
810

@@ -22,6 +24,15 @@ export function convertVersion(version: string): string {
2224
}
2325
}
2426

27+
function checkIfCommandExists(command: string): Promise<boolean> {
28+
const checkCommand = os.platform() === 'win32' ? 'where' : 'which';
29+
return new Promise((resolve) => {
30+
exec(`${checkCommand} ${command}`, (error) => {
31+
resolve(error ? false : true);
32+
});
33+
});
34+
}
35+
2536

2637
export async function createWindowsInstaller(options: SquirrelWindowsOptions): Promise<void> {
2738
let useMono = false;
@@ -31,7 +42,12 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P
3142

3243
if (process.platform !== 'win32') {
3344
useMono = true;
34-
if (!wineExe || !monoExe) {
45+
const [hasWine, hasMono] = await Promise.all([
46+
checkIfCommandExists(wineExe),
47+
checkIfCommandExists(monoExe)
48+
]);
49+
50+
if (!hasWine || !hasMono) {
3551
throw new Error('You must install both Mono and Wine on non-Windows');
3652
}
3753

0 commit comments

Comments
 (0)