From b20a2561b99d471cbfe1222b16de377c5ccc78dc Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 20 May 2022 13:45:28 +0200 Subject: [PATCH] get manifest once --- dist/setup/index.js | 32 ++++++++++++++++---------------- src/installer.ts | 39 +++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4adfa5c2..e8cdb8cc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62339,20 +62339,24 @@ const tc = __importStar(__webpack_require__(533)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const fs = __webpack_require__(747); -const installer = __importStar(__webpack_require__(923)); 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 distManifest; let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let latestVersionResolved = false; 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)) { + distManifest = yield getVersionsFromDist(); + versionSpec = yield queryDistForMatch(versionSpec, arch, distManifest); + core.info(`getting latest node version...`); + } if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); const resolvedVersion = yield resolveVersionFromManifest(versionSpec, stable, auth, osArch, manifest); @@ -62364,11 +62368,6 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } - if (isLatestSyntax(versionSpec)) { - versionSpec = yield queryDistForMatch(versionSpec, arch); - latestVersionResolved = true; - core.info(`getting latest node version...`); - } // check cache let toolPath; toolPath = tc.find('node', versionSpec, osArch); @@ -62409,7 +62408,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch, latestVersionResolved); + info = yield getInfoFromDist(versionSpec, arch, distManifest); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62509,13 +62508,11 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch(), latestVersionResolved) { +function getInfoFromDist(versionSpec, arch = os.arch(), distManifest) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version = latestVersionResolved - ? versionSpec - : yield queryDistForMatch(versionSpec, arch); + let version = yield queryDistForMatch(versionSpec, arch, distManifest); if (!version) { return null; } @@ -62574,7 +62571,7 @@ function evaluateVersions(versions, versionSpec) { } return version; } -function queryDistForMatch(versionSpec, arch = os.arch()) { +function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); @@ -62593,13 +62590,16 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { default: throw new Error(`Unexpected OS '${osPlat}'`); } + if (!distManifest) { + core.debug('No dist manifest cached'); + distManifest = yield getVersionsFromDist(); + } let versions = []; - let nodeVersions = yield installer.getVersionsFromDist(); if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return nodeVersions[0].version; + return distManifest[0].version; } - nodeVersions.forEach((nodeVersion) => { + distManifest.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); diff --git a/src/installer.ts b/src/installer.ts index cfd69458..2956226e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -38,9 +38,9 @@ export async function getNode( ) { // Store manifest data to avoid multiple calls let manifest: INodeRelease[] | undefined; + let distManifest: INodeVersion[] | undefined; let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let latestVersionResolved: boolean = false; if (isLtsAlias(versionSpec)) { core.info('Attempt to resolve LTS alias from manifest...'); @@ -51,6 +51,12 @@ export async function getNode( versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } + if (isLatestSyntax(versionSpec)) { + distManifest = await getVersionsFromDist(); + versionSpec = await queryDistForMatch(versionSpec, arch, distManifest); + core.info(`getting latest node version...`); + } + if (checkLatest) { core.info('Attempt to resolve the latest version from manifest...'); const resolvedVersion = await resolveVersionFromManifest( @@ -68,12 +74,6 @@ export async function getNode( } } - if (isLatestSyntax(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); - latestVersionResolved = true; - core.info(`getting latest node version...`); - } - // check cache let toolPath: string; toolPath = tc.find('node', versionSpec, osArch); @@ -127,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch, latestVersionResolved); + info = await getInfoFromDist(versionSpec, arch, distManifest); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -274,14 +274,16 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, arch: string = os.arch(), - latestVersionResolved?: boolean + distManifest?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let version: string = latestVersionResolved - ? versionSpec - : await queryDistForMatch(versionSpec, arch); + let version: string = await queryDistForMatch( + versionSpec, + arch, + distManifest + ); if (!version) { return null; @@ -359,7 +361,8 @@ function evaluateVersions(versions: string[], versionSpec: string): string { async function queryDistForMatch( versionSpec: string, - arch: string = os.arch() + arch: string = os.arch(), + distManifest?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -380,15 +383,19 @@ async function queryDistForMatch( throw new Error(`Unexpected OS '${osPlat}'`); } + if (!distManifest) { + core.debug('No dist manifest cached'); + distManifest = await getVersionsFromDist(); + } + let versions: string[] = []; - let nodeVersions = await installer.getVersionsFromDist(); if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return nodeVersions[0].version; + return distManifest[0].version; } - nodeVersions.forEach((nodeVersion: INodeVersion) => { + distManifest.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version);