setup-node/src/distributions/nightly/nightly_builds.ts

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-13 15:31:03 +01:00
import * as tc from '@actions/tool-cache';
2022-12-13 10:09:39 +01:00
import semver from 'semver';
import BaseDistribution from '../base-distribution';
2022-12-22 01:09:28 +01:00
import {INodejs} from '../base-models';
2022-12-13 10:09:39 +01:00
export default class NightlyNodejs extends BaseDistribution {
2022-12-22 01:51:36 +01:00
protected distribution = 'nightly';
2022-12-13 10:09:39 +01:00
constructor(nodeInfo: INodejs) {
super(nodeInfo);
}
2022-12-27 17:44:25 +01:00
protected findVersionInHostedToolCacheDirectory(): string {
2022-12-13 16:33:20 +01:00
let toolPath = '';
2022-12-13 16:27:32 +01:00
const localVersionPaths = tc
.findAllVersions('node', this.nodeInfo.arch)
.filter(i => {
const prerelease = semver.prerelease(i);
if (!prerelease) {
return false;
}
2022-12-22 01:51:36 +01:00
return prerelease[0].includes(this.distribution);
2022-12-13 16:27:32 +01:00
});
2022-12-22 00:05:42 +01:00
localVersionPaths.sort(semver.rcompare);
2022-12-13 15:31:03 +01:00
const localVersion = this.evaluateVersions(localVersionPaths);
2022-12-13 16:33:20 +01:00
if (localVersion) {
toolPath = tc.find('node', localVersion, this.nodeInfo.arch);
}
2022-12-13 15:31:03 +01:00
return toolPath;
}
2022-12-13 10:09:39 +01:00
protected getDistributionUrl(): string {
return 'https://nodejs.org/download/nightly';
}
2022-12-27 20:58:46 +01:00
protected validRange(versionSpec: string) {
2022-12-13 15:31:03 +01:00
let range: string;
2022-12-13 10:09:39 +01:00
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver.valid(raw);
const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!;
2022-12-22 01:51:36 +01:00
if (prerelease !== this.distribution) {
2022-12-13 15:31:03 +01:00
range = `${rawVersion}-${prerelease.replace(
2022-12-22 01:51:36 +01:00
this.distribution,
`${this.distribution}.`
2022-12-13 10:09:39 +01:00
)}`;
} else {
2022-12-22 01:51:36 +01:00
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
2022-12-13 10:09:39 +01:00
}
2022-12-27 20:58:46 +01:00
return {range, options: {includePrerelease: !isValidVersion}};
2022-12-13 10:09:39 +01:00
}
2022-12-13 15:31:03 +01:00
protected splitVersionSpec(versionSpec: string) {
2022-12-13 10:09:39 +01:00
return versionSpec.split(/-(.*)/s);
}
}