From 000394d00123ccbe4f6b1fd01409380c38fb1362 Mon Sep 17 00:00:00 2001 From: removedporn <86824510+removedporn@users.noreply.github.com> Date: Thu, 16 Sep 2021 23:28:23 +0800 Subject: [PATCH] Delete src directory --- src/install.js | 77 ---------------------------------------- src/version.js | 96 -------------------------------------------------- 2 files changed, 173 deletions(-) delete mode 100644 src/install.js delete mode 100644 src/version.js diff --git a/src/install.js b/src/install.js deleted file mode 100644 index 31b160a..0000000 --- a/src/install.js +++ /dev/null @@ -1,77 +0,0 @@ -const os = require("os"); -const path = require("path"); -const process = require("process"); -const core = require("@actions/core"); -const tc = require("@actions/tool-cache"); - -/** - * @param {import("./version").Version} version - */ -async function install(version) { - const cachedPath = tc.find( - "deno", - version.isCanary ? `0.0.0-${version.version}` : version.version, - ); - if (cachedPath) { - core.info(`Using cached Deno installation from ${cachedPath}.`); - core.addPath(cachedPath); - return; - } - - const zip = zipName(); - const url = version.isCanary - ? `https://dl.deno.land/canary/${version.version}/${zip}` - : `https://github.com/denoland/deno/releases/download/v${version.version}/${zip}`; - - core.info(`Downloading Deno from ${url}.`); - - const zipPath = await tc.downloadTool(url); - const extractedFolder = await tc.extractZip(zipPath); - - const newCachedPath = await tc.cacheDir( - extractedFolder, - "deno", - version.isCanary ? `0.0.0-${version.version}` : version.version, - ); - core.info(`Cached Deno to ${newCachedPath}.`); - core.addPath(newCachedPath); - const denoInstallRoot = process.env.DENO_INSTALL_ROOT || - path.join(os.homedir(), ".deno", "bin"); - core.addPath(denoInstallRoot); -} - -/** @returns {string} */ -function zipName() { - let arch; - switch (process.arch) { - case "arm64": - arch = "aarch64"; - break; - case "x64": - arch = "x86_64"; - break; - default: - throw new Error(`Unsupported architechture ${process.arch}.`); - } - - let platform; - switch (process.platform) { - case "linux": - platform = "unknown-linux-gnu"; - break; - case "darwin": - platform = "apple-darwin"; - break; - case "win32": - platform = "pc-windows-msvc"; - break; - default: - throw new Error(`Unsupported platform ${process.platform}.`); - } - - return `deno-${arch}-${platform}.zip`; -} - -module.exports = { - install, -}; diff --git a/src/version.js b/src/version.js deleted file mode 100644 index 8322b9e..0000000 --- a/src/version.js +++ /dev/null @@ -1,96 +0,0 @@ -const semver = require("semver"); -const fetch = require("node-fetch"); - -const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/; - -/** - * @typedef VersionRange - * @property {string} range - * @property {boolean} isCanary - */ - -/** - * @typedef Version - * @property {string} version - * @property {boolean} isCanary - */ - -/** - * Parses the version from the user into a structure. - * - * @param {string | undefined} version - * @returns {VersionRange | null} - */ -function parseVersionRange(version) { - version = String(version) || "1.x"; - version = version.trim(); - - if (version == "canary") { - return { range: "latest", isCanary: true }; - } - - if (GIT_HASH_RE.test(version)) { - return { range: version, isCanary: true }; - } - - const range = semver.validRange(version); - if (range !== null) { - return { range, isCanary: false }; - } - - return null; -} - -/** - * @param {VersionRange} range - * @returns {Promise} - */ -async function resolveVersion({ range, isCanary }) { - if (isCanary) { - if (range === "latest") { - const res = await fetch("https://dl.deno.land/canary-latest.txt"); - if (res.status !== 200) { - throw new Error( - "Failed to fetch canary version info from dl.deno.land. Please try again later.", - ); - } - const version = (await res.text()).trim(); - return { version, isCanary: true }; - } - return { version: range, isCanary: true }; - } - - const res = await fetch( - "https://raw.githubusercontent.com/denoland/deno_website2/main/versions.json", - ); - if (res.status !== 200) { - throw new Error( - "Failed to fetch stable version info from raw.githubusercontent.com. Please try again later.", - ); - } - const versionJson = await res.json(); - if (!("cli" in versionJson)) { - throw new Error("Fetched stable version info is invalid."); - } - /** @type {string[]} */ - const versions = versionJson.cli; - if (!Array.isArray(versions)) { - throw new Error("Fetched stable version info is invalid."); - } - - let version = semver.maxSatisfying(versions, range); - if (version === null) { - return null; - } - version = semver.clean(version); - if (version === null) { - return null; - } - - return { version, isCanary: false }; -} - -module.exports = { - parseVersionRange, - resolveVersion, -};