polish code

This commit is contained in:
Dmitry Shibanov 2022-12-08 22:20:19 +01:00
parent 5a5cdc8151
commit 7e3178723a
2 changed files with 46 additions and 35 deletions

View file

@ -52,30 +52,7 @@ export async function getGo(
);
if (!stableVersion) {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
let candidates:
| IGoVersion[]
| null = await module.exports.getVersionsDist(dlUrl);
if (!candidates) {
throw new Error(`golang download url did not return results`);
}
const fixedCandidates = candidates.map(item => {
return {
...item,
version: makeSemver(item.version)
};
});
stableVersion = await resolveStableVersionInput(
versionSpec,
archFilter,
platFilter,
fixedCandidates
);
stableVersion = await resolveStableVersionDist(versionSpec, arch);
if (!stableVersion) {
throw new Error(
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
@ -389,6 +366,34 @@ export function parseGoVersionFile(versionFilePath: string): string {
return contents.trim();
}
async function resolveStableVersionDist(versionSpec: string, arch: string) {
let archFilter = sys.getArch(arch);
let platFilter = sys.getPlatform();
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
let candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
dlUrl
);
if (!candidates) {
throw new Error(`golang download url did not return results`);
}
const fixedCandidates = candidates.map(item => {
return {
...item,
version: makeSemver(item.version)
};
});
const stableVersion = await resolveStableVersionInput(
versionSpec,
archFilter,
platFilter,
fixedCandidates
);
return stableVersion;
}
export async function resolveStableVersionInput(
versionSpec: string,
arch: string,