From 05a0c220b353a81252fdaac53107f9b3eb5cb8cf Mon Sep 17 00:00:00 2001 From: Nikhil Narayana Date: Tue, 31 Oct 2023 17:23:19 -0700 Subject: [PATCH] fix: parse full semver string the semver-regex package only captures the core version number --- src/dolphin/install/ishiiInstallation.ts | 7 +++++-- src/dolphin/install/mainlineInstallation.ts | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dolphin/install/ishiiInstallation.ts b/src/dolphin/install/ishiiInstallation.ts index 2f6e2719b..8293ec42a 100644 --- a/src/dolphin/install/ishiiInstallation.ts +++ b/src/dolphin/install/ishiiInstallation.ts @@ -8,7 +8,6 @@ import * as fs from "fs-extra"; import os from "os"; import path from "path"; import { lt } from "semver"; -import semverRegex from "semver-regex"; import type { DolphinInstallation } from "../types"; import { DolphinLaunchType } from "../types"; @@ -19,6 +18,10 @@ const log = electronLog.scope("dolphin/ishiiInstallation"); const isLinux = process.platform === "linux"; +// taken from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string +const semverRegex = + /(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/; + export class IshiirukaDolphinInstallation implements DolphinInstallation { public readonly installationFolder: string; constructor(private readonly dolphinLaunchType: DolphinLaunchType) { @@ -219,7 +222,7 @@ export class IshiirukaDolphinInstallation implements DolphinInstallation { try { const dolphinPath = await this.findDolphinExecutable(); const dolphinVersionOut = spawnSync(dolphinPath, ["--version"]).stdout.toString(); - const match = dolphinVersionOut.match(semverRegex()); + const match = dolphinVersionOut.match(semverRegex); return match?.[0] ?? null; } catch (err) { return null; diff --git a/src/dolphin/install/mainlineInstallation.ts b/src/dolphin/install/mainlineInstallation.ts index 230837975..cfbbd3ddd 100644 --- a/src/dolphin/install/mainlineInstallation.ts +++ b/src/dolphin/install/mainlineInstallation.ts @@ -8,7 +8,6 @@ import * as fs from "fs-extra"; import os from "os"; import path from "path"; import { lt } from "semver"; -import semverRegex from "semver-regex"; import type { DolphinInstallation } from "../types"; import { DolphinLaunchType } from "../types"; @@ -19,6 +18,10 @@ const log = electronLog.scope("dolphin/mainlineInstallation"); const isLinux = process.platform === "linux"; +// taken from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string +const semverRegex = + /(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/; + export class MainlineDolphinInstallation implements DolphinInstallation { public readonly installationFolder: string; constructor(private readonly dolphinLaunchType: DolphinLaunchType, private readonly betaSuffix: string) { @@ -230,10 +233,9 @@ export class MainlineDolphinInstallation implements DolphinInstallation { public async getDolphinVersion(): Promise { try { const dolphinPath = await this.findDolphinExecutable(); - log.warn(`dolphinPath = ${dolphinPath}`); const dolphinVersionOut = spawnSync(dolphinPath, ["--version"]).stdout.toString(); log.warn(`dolphinVersionOut = ${dolphinVersionOut}`); - const match = dolphinVersionOut.match(semverRegex()); + const match = dolphinVersionOut.match(semverRegex); return match?.[0] ?? null; } catch (err) { return null;