mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-04-17 02:06:29 +00:00
Refactor version resolving (#852)
This commit is contained in:
committed by
GitHub
parent
cb84d12dc6
commit
cdfb2ee6dd
59
src/version/specifier.ts
Normal file
59
src/version/specifier.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import * as tc from "@actions/tool-cache";
|
||||
|
||||
export type ParsedVersionSpecifier =
|
||||
| {
|
||||
kind: "exact";
|
||||
normalized: string;
|
||||
raw: string;
|
||||
}
|
||||
| {
|
||||
kind: "latest";
|
||||
normalized: "latest";
|
||||
raw: string;
|
||||
}
|
||||
| {
|
||||
isSimpleMinimumVersionSpecifier: boolean;
|
||||
kind: "range";
|
||||
normalized: string;
|
||||
raw: string;
|
||||
};
|
||||
|
||||
export function normalizeVersionSpecifier(specifier: string): string {
|
||||
const trimmedSpecifier = specifier.trim();
|
||||
|
||||
if (trimmedSpecifier.startsWith("==")) {
|
||||
return trimmedSpecifier.slice(2);
|
||||
}
|
||||
|
||||
return trimmedSpecifier;
|
||||
}
|
||||
|
||||
export function parseVersionSpecifier(
|
||||
specifier: string,
|
||||
): ParsedVersionSpecifier {
|
||||
const raw = specifier.trim();
|
||||
const normalized = normalizeVersionSpecifier(raw);
|
||||
|
||||
if (normalized === "latest") {
|
||||
return {
|
||||
kind: "latest",
|
||||
normalized: "latest",
|
||||
raw,
|
||||
};
|
||||
}
|
||||
|
||||
if (tc.isExplicitVersion(normalized)) {
|
||||
return {
|
||||
kind: "exact",
|
||||
normalized,
|
||||
raw,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
isSimpleMinimumVersionSpecifier: raw.includes(">") && !raw.includes(","),
|
||||
kind: "range",
|
||||
normalized,
|
||||
raw,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user