Skip to content

Commit

Permalink
fix: parse full semver string
Browse files Browse the repository at this point in the history
the semver-regex package only captures the core version number
  • Loading branch information
NikhilNarayana committed Nov 1, 2023
1 parent 5888f15 commit 05a0c22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/dolphin/install/ishiiInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/dolphin/install/mainlineInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -230,10 +233,9 @@ export class MainlineDolphinInstallation implements DolphinInstallation {
public async getDolphinVersion(): Promise<string | null> {
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;
Expand Down

0 comments on commit 05a0c22

Please sign in to comment.