From 2fb8e5c5e5f60e8f64333dcfebaeb1b7c18693e4 Mon Sep 17 00:00:00 2001 From: BitYoungjae Date: Tue, 24 Oct 2023 15:32:43 +0900 Subject: [PATCH] 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 --- src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 60d812a..067a96e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,8 @@ import { createTempDir } from './temp-utils'; import * as fs from 'fs-extra'; import { Metadata, SquirrelWindowsOptions, PersonMetadata } from './options'; import * as path from 'path'; +import * as os from 'os'; +import { exec } from 'child_process'; import spawn from './spawn-promise'; import template from 'lodash.template'; @@ -22,6 +24,15 @@ export function convertVersion(version: string): string { } } +function checkIfCommandExists(command: string): Promise { + const checkCommand = os.platform() === 'win32' ? 'where' : 'which'; + return new Promise((resolve) => { + exec(`${checkCommand} ${command}`, (error) => { + resolve(error ? false : true); + }); + }); +} + export async function createWindowsInstaller(options: SquirrelWindowsOptions): Promise { let useMono = false; @@ -31,7 +42,12 @@ export async function createWindowsInstaller(options: SquirrelWindowsOptions): P if (process.platform !== 'win32') { useMono = true; - if (!wineExe || !monoExe) { + const [hasWine, hasMono] = await Promise.all([ + checkIfCommandExists(wineExe), + checkIfCommandExists(monoExe) + ]); + + if (!hasWine || !hasMono) { throw new Error('You must install both Mono and Wine on non-Windows'); }