From 8c66f89aefe59190295a477c99b61493eb25cd8b Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 16:48:16 +0200 Subject: [PATCH 1/9] improve latest version syntax --- dist/setup/index.js | 10 ++++------ package-lock.json | 2 +- package.json | 2 +- src/installer.ts | 14 +++++--------- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ecf99914..23e5d16c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62362,6 +62362,10 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } + if (['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = yield queryDistForMatch(versionSpec, arch); + core.info(`getting latest node version...`); + } // check cache let toolPath; toolPath = tc.find('node', versionSpec, osArch); @@ -62587,12 +62591,6 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { } let versions = []; let nodeVersions = yield getVersionsFromDist(); - if (versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node') { - core.info(`getting latest node version...`); - return nodeVersions[0].version; - } nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { diff --git a/package-lock.json b/package-lock.json index 87480e4a..dbadde06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/package.json b/package.json index 63b36edd..df56518d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "^1.19.1", + "prettier": "1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/src/installer.ts b/src/installer.ts index 5b87d29a..fb35d73f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,6 +66,11 @@ export async function getNode( } } + if (['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); + core.info(`getting latest node version...`); + } + // check cache let toolPath: string; toolPath = tc.find('node', versionSpec, osArch); @@ -373,15 +378,6 @@ async function queryDistForMatch( let versions: string[] = []; let nodeVersions = await getVersionsFromDist(); - if ( - versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node' - ) { - core.info(`getting latest node version...`); - return nodeVersions[0].version; - } - nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From 45e544a71a30e9753c47c60ffa6894206879eca6 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:02:08 +0200 Subject: [PATCH 2/9] fix versionSpec required error --- src/installer.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index fb35d73f..4029b596 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,8 +66,8 @@ export async function getNode( } } - if (['current', 'latest', 'node'].includes(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); + if(['current', 'latest', 'node'].includes(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -378,6 +378,15 @@ async function queryDistForMatch( let versions: string[] = []; let nodeVersions = await getVersionsFromDist(); + if ( + versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node' + ) { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } + nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From 9a03ebd9cc165b5097a085f36b4bf1479b417142 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:06:51 +0200 Subject: [PATCH 3/9] run build --- dist/setup/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 23e5d16c..6740015e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62591,6 +62591,12 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { } let versions = []; let nodeVersions = yield getVersionsFromDist(); + if (versionSpec === 'current' || + versionSpec === 'latest' || + versionSpec === 'node') { + core.info(`getting latest node version...`); + return nodeVersions[0].version; + } nodeVersions.forEach((nodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { From fd1b409bc3adb8a843e511763a0160bfa08e1aea Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:33:13 +0200 Subject: [PATCH 4/9] unit tests --- __tests__/installer.test.ts | 27 +++++++++++++++++++++++++++ dist/setup/index.js | 12 +++++++----- src/installer.ts | 17 +++++++++-------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 004362d0..f3eb8db9 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -913,4 +913,31 @@ describe('setup-node', () => { } ); }); + + describe('latest alias syntax from cache', () => { + it.each(['latest', 'current', 'node'])( + 'download the %s version if alias is provided', + async inputVersion => { + // Arrange + inputs['node-version'] = inputVersion; + const expectedVersion = nodeTestDist[0]; + + os.platform = 'darwin'; + os.arch = 'x64'; + + const toolPath = path.normalize( + `/cache/node/${expectedVersion.version}/x64` + ); + findSpy.mockReturnValue(toolPath); + + // Act + await main.run(); + + // assert + expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); + + expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); + } + ); + }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 6740015e..0a513f92 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62339,6 +62339,7 @@ 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 @@ -62362,7 +62363,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { core.info(`Failed to resolve version ${versionSpec} from manifest`); } } - if (['current', 'latest', 'node'].includes(versionSpec)) { + if (isLatestSyntax(versionSpec)) { versionSpec = yield queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -62590,10 +62591,8 @@ function queryDistForMatch(versionSpec, arch = os.arch()) { throw new Error(`Unexpected OS '${osPlat}'`); } let versions = []; - let nodeVersions = yield getVersionsFromDist(); - if (versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node') { + let nodeVersions = yield installer.getVersionsFromDist(); + if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); return nodeVersions[0].version; } @@ -62692,6 +62691,9 @@ function parseNodeVersionFile(contents) { return nodeVersion; } exports.parseNodeVersionFile = parseNodeVersionFile; +function isLatestSyntax(versionSpec) { + return ['current', 'latest', 'node'].includes(versionSpec); +} /***/ }), diff --git a/src/installer.ts b/src/installer.ts index 4029b596..4f7603ae 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,6 +7,7 @@ import * as tc from '@actions/tool-cache'; import * as path from 'path'; import * as semver from 'semver'; import fs = require('fs'); +import * as installer from './installer'; // // Node versions interface @@ -66,8 +67,8 @@ export async function getNode( } } - if(['current', 'latest', 'node'].includes(versionSpec)) { - versionSpec = await queryDistForMatch(versionSpec, arch); + if (isLatestSyntax(versionSpec)) { + versionSpec = await queryDistForMatch(versionSpec, arch); core.info(`getting latest node version...`); } @@ -376,13 +377,9 @@ async function queryDistForMatch( } let versions: string[] = []; - let nodeVersions = await getVersionsFromDist(); + let nodeVersions = await installer.getVersionsFromDist(); - if ( - versionSpec === 'current' || - versionSpec === 'latest' || - versionSpec === 'node' - ) { + if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); return nodeVersions[0].version; } @@ -487,3 +484,7 @@ export function parseNodeVersionFile(contents: string): string { } return nodeVersion; } + +function isLatestSyntax(versionSpec): boolean { + return ['current', 'latest', 'node'].includes(versionSpec); +} From 808c8f917fea369038867811c092cb7843514fbb Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 17:38:21 +0200 Subject: [PATCH 5/9] remove bumping deps --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index dbadde06..87480e4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "1.19.1", + "prettier": "^1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } diff --git a/package.json b/package.json index df56518d..63b36edd 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@zeit/ncc": "^0.21.0", "jest": "^27.2.5", "jest-circus": "^27.2.5", - "prettier": "1.19.1", + "prettier": "^1.19.1", "ts-jest": "^27.0.5", "typescript": "^3.8.3" } From 141334fcd1248aba82bae2a0682d9f5a5e06cf84 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Thu, 19 May 2022 18:21:03 +0200 Subject: [PATCH 6/9] remove unnecessary dist call --- dist/setup/index.js | 11 +++++++---- src/installer.ts | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0a513f92..4adfa5c2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62346,6 +62346,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { let manifest; 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 @@ -62365,6 +62366,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { } if (isLatestSyntax(versionSpec)) { versionSpec = yield queryDistForMatch(versionSpec, arch); + latestVersionResolved = true; core.info(`getting latest node version...`); } // check cache @@ -62407,7 +62409,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch); + info = yield getInfoFromDist(versionSpec, arch, latestVersionResolved); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62507,12 +62509,13 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch()) { +function getInfoFromDist(versionSpec, arch = os.arch(), latestVersionResolved) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version; - version = yield queryDistForMatch(versionSpec, arch); + let version = latestVersionResolved + ? versionSpec + : yield queryDistForMatch(versionSpec, arch); if (!version) { return null; } diff --git a/src/installer.ts b/src/installer.ts index 4f7603ae..cfd69458 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -40,6 +40,7 @@ export async function getNode( let manifest: INodeRelease[] | 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...'); @@ -69,6 +70,7 @@ export async function getNode( if (isLatestSyntax(versionSpec)) { versionSpec = await queryDistForMatch(versionSpec, arch); + latestVersionResolved = true; core.info(`getting latest node version...`); } @@ -125,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch); + info = await getInfoFromDist(versionSpec, arch, latestVersionResolved); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -271,14 +273,16 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, - arch: string = os.arch() + arch: string = os.arch(), + latestVersionResolved?: boolean ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); - let version: string; + let version: string = latestVersionResolved + ? versionSpec + : await queryDistForMatch(versionSpec, arch); - version = await queryDistForMatch(versionSpec, arch); if (!version) { return null; } From b20a2561b99d471cbfe1222b16de377c5ccc78dc Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 20 May 2022 13:45:28 +0200 Subject: [PATCH 7/9] 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); From 7569de03e709e75afc4815ae1688120e2c5bc068 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Fri, 20 May 2022 16:32:52 +0200 Subject: [PATCH 8/9] rename dist manifest to node versions --- dist/setup/index.js | 22 +++++++++++----------- src/installer.ts | 22 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index e8cdb8cc..8a4d83b5 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -62343,7 +62343,7 @@ 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 nodeVersions; let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); if (isLtsAlias(versionSpec)) { @@ -62353,8 +62353,8 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { versionSpec = resolveLtsAliasFromManifest(versionSpec, stable, manifest); } if (isLatestSyntax(versionSpec)) { - distManifest = yield getVersionsFromDist(); - versionSpec = yield queryDistForMatch(versionSpec, arch, distManifest); + nodeVersions = yield getVersionsFromDist(); + versionSpec = yield queryDistForMatch(versionSpec, arch, nodeVersions); core.info(`getting latest node version...`); } if (checkLatest) { @@ -62408,7 +62408,7 @@ function getNode(versionSpec, stable, checkLatest, auth, arch = os.arch()) { // Download from nodejs.org // if (!downloadPath) { - info = yield getInfoFromDist(versionSpec, arch, distManifest); + info = yield getInfoFromDist(versionSpec, arch, nodeVersions); if (!info) { throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`); } @@ -62508,11 +62508,11 @@ function getInfoFromManifest(versionSpec, stable, auth, osArch = translateArchTo return info; }); } -function getInfoFromDist(versionSpec, arch = os.arch(), distManifest) { +function getInfoFromDist(versionSpec, arch = os.arch(), nodeVersions) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); - let version = yield queryDistForMatch(versionSpec, arch, distManifest); + let version = yield queryDistForMatch(versionSpec, arch, nodeVersions); if (!version) { return null; } @@ -62571,7 +62571,7 @@ function evaluateVersions(versions, versionSpec) { } return version; } -function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { +function queryDistForMatch(versionSpec, arch = os.arch(), nodeVersions) { return __awaiter(this, void 0, void 0, function* () { let osPlat = os.platform(); let osArch = translateArchToDistUrl(arch); @@ -62590,16 +62590,16 @@ function queryDistForMatch(versionSpec, arch = os.arch(), distManifest) { default: throw new Error(`Unexpected OS '${osPlat}'`); } - if (!distManifest) { + if (!nodeVersions) { core.debug('No dist manifest cached'); - distManifest = yield getVersionsFromDist(); + nodeVersions = yield getVersionsFromDist(); } let versions = []; if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return distManifest[0].version; + return nodeVersions[0].version; } - distManifest.forEach((nodeVersion) => { + nodeVersions.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 2956226e..6e79132d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -38,7 +38,7 @@ export async function getNode( ) { // Store manifest data to avoid multiple calls let manifest: INodeRelease[] | undefined; - let distManifest: INodeVersion[] | undefined; + let nodeVersions: INodeVersion[] | undefined; let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -52,8 +52,8 @@ export async function getNode( } if (isLatestSyntax(versionSpec)) { - distManifest = await getVersionsFromDist(); - versionSpec = await queryDistForMatch(versionSpec, arch, distManifest); + nodeVersions = await getVersionsFromDist(); + versionSpec = await queryDistForMatch(versionSpec, arch, nodeVersions); core.info(`getting latest node version...`); } @@ -127,7 +127,7 @@ export async function getNode( // Download from nodejs.org // if (!downloadPath) { - info = await getInfoFromDist(versionSpec, arch, distManifest); + info = await getInfoFromDist(versionSpec, arch, nodeVersions); if (!info) { throw new Error( `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` @@ -274,7 +274,7 @@ async function getInfoFromManifest( async function getInfoFromDist( versionSpec: string, arch: string = os.arch(), - distManifest?: INodeVersion[] + nodeVersions?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -282,7 +282,7 @@ async function getInfoFromDist( let version: string = await queryDistForMatch( versionSpec, arch, - distManifest + nodeVersions ); if (!version) { @@ -362,7 +362,7 @@ function evaluateVersions(versions: string[], versionSpec: string): string { async function queryDistForMatch( versionSpec: string, arch: string = os.arch(), - distManifest?: INodeVersion[] + nodeVersions?: INodeVersion[] ): Promise { let osPlat: string = os.platform(); let osArch: string = translateArchToDistUrl(arch); @@ -383,19 +383,19 @@ async function queryDistForMatch( throw new Error(`Unexpected OS '${osPlat}'`); } - if (!distManifest) { + if (!nodeVersions) { core.debug('No dist manifest cached'); - distManifest = await getVersionsFromDist(); + nodeVersions = await getVersionsFromDist(); } let versions: string[] = []; if (isLatestSyntax(versionSpec)) { core.info(`getting latest node version...`); - return distManifest[0].version; + return nodeVersions[0].version; } - distManifest.forEach((nodeVersion: INodeVersion) => { + nodeVersions.forEach((nodeVersion: INodeVersion) => { // ensure this version supports your os and platform if (nodeVersion.files.indexOf(dataFileName) >= 0) { versions.push(nodeVersion.version); From b14573ddb960b7d615cb82f84704679a2ffbdf2c Mon Sep 17 00:00:00 2001 From: panticmilos Date: Mon, 23 May 2022 12:53:31 +0200 Subject: [PATCH 9/9] remove installer import --- src/installer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index 6e79132d..cd4619ea 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,6 @@ import * as tc from '@actions/tool-cache'; import * as path from 'path'; import * as semver from 'semver'; import fs = require('fs'); -import * as installer from './installer'; // // Node versions interface