Support lts/-n aliases (#481)

This commit is contained in:
Jack Bates
2022-06-02 03:30:33 -07:00
committed by GitHub
parent ed1a46e9f2
commit eeb10cff27
6 changed files with 309 additions and 302 deletions

14
dist/setup/index.js vendored
View File

@ -70756,10 +70756,18 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
throw new Error(`Unable to parse LTS alias for Node version '${versionSpec}'`);
}
core.debug(`LTS alias '${alias}' for Node version '${versionSpec}'`);
// Supported formats are `lts/<alias>` and `lts/*`. Where asterisk means highest possible LTS.
// Supported formats are `lts/<alias>`, `lts/*`, and `lts/-n`. Where asterisk means highest possible LTS and -n means the nth-highest.
const n = Number(alias);
const aliases = Object.fromEntries(manifest
.filter(x => x.lts && x.stable === stable)
.map(x => [x.lts.toLowerCase(), x])
.reverse());
const numbered = Object.values(aliases);
const release = alias === '*'
? manifest.find(x => !!x.lts && x.stable === stable)
: manifest.find(x => { var _a; return ((_a = x.lts) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === alias && x.stable === stable; });
? numbered[numbered.length - 1]
: n < 0
? numbered[numbered.length - 1 + n]
: aliases[alias];
if (!release) {
throw new Error(`Unable to find LTS release '${alias}' for Node version '${versionSpec}'.`);
}