mirror of https://github.com/aminya/setup-cpp
fix: fix semver regex match
This commit is contained in:
parent
088b9ab277
commit
723f5c82ff
|
@ -51,10 +51,10 @@ export async function getSpecificVersionAndUrl(
|
||||||
throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`)
|
throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const versionRegex = /v(\d\S*)\s/
|
export const defaultVersionRegex = /v?(\d\S*)/
|
||||||
|
|
||||||
/** Get the version of a binary */
|
/** Get the version of a binary */
|
||||||
export async function getBinVersion(file: string) {
|
export async function getBinVersion(file: string, versionRegex: RegExp = defaultVersionRegex) {
|
||||||
try {
|
try {
|
||||||
const { stderr, stdout } = await getExecOutput(file, ["--version"])
|
const { stderr, stdout } = await getExecOutput(file, ["--version"])
|
||||||
const version = stdout.match(versionRegex)?.[1] ?? stderr.match(versionRegex)?.[1]
|
const version = stdout.match(versionRegex)?.[1] ?? stderr.match(versionRegex)?.[1]
|
||||||
|
@ -66,8 +66,12 @@ export async function getBinVersion(file: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if the given bin is up to date against the target version */
|
/** Check if the given bin is up to date against the target version */
|
||||||
export async function isBinUptoDate(givenFile: string, targetVersion: string) {
|
export async function isBinUptoDate(
|
||||||
const givenVersion = await getBinVersion(givenFile)
|
givenFile: string,
|
||||||
|
targetVersion: string,
|
||||||
|
versionRegex: RegExp = defaultVersionRegex
|
||||||
|
) {
|
||||||
|
const givenVersion = await getBinVersion(givenFile, versionRegex)
|
||||||
if (
|
if (
|
||||||
typeof givenVersion === "string" &&
|
typeof givenVersion === "string" &&
|
||||||
typeof targetVersion === "string" &&
|
typeof targetVersion === "string" &&
|
||||||
|
|
Loading…
Reference in New Issue