From 785620d55b58aae21556e1b5ce1e78bb42d8541d Mon Sep 17 00:00:00 2001
From: Dmitry Shibanov <shibanov-1997@inbox.ru>
Date: Wed, 14 Dec 2022 19:08:19 +0100
Subject: [PATCH] optimize code

---
 dist/setup/index.js                           | 67 +++----------------
 src/distibutions/base-distribution.ts         |  9 ++-
 src/distibutions/nightly/nightly_builds.ts    |  8 ---
 .../official_builds/official_builds.ts        |  8 ---
 .../official_builds/rc/rc_builds.ts           |  8 ---
 src/distibutions/v8-canary/canary_builds.ts   |  8 ---
 6 files changed, 16 insertions(+), 92 deletions(-)

diff --git a/dist/setup/index.js b/dist/setup/index.js
index bb4428a4..857ffcbe 100644
--- a/dist/setup/index.js
+++ b/dist/setup/index.js
@@ -73244,6 +73244,14 @@ class BaseDistribution {
     findVersionInHoostedToolCacheDirectory() {
         return tc.find('node', this.nodeInfo.versionSpec, this.nodeInfo.arch);
     }
+    getNodejsVersions() {
+        return __awaiter(this, void 0, void 0, function* () {
+            const initialUrl = this.getDistributionUrl();
+            const dataUrl = `${initialUrl}/index.json`;
+            let response = yield this.httpClient.getJson(dataUrl);
+            return response.result || [];
+        });
+    }
     getNodejsDistInfo(version, osPlat) {
         let osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
         version = semver_1.default.clean(version) || '';
@@ -73454,15 +73462,6 @@ exports.getNodejsDistribution = getNodejsDistribution;
 
 "use strict";
 
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
-    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
-    return new (P || (P = Promise))(function (resolve, reject) {
-        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
-        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
-        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
-        step((generator = generator.apply(thisArg, _arguments || [])).next());
-    });
-};
 var __importStar = (this && this.__importStar) || function (mod) {
     if (mod && mod.__esModule) return mod;
     var result = {};
@@ -73524,14 +73523,6 @@ class NightlyNodejs extends base_distribution_1.default {
     getDistributionUrl() {
         return 'https://nodejs.org/download/nightly';
     }
-    getNodejsVersions() {
-        return __awaiter(this, void 0, void 0, function* () {
-            const initialUrl = this.getDistributionUrl();
-            const dataUrl = `${initialUrl}/index.json`;
-            let response = yield this.httpClient.getJson(dataUrl);
-            return response.result || [];
-        });
-    }
     createRangePreRelease(versionSpec, distribution = '') {
         let range;
         const [raw, prerelease] = this.splitVersionSpec(versionSpec);
@@ -73667,14 +73658,6 @@ class OfficialBuilds extends base_distribution_1.default {
     getDistributionUrl() {
         return `https://nodejs.org/dist`;
     }
-    getNodejsVersions() {
-        return __awaiter(this, void 0, void 0, function* () {
-            const initialUrl = this.getDistributionUrl();
-            const dataUrl = `${initialUrl}/index.json`;
-            let response = yield this.httpClient.getJson(dataUrl);
-            return response.result || [];
-        });
-    }
     getManifest() {
         core.debug('Getting manifest from actions/node-versions@main');
         return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
@@ -73739,15 +73722,6 @@ exports["default"] = OfficialBuilds;
 
 "use strict";
 
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
-    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
-    return new (P || (P = Promise))(function (resolve, reject) {
-        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
-        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
-        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
-        step((generator = generator.apply(thisArg, _arguments || [])).next());
-    });
-};
 var __importStar = (this && this.__importStar) || function (mod) {
     if (mod && mod.__esModule) return mod;
     var result = {};
@@ -73766,14 +73740,6 @@ class RcBuild extends base_distribution_1.default {
     constructor(nodeInfo) {
         super(nodeInfo);
     }
-    getNodejsVersions() {
-        return __awaiter(this, void 0, void 0, function* () {
-            const initialUrl = this.getDistributionUrl();
-            const dataUrl = `${initialUrl}/index.json`;
-            let response = yield this.httpClient.getJson(dataUrl);
-            return response.result || [];
-        });
-    }
     evaluateVersions(versions) {
         let version = '';
         core.debug(`evaluating ${versions.length} versions`);
@@ -73807,15 +73773,6 @@ exports["default"] = RcBuild;
 
 "use strict";
 
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
-    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
-    return new (P || (P = Promise))(function (resolve, reject) {
-        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
-        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
-        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
-        step((generator = generator.apply(thisArg, _arguments || [])).next());
-    });
-};
 var __importStar = (this && this.__importStar) || function (mod) {
     if (mod && mod.__esModule) return mod;
     var result = {};
@@ -73877,14 +73834,6 @@ class CanaryBuild extends base_distribution_1.default {
         }
         return version;
     }
-    getNodejsVersions() {
-        return __awaiter(this, void 0, void 0, function* () {
-            const initialUrl = this.getDistributionUrl();
-            const dataUrl = `${initialUrl}/index.json`;
-            let response = yield this.httpClient.getJson(dataUrl);
-            return response.result || [];
-        });
-    }
     createRangePreRelease(versionSpec, distribution = '') {
         let range;
         const [raw, prerelease] = this.splitVersionSpec(versionSpec);
diff --git a/src/distibutions/base-distribution.ts b/src/distibutions/base-distribution.ts
index f843e732..5d488954 100644
--- a/src/distibutions/base-distribution.ts
+++ b/src/distibutions/base-distribution.ts
@@ -24,7 +24,6 @@ export default abstract class BaseDistribution {
   }
 
   protected abstract getDistributionUrl(): string;
-  protected abstract getNodejsVersions(): Promise<INodeVersion[]>;
   protected abstract evaluateVersions(nodeVersions: string[]): string;
 
   public async getNodeJsInfo() {
@@ -48,6 +47,14 @@ export default abstract class BaseDistribution {
     return tc.find('node', this.nodeInfo.versionSpec, this.nodeInfo.arch);
   }
 
+  protected async getNodejsVersions(): Promise<INodeVersion[]> {
+    const initialUrl = this.getDistributionUrl();
+    const dataUrl = `${initialUrl}/index.json`;
+
+    let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
+    return response.result || [];
+  }
+
   protected getNodejsDistInfo(version: string, osPlat: string) {
     let osArch: string = this.translateArchToDistUrl(this.nodeInfo.arch);
     version = semver.clean(version) || '';
diff --git a/src/distibutions/nightly/nightly_builds.ts b/src/distibutions/nightly/nightly_builds.ts
index ff8e824e..d40e930f 100644
--- a/src/distibutions/nightly/nightly_builds.ts
+++ b/src/distibutions/nightly/nightly_builds.ts
@@ -69,14 +69,6 @@ export default class NightlyNodejs extends BaseDistribution {
     return 'https://nodejs.org/download/nightly';
   }
 
-  async getNodejsVersions(): Promise<INodeVersion[]> {
-    const initialUrl = this.getDistributionUrl();
-    const dataUrl = `${initialUrl}/index.json`;
-
-    let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
-    return response.result || [];
-  }
-
   protected createRangePreRelease(
     versionSpec: string,
     distribution: string = ''
diff --git a/src/distibutions/official_builds/official_builds.ts b/src/distibutions/official_builds/official_builds.ts
index 85e68efd..cb2c2b46 100644
--- a/src/distibutions/official_builds/official_builds.ts
+++ b/src/distibutions/official_builds/official_builds.ts
@@ -131,14 +131,6 @@ export default class OfficialBuilds extends BaseDistribution {
     return `https://nodejs.org/dist`;
   }
 
-  protected async getNodejsVersions(): Promise<INodeVersion[]> {
-    const initialUrl = this.getDistributionUrl();
-    const dataUrl = `${initialUrl}/index.json`;
-
-    let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
-    return response.result || [];
-  }
-
   private getManifest(): Promise<tc.IToolRelease[]> {
     core.debug('Getting manifest from actions/node-versions@main');
     return tc.getManifestFromRepo(
diff --git a/src/distibutions/official_builds/rc/rc_builds.ts b/src/distibutions/official_builds/rc/rc_builds.ts
index 3c95fc95..d6e2d893 100644
--- a/src/distibutions/official_builds/rc/rc_builds.ts
+++ b/src/distibutions/official_builds/rc/rc_builds.ts
@@ -10,14 +10,6 @@ export default class RcBuild extends BaseDistribution {
     super(nodeInfo);
   }
 
-  protected async getNodejsVersions(): Promise<INodeVersion[]> {
-    const initialUrl = this.getDistributionUrl();
-    const dataUrl = `${initialUrl}/index.json`;
-
-    let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
-    return response.result || [];
-  }
-
   protected evaluateVersions(versions: string[]): string {
     let version = '';
 
diff --git a/src/distibutions/v8-canary/canary_builds.ts b/src/distibutions/v8-canary/canary_builds.ts
index 12d23eac..9568dad1 100644
--- a/src/distibutions/v8-canary/canary_builds.ts
+++ b/src/distibutions/v8-canary/canary_builds.ts
@@ -70,14 +70,6 @@ export default class CanaryBuild extends BaseDistribution {
     return version;
   }
 
-  async getNodejsVersions(): Promise<INodeVersion[]> {
-    const initialUrl = this.getDistributionUrl();
-    const dataUrl = `${initialUrl}/index.json`;
-
-    let response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
-    return response.result || [];
-  }
-
   protected createRangePreRelease(
     versionSpec: string,
     distribution: string = ''