Skip to content

Commit

Permalink
Build compiled js code
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Nov 9, 2022
1 parent d703091 commit de40daa
Showing 1 changed file with 81 additions and 15 deletions.
96 changes: 81 additions & 15 deletions dist/setup/index.js
Expand Up @@ -73189,23 +73189,26 @@ const tc = __importStar(__nccwpck_require__(7784));
const path = __importStar(__nccwpck_require__(1017));
const semver = __importStar(__nccwpck_require__(5911));
const fs = __nccwpck_require__(7147);
const isVersionCanary = (versionSpec) => versionSpec.includes(`-v8-canary`);
function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
// Store manifest data to avoid multiple calls
let manifest;
let nodeVersions;
let osPlat = os.platform();
let osArch = translateArchToDistUrl(arch);
let isCanary = isVersionCanary(versionSpec);
if (isLtsAlias(versionSpec)) {
core.info('Attempt to resolve LTS alias from manifest...');
// No try-catch since it's not possible to resolve LTS alias without manifest
manifest = yield getManifest(auth);
versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest);
}
if (isLatestSyntax(versionSpec)) {
nodeVersions = yield getVersionsFromDist();
// evaluate exact versionSpec from input
if (isLatestSyntax(versionSpec) || isCanary) {
nodeVersions = yield getVersionsFromDist(versionSpec);
versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions);
core.info(`getting latest node version...`);
core.info(`getting ${isCanary ? 'v8-canary' : 'latest'} node version ${versionSpec}...`);
}
if (checkLatest) {
core.info('Attempt to resolve the latest version from manifest...');
Expand All @@ -73219,8 +73222,16 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) {
}
}
// check cache
let toolPath;
toolPath = tc.find('node', versionSpec, osArch);
core.info('Attempt to find existing version in cache...');
let toolPath = '';
if (isCanary) {
const localVersions = tc.findAllVersions('node', osArch);
toolPath = evaluateVersions(localVersions, versionSpec);
}
else {
// TODO: tc.find should allow custom evolution
toolPath = tc.find('node', versionSpec, osArch);
}
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
Expand Down Expand Up @@ -73319,6 +73330,7 @@ exports.getNode = getNode;
function isLtsAlias(versionSpec) {
return versionSpec.startsWith('lts/');
}
exports.isLtsAlias = isLtsAlias;
function getManifest(auth) {
core.debug('Getting manifest from actions/node-versions@main');
return tc.getManifestFromRepo('actions', 'node-versions', auth, 'main');
Expand Down Expand Up @@ -73348,6 +73360,7 @@ function resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
core.debug(`Found LTS release '${release.version}' for Node version '${versionSpec}'`);
return release.version.split('.')[0];
}
exports.resolveLtsAliasFromManifest = resolveLtsAliasFromManifest;
function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchToDistUrl(os.arch()), manifest) {
return __awaiter(this, void 0, void 0, function* () {
let info = null;
Expand Down Expand Up @@ -73382,7 +73395,8 @@ function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) {
? `node-v${version}-win-${osArch}`
: `node-v${version}-${osPlat}-${osArch}`;
let urlFileName = osPlat == 'win32' ? `${fileName}.7z` : `${fileName}.tar.gz`;
let url = `https://nodejs.org/dist/v${version}/${urlFileName}`;
const initialUrl = getNodejsDistUrl(versionSpec);
const url = `${initialUrl}/v${version}/${urlFileName}`;
return {
downloadUrl: url,
resolvedVersion: version,
Expand Down Expand Up @@ -73413,9 +73427,12 @@ function evaluateVersions(versions, versionSpec) {
}
return -1;
});
const matcher = isVersionCanary(versionSpec)
? evaluateCanaryMatcher(versionSpec)
: potential => semver.satisfies(potential, versionSpec);
for (let i = versions.length - 1; i >= 0; i--) {
const potential = versions[i];
const satisfied = semver.satisfies(potential, versionSpec);
const satisfied = matcher(potential);
if (satisfied) {
version = potential;
break;
Expand All @@ -73429,6 +73446,26 @@ function evaluateVersions(versions, versionSpec) {
}
return version;
}
exports.evaluateVersions = evaluateVersions;
function getNodejsDistUrl(version) {
const prerelease = semver.prerelease(version);
if (version.includes('nightly')) {
core.debug('requested nightly distribution');
return 'https://nodejs.org/download/nightly';
}
else if (isVersionCanary(version)) {
core.debug('requested v8 canary distribution');
return 'https://nodejs.org/download/v8-canary';
}
else if (!prerelease) {
return 'https://nodejs.org/dist';
}
else {
core.debug('requested RC build');
return 'https://nodejs.org/download/rc';
}
}
exports.getNodejsDistUrl = getNodejsDistUrl;
function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
return __awaiter(this, void 0, void 0, function* () {
let osPlat = os.platform();
Expand All @@ -73450,13 +73487,13 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
}
if (!nodeVersions) {
core.debug('No dist manifest cached');
nodeVersions = yield getVersionsFromDist();
nodeVersions = yield getVersionsFromDist(versionSpec);
}
let versions = [];
if (isLatestSyntax(versionSpec)) {
core.info(`getting latest node version...`);
return nodeVersions[0].version;
}
let versions = [];
nodeVersions.forEach((nodeVersion) => {
// ensure this version supports your os and platform
if (nodeVersion.files.indexOf(dataFileName) >= 0) {
Expand All @@ -73468,9 +73505,11 @@ function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) {
return version;
});
}
function getVersionsFromDist() {
exports.queryDistForMatch = queryDistForMatch;
function getVersionsFromDist(versionSpec) {
return __awaiter(this, void 0, void 0, function* () {
let dataUrl = 'https://nodejs.org/dist/index.json';
const distUrl = getNodejsDistUrl(versionSpec);
const dataUrl = `${distUrl}/index.json`;
let httpClient = new hc.HttpClient('setup-node', [], {
allowRetries: true,
maxRetries: 3
Expand All @@ -73494,6 +73533,7 @@ exports.getVersionsFromDist = getVersionsFromDist;
// and lib file in a folder, not zipped.
function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
return __awaiter(this, void 0, void 0, function* () {
const initialUrl = getNodejsDistUrl(version);
let osPlat = os.platform();
let osArch = translateArchToDistUrl(arch);
// Create temporary folder to download in to
Expand All @@ -73505,8 +73545,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
let exeUrl;
let libUrl;
try {
exeUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/win-${osArch}/node.lib`;
exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
core.info(`Downloading only node binary from ${exeUrl}`);
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
Expand All @@ -73515,8 +73555,8 @@ function acquireNodeFromFallbackLocation(version, arch = os.arch()) {
}
catch (err) {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
exeUrl = `${initialUrl}/v${version}/node.exe`;
libUrl = `${initialUrl}/v${version}/node.lib`;
const exePath = yield tc.downloadTool(exeUrl);
yield io.cp(exePath, path.join(tempDir, 'node.exe'));
const libPath = yield tc.downloadTool(libUrl);
Expand Down Expand Up @@ -73570,6 +73610,32 @@ exports.parseNodeVersionFile = parseNodeVersionFile;
function isLatestSyntax(versionSpec) {
return ['current', 'latest', 'node'].includes(versionSpec);
}
exports.isLatestSyntax = isLatestSyntax;
function evaluateCanaryMatcher(versionSpec) {
var _a;
const [raw, prerelease] = versionSpec.split(/-(.*)/s);
const isValidVersion = semver.valid(raw);
const rawVersion = isValidVersion ? raw : (_a = semver.coerce(raw)) === null || _a === void 0 ? void 0 : _a.version;
if (rawVersion) {
if (prerelease === 'v8-canary') {
// it means versionSpec does not have timestamp
const range = semver.validRange(`^${rawVersion}`);
return (potential) => semver.satisfies(
// TODO: check latest?
potential.replace('-v8-canary', '+v8-canary.'), range);
}
else {
// see https://github.com/actions/setup-node/blob/00e1b6691b40cce14b5078cb411dd1ec7dab07f7/__tests__/verify-node.sh#L10
// there must be exact match
const range = `${rawVersion}-${prerelease}`;
return (potential) => semver.satisfies(
// TODO: check latest?
potential, range);
}
}
return () => false;
}
exports.evaluateCanaryMatcher = evaluateCanaryMatcher;


/***/ }),
Expand Down

0 comments on commit de40daa

Please sign in to comment.