better handling of (nodeRange === 'latest')
This commit is contained in:
parent
799a9b4883
commit
4163432e7d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
20
lib/index.js
20
lib/index.js
@ -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 });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user