better handling of (nodeRange === 'latest')

This commit is contained in:
Igor Klopov 2017-07-24 13:55:18 +03:00
parent 799a9b4883
commit 4163432e7d
2 changed files with 14 additions and 8 deletions

View File

@ -146,7 +146,7 @@ export class GitHub {
await this.downloadUrl(url, file, short);
return true;
} catch (error) {
log.info(`Asset '${tag}/${name}' not found by direct link`);
log.info('Asset not found by direct link:', JSON.stringify({ tag, name }));
return false;
}
}

View File

@ -30,25 +30,31 @@ export async function need (opts = {}) { // eslint-disable-line complexity
platform = toFancyPlatform(platform); // win32 -> win
arch = toFancyArch(arch); // ia32 -> x86
function listNodeVersions (includeLowPriority) {
return Object.keys(patchesJson)
function satisfyingNodeVersion (includeLowPriority) {
const versions = Object.keys(patchesJson)
.filter((nodeVersion) => includeLowPriority ||
!patchesJson[nodeVersion].lowPriority)
.filter((nodeVersion) => semver.satisfies(nodeVersion, nodeRange) ||
nodeRange === 'latest')
.sort((nv1, nv2) => semver.gt(nv1, nv2));
return versions.pop();
}
let nodeVersions = listNodeVersions(false);
let nodeVersion;
if (!nodeVersions.length) {
nodeVersions = listNodeVersions(true);
if (nodeRange === 'latest') {
nodeVersion = satisfyingNodeVersion(true);
} else {
nodeVersion = satisfyingNodeVersion(false);
if (!nodeVersion) {
nodeVersion = satisfyingNodeVersion(true);
}
}
if (!nodeVersions.length) {
if (!nodeVersion) {
throw wasReported(`No available node version satisfies '${opts.nodeRange}'`);
}
const nodeVersion = nodeVersions.pop();
const fetched = localPlace({ from: 'fetched', arch, nodeVersion, platform, version });
const built = localPlace({ from: 'built', arch, nodeVersion, platform, version });
const remote = remotePlace({ arch, nodeVersion, platform, version });