minor changes

This commit is contained in:
Dmitry Shibanov 2022-12-28 15:36:07 +01:00
parent 166e53bba8
commit eec2a7e0d8
9 changed files with 184 additions and 148 deletions

166
dist/setup/index.js vendored
View file

@ -73220,6 +73220,81 @@ var Outputs;
})(Outputs = exports.Outputs || (exports.Outputs = {}));
/***/ }),
/***/ 957:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const tc = __importStar(__nccwpck_require__(7784));
const semver_1 = __importDefault(__nccwpck_require__(5911));
const base_distribution_1 = __importDefault(__nccwpck_require__(7));
class BasePrereleaseNodejs extends base_distribution_1.default {
constructor(nodeInfo) {
super(nodeInfo);
}
findVersionInHostedToolCacheDirectory() {
let toolPath = '';
const localVersionPaths = tc
.findAllVersions('node', this.nodeInfo.arch)
.filter(i => {
const prerelease = semver_1.default.prerelease(i);
if (!prerelease) {
return false;
}
return prerelease[0].includes(this.distribution);
});
localVersionPaths.sort(semver_1.default.rcompare);
const localVersion = this.evaluateVersions(localVersionPaths);
if (localVersion) {
toolPath = tc.find('node', localVersion, this.nodeInfo.arch);
}
return toolPath;
}
validRange(versionSpec) {
let range;
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver_1.default.valid(raw);
const rawVersion = (isValidVersion ? raw : semver_1.default.coerce(raw));
if (prerelease !== this.distribution) {
range = versionSpec;
}
else {
range = `${semver_1.default.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return { range, options: { includePrerelease: !isValidVersion } };
}
splitVersionSpec(versionSpec) {
return versionSpec.split(/-(.*)/s);
}
}
exports["default"] = BasePrereleaseNodejs;
/***/ }),
/***/ 7:
@ -73281,24 +73356,15 @@ class BaseDistribution {
return __awaiter(this, void 0, void 0, function* () {
let nodeJsVersions;
if (this.nodeInfo.checkLatest) {
nodeJsVersions = yield this.getNodeJsVersions();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (evaluatedVersion) {
this.nodeInfo.versionSpec = evaluatedVersion;
}
const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions);
this.nodeInfo.versionSpec = evaluatedVersion;
}
let toolPath = this.findVersionInHostedToolCacheDirectory();
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
}
else {
nodeJsVersions = nodeJsVersions !== null && nodeJsVersions !== void 0 ? nodeJsVersions : (yield this.getNodeJsVersions());
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
}
const evaluatedVersion = yield this.findVersionInDist(nodeJsVersions);
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = yield this.downloadNodejs(toolName);
}
@ -73308,6 +73374,19 @@ class BaseDistribution {
core.addPath(toolPath);
});
}
findVersionInDist(nodeJsVersions) {
return __awaiter(this, void 0, void 0, function* () {
if (!nodeJsVersions) {
nodeJsVersions = yield this.getNodeJsVersions();
}
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`);
}
return evaluatedVersion;
});
}
evaluateVersions(versions) {
let version = '';
const { range, options } = this.validRange(this.nodeInfo.versionSpec);
@ -73541,74 +73620,19 @@ exports.getNodejsDistribution = getNodejsDistribution;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const tc = __importStar(__nccwpck_require__(7784));
const semver_1 = __importDefault(__nccwpck_require__(5911));
const base_distribution_1 = __importDefault(__nccwpck_require__(7));
class NightlyNodejs extends base_distribution_1.default {
const base_distribution_prerelease_1 = __importDefault(__nccwpck_require__(957));
class NightlyNodejs extends base_distribution_prerelease_1.default {
constructor(nodeInfo) {
super(nodeInfo);
this.distribution = 'nightly';
}
findVersionInHostedToolCacheDirectory() {
let toolPath = '';
const localVersionPaths = tc
.findAllVersions('node', this.nodeInfo.arch)
.filter(i => {
const prerelease = semver_1.default.prerelease(i);
if (!prerelease) {
return false;
}
return prerelease[0].includes(this.distribution);
});
localVersionPaths.sort(semver_1.default.rcompare);
const localVersion = this.evaluateVersions(localVersionPaths);
if (localVersion) {
toolPath = tc.find('node', localVersion, this.nodeInfo.arch);
}
return toolPath;
}
getDistributionUrl() {
return 'https://nodejs.org/download/nightly';
}
validRange(versionSpec) {
let range;
const [raw, prerelease] = this.splitVersionSpec(versionSpec);
const isValidVersion = semver_1.default.valid(raw);
const rawVersion = (isValidVersion ? raw : semver_1.default.coerce(raw));
if (prerelease !== this.distribution) {
range = versionSpec;
}
else {
range = `${semver_1.default.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return { range, options: { includePrerelease: !isValidVersion } };
}
splitVersionSpec(versionSpec) {
return versionSpec.split(/-(.*)/s);
}
}
exports["default"] = NightlyNodejs;
@ -73853,8 +73877,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const nightly_builds_1 = __importDefault(__nccwpck_require__(7127));
class CanaryBuild extends nightly_builds_1.default {
const base_distribution_prerelease_1 = __importDefault(__nccwpck_require__(957));
class CanaryBuild extends base_distribution_prerelease_1.default {
constructor(nodeInfo) {
super(nodeInfo);
this.distribution = 'v8-canary';

View file

@ -0,0 +1,53 @@
import * as tc from '@actions/tool-cache';
import semver from 'semver';
import BaseDistribution from './base-distribution';
import {NodeInputs} from './base-models';
export default abstract class BasePrereleaseNodejs extends BaseDistribution {
protected abstract distribution: string;
constructor(nodeInfo: NodeInputs) {
super(nodeInfo);
}
protected findVersionInHostedToolCacheDirectory(): string {
let toolPath = '';
const localVersionPaths = tc
.findAllVersions('node', this.nodeInfo.arch)
.filter(i => {
const prerelease = semver.prerelease(i);
if (!prerelease) {
return false;
}
return prerelease[0].includes(this.distribution);
});
localVersionPaths.sort(semver.rcompare);
const localVersion = this.evaluateVersions(localVersionPaths);
if (localVersion) {
toolPath = tc.find('node', localVersion, this.nodeInfo.arch);
}
return toolPath;
}
protected validRange(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 !== this.distribution) {
range = versionSpec;
} else {
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return {range, options: {includePrerelease: !isValidVersion}};
}
protected splitVersionSpec(versionSpec: string) {
return versionSpec.split(/-(.*)/s);
}
}

View file

@ -10,13 +10,13 @@ import * as path from 'path';
import os from 'os';
import fs from 'fs';
import {INodejs, INodeVersion, INodeVersionInfo} from './base-models';
import {NodeInputs, INodeVersion, INodeVersionInfo} from './base-models';
export default abstract class BaseDistribution {
protected httpClient: hc.HttpClient;
protected osPlat = os.platform();
constructor(protected nodeInfo: INodejs) {
constructor(protected nodeInfo: NodeInputs) {
this.httpClient = new hc.HttpClient('setup-node', [], {
allowRetries: true,
maxRetries: 3
@ -28,27 +28,15 @@ export default abstract class BaseDistribution {
public async setupNodeJs() {
let nodeJsVersions: INodeVersion[] | undefined;
if (this.nodeInfo.checkLatest) {
nodeJsVersions = await this.getNodeJsVersions();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (evaluatedVersion) {
this.nodeInfo.versionSpec = evaluatedVersion;
}
const evaluatedVersion = await this.findVersionInDist(nodeJsVersions);
this.nodeInfo.versionSpec = evaluatedVersion;
}
let toolPath = this.findVersionInHostedToolCacheDirectory();
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
} else {
nodeJsVersions = nodeJsVersions ?? (await this.getNodeJsVersions());
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const evaluatedVersion = await this.findVersionInDist(nodeJsVersions);
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
}
@ -60,6 +48,21 @@ export default abstract class BaseDistribution {
core.addPath(toolPath);
}
protected async findVersionInDist(nodeJsVersions?: INodeVersion[]) {
if (!nodeJsVersions) {
nodeJsVersions = await this.getNodeJsVersions();
}
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
return evaluatedVersion;
}
protected evaluateVersions(versions: string[]): string {
let version = '';

View file

@ -1,4 +1,4 @@
export interface INodejs {
export interface NodeInputs {
versionSpec: string;
arch: string;
auth?: string;

View file

@ -1,5 +1,5 @@
import BaseDistribution from './base-distribution';
import {INodejs} from './base-models';
import {NodeInputs} from './base-models';
import NightlyNodejs from './nightly/nightly_builds';
import OfficialBuilds from './official_builds/official_builds';
import RcBuild from './rc/rc_builds';
@ -13,7 +13,7 @@ enum Distributions {
}
export function getNodejsDistribution(
installerOptions: INodejs
installerOptions: NodeInputs
): BaseDistribution {
const versionSpec = installerOptions.versionSpec;
let distribution: BaseDistribution;

View file

@ -1,57 +1,13 @@
import * as tc from '@actions/tool-cache';
import BasePrereleaseNodejs from '../base-distribution-prerelease';
import {NodeInputs} from '../base-models';
import semver from 'semver';
import BaseDistribution from '../base-distribution';
import {INodejs} from '../base-models';
export default class NightlyNodejs extends BaseDistribution {
export default class NightlyNodejs extends BasePrereleaseNodejs {
protected distribution = 'nightly';
constructor(nodeInfo: INodejs) {
constructor(nodeInfo: NodeInputs) {
super(nodeInfo);
}
protected findVersionInHostedToolCacheDirectory(): string {
let toolPath = '';
const localVersionPaths = tc
.findAllVersions('node', this.nodeInfo.arch)
.filter(i => {
const prerelease = semver.prerelease(i);
if (!prerelease) {
return false;
}
return prerelease[0].includes(this.distribution);
});
localVersionPaths.sort(semver.rcompare);
const localVersion = this.evaluateVersions(localVersionPaths);
if (localVersion) {
toolPath = tc.find('node', localVersion, this.nodeInfo.arch);
}
return toolPath;
}
protected getDistributionUrl(): string {
return 'https://nodejs.org/download/nightly';
}
protected validRange(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 !== this.distribution) {
range = versionSpec;
} else {
range = `${semver.validRange(`^${rawVersion}-${this.distribution}`)}-0`;
}
return {range, options: {includePrerelease: !isValidVersion}};
}
protected splitVersionSpec(versionSpec: string) {
return versionSpec.split(/-(.*)/s);
}
}

View file

@ -3,14 +3,14 @@ import * as tc from '@actions/tool-cache';
import path from 'path';
import BaseDistribution from '../base-distribution';
import {INodejs, INodeVersion, INodeVersionInfo} from '../base-models';
import {NodeInputs, INodeVersion, INodeVersionInfo} from '../base-models';
interface INodeRelease extends tc.IToolRelease {
lts?: string;
}
export default class OfficialBuilds extends BaseDistribution {
constructor(nodeInfo: INodejs) {
constructor(nodeInfo: NodeInputs) {
super(nodeInfo);
}

View file

@ -1,8 +1,8 @@
import BaseDistribution from '../base-distribution';
import {INodejs} from '../base-models';
import {NodeInputs} from '../base-models';
export default class RcBuild extends BaseDistribution {
constructor(nodeInfo: INodejs) {
constructor(nodeInfo: NodeInputs) {
super(nodeInfo);
}

View file

@ -1,10 +1,10 @@
import {INodejs} from '../base-models';
import NightlyNodejs from '../nightly/nightly_builds';
import BasePrereleaseNodejs from '../base-distribution-prerelease';
import {NodeInputs} from '../base-models';
export default class CanaryBuild extends NightlyNodejs {
constructor(nodeInfo: INodejs) {
export default class CanaryBuild extends BasePrereleaseNodejs {
protected distribution = 'v8-canary';
constructor(nodeInfo: NodeInputs) {
super(nodeInfo);
this.distribution = 'v8-canary';
}
protected getDistributionUrl(): string {