mirror of
https://github.com/actions/setup-node.git
synced 2025-07-25 16:08:25 +02:00
polish code
This commit is contained in:
parent
f3c48890ed
commit
cd6d6a6700
8 changed files with 283 additions and 125 deletions
|
@ -27,8 +27,9 @@ export default abstract class BaseDistribution {
|
|||
protected abstract evaluateVersions(nodeVersions: string[]): string;
|
||||
|
||||
public async getNodeJsInfo() {
|
||||
let nodeVersions: INodeVersion[] | undefined;
|
||||
if (this.nodeInfo.checkLatest) {
|
||||
const nodeVersions = await this.getNodejsVersions();
|
||||
nodeVersions = await this.getNodejsVersions();
|
||||
const versions = this.filterVersions(nodeVersions);
|
||||
const evaluatedVersion = this.evaluateVersions(versions);
|
||||
|
||||
|
@ -41,7 +42,7 @@ export default abstract class BaseDistribution {
|
|||
if (toolPath) {
|
||||
core.info(`Found in cache @ ${toolPath}`);
|
||||
} else {
|
||||
const nodeVersions = await this.getNodejsVersions();
|
||||
nodeVersions ??= await this.getNodejsVersions();
|
||||
const versions = this.filterVersions(nodeVersions);
|
||||
const evaluatedVersion = this.evaluateVersions(versions);
|
||||
if (!evaluatedVersion) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import BaseDistribution from '../base-distribution';
|
|||
import {INodejs} from '../base-models';
|
||||
|
||||
export default class NightlyNodejs extends BaseDistribution {
|
||||
protected distribution = 'nightly';
|
||||
constructor(nodeInfo: INodejs) {
|
||||
super(nodeInfo);
|
||||
}
|
||||
|
@ -21,7 +22,7 @@ export default class NightlyNodejs extends BaseDistribution {
|
|||
return false;
|
||||
}
|
||||
|
||||
return prerelease[0].includes('nightly');
|
||||
return prerelease[0].includes(this.distribution);
|
||||
});
|
||||
localVersionPaths.sort(semver.rcompare);
|
||||
const localVersion = this.evaluateVersions(localVersionPaths);
|
||||
|
@ -38,14 +39,13 @@ export default class NightlyNodejs extends BaseDistribution {
|
|||
core.debug(`evaluating ${versions.length} versions`);
|
||||
|
||||
const {includePrerelease, range} = this.createRangePreRelease(
|
||||
this.nodeInfo.versionSpec,
|
||||
'nightly'
|
||||
this.nodeInfo.versionSpec
|
||||
);
|
||||
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
const potential: string = versions[i];
|
||||
const satisfied: boolean = semver.satisfies(
|
||||
potential.replace('nightly', 'nightly.'),
|
||||
potential.replace(this.distribution, `${this.distribution}.`),
|
||||
range,
|
||||
{
|
||||
includePrerelease: includePrerelease
|
||||
|
@ -70,22 +70,19 @@ export default class NightlyNodejs extends BaseDistribution {
|
|||
return 'https://nodejs.org/download/nightly';
|
||||
}
|
||||
|
||||
protected createRangePreRelease(
|
||||
versionSpec: string,
|
||||
distribution: string = ''
|
||||
) {
|
||||
protected createRangePreRelease(versionSpec: string) {
|
||||
let range: string;
|
||||
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
|
||||
const isValidVersion = semver.valid(raw);
|
||||
const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!;
|
||||
|
||||
if (prerelease !== distribution) {
|
||||
if (prerelease !== this.distribution) {
|
||||
range = `${rawVersion}-${prerelease.replace(
|
||||
distribution,
|
||||
`${distribution}.`
|
||||
this.distribution,
|
||||
`${this.distribution}.`
|
||||
)}`;
|
||||
} else {
|
||||
range = `${semver.validRange(`^${rawVersion}-${distribution}`)}-0`;
|
||||
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
|
||||
}
|
||||
|
||||
return {range, includePrerelease: !isValidVersion};
|
||||
|
|
|
@ -19,6 +19,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
public async getNodeJsInfo() {
|
||||
let manifest: tc.IToolRelease[] | undefined;
|
||||
let nodeVersions: INodeVersion[] | undefined;
|
||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||
if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
|
||||
core.info('Attempt to resolve LTS alias from manifest...');
|
||||
|
||||
|
@ -42,7 +43,6 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
|
||||
if (this.nodeInfo.checkLatest) {
|
||||
core.info('Attempt to resolve the latest version from manifest...');
|
||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||
const resolvedVersion = await this.resolveVersionFromManifest(
|
||||
this.nodeInfo.versionSpec,
|
||||
osArch,
|
||||
|
@ -66,7 +66,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
let downloadPath = '';
|
||||
try {
|
||||
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
|
||||
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
|
||||
|
||||
const versionInfo = await this.getInfoFromManifest(
|
||||
this.nodeInfo.versionSpec,
|
||||
osArch,
|
||||
|
|
|
@ -7,6 +7,7 @@ import BaseDistribution from '../base-distribution';
|
|||
import {INodejs} from '../base-models';
|
||||
|
||||
export default class CanaryBuild extends BaseDistribution {
|
||||
protected distribution = 'v8-canary';
|
||||
constructor(nodeInfo: INodejs) {
|
||||
super(nodeInfo);
|
||||
}
|
||||
|
@ -21,7 +22,7 @@ export default class CanaryBuild extends BaseDistribution {
|
|||
return false;
|
||||
}
|
||||
|
||||
return prerelease[0].includes('v8-canary');
|
||||
return prerelease[0].includes(this.distribution);
|
||||
});
|
||||
localVersionPaths.sort(semver.rcompare);
|
||||
const localVersion = this.evaluateVersions(localVersionPaths);
|
||||
|
@ -42,14 +43,13 @@ export default class CanaryBuild extends BaseDistribution {
|
|||
core.debug(`evaluating ${versions.length} versions`);
|
||||
|
||||
const {includePrerelease, range} = this.createRangePreRelease(
|
||||
this.nodeInfo.versionSpec,
|
||||
'v8-canary'
|
||||
this.nodeInfo.versionSpec
|
||||
);
|
||||
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
const potential: string = versions[i];
|
||||
const satisfied: boolean = semver.satisfies(
|
||||
potential.replace('v8-canary', 'v8-canary.'),
|
||||
potential.replace(this.distribution, `${this.distribution}.`),
|
||||
range,
|
||||
{
|
||||
includePrerelease: includePrerelease
|
||||
|
@ -70,22 +70,19 @@ export default class CanaryBuild extends BaseDistribution {
|
|||
return version;
|
||||
}
|
||||
|
||||
protected createRangePreRelease(
|
||||
versionSpec: string,
|
||||
distribution: string = ''
|
||||
) {
|
||||
protected createRangePreRelease(versionSpec: string) {
|
||||
let range: string;
|
||||
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
|
||||
const isValidVersion = semver.valid(raw);
|
||||
const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!;
|
||||
|
||||
if (prerelease !== distribution) {
|
||||
if (prerelease !== this.distribution) {
|
||||
range = `${rawVersion}-${prerelease.replace(
|
||||
distribution,
|
||||
`${distribution}.`
|
||||
this.distribution,
|
||||
`${this.distribution}.`
|
||||
)}`;
|
||||
} else {
|
||||
range = `${semver.validRange(`^${rawVersion}-${distribution}`)}-0`;
|
||||
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
|
||||
}
|
||||
|
||||
return {range, includePrerelease: !isValidVersion};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue