Skip to content

Commit

Permalink
Revert "fix: use is-url-online to validate the download links"
Browse files Browse the repository at this point in the history
This reverts commit 232af3c.
  • Loading branch information
aminya committed Aug 8, 2022
1 parent 232af3c commit edc37d2
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.mjs.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"exec-powershell": "workspace:*",
"execa": "^5.1.1",
"extension-tools": "workspace:*",
"is-url-online": "^1.4.0",
"mri": "^1.2.0",
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"numerous": "1.0.3",
Expand Down
34 changes: 0 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/llvm/__tests__/llvm.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setupLLVM, VERSIONS, getUrl, setupClangTools, getLinuxUrl } from "../llvm"
import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { isUrlOnline } from "is-url-online"
import { isValidUrl } from "../../utils/http/validate_url"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import ciDetect from "@npmcli/ci-detect"
import execa from "execa"
Expand All @@ -14,7 +14,7 @@ jest.setTimeout(400000)
async function testUrl(version: string) {
const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, process.platform, version, getUrl)

if (!(await isUrlOnline(url))) {
if (!(await isValidUrl(url))) {
throw new Error(`Failed to install Version: ${version} => ${specificVersion} \n URL: ${url}`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/llvm/llvm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "path"
import semverLte from "semver/functions/lte"
import semverMajor from "semver/functions/major"
import { isUrlOnline } from "is-url-online"
import { isValidUrl } from "../utils/http/validate_url"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { extractExe, extractTarByExe } from "../utils/setup/extract"
import {
Expand Down Expand Up @@ -231,7 +231,7 @@ async function getWin32Url(version: string): Promise<string | null> {
let fallback = false
if (olderThan9_1) {
url = getReleaseUrl(version, prefix, suffix)
if (!(await isUrlOnline(url))) {
if (!(await isValidUrl(url))) {
fallback = true // fallback to github
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/utils/http/validate_url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as https from "https"

export function isValidUrl(url: string) {
return new Promise<boolean>((resolve) => {
https.get(url, (res) => {
if (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode <= 399) {
resolve(true)
} else {
resolve(false)
}
})
})
}
6 changes: 3 additions & 3 deletions src/utils/setup/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUrlOnline } from "is-url-online"
import { isValidUrl } from "../http/validate_url"
import semverCompare from "semver/functions/compare"
import semverCoerce from "semver/functions/coerce"
import semverValid from "semver/functions/valid"
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function getSpecificVersionAndUrl(
if (platform === "linux" && version.includes("ubuntu")) {
const url = await getUrl(platform, version)
// eslint-disable-next-line no-await-in-loop
if (url !== null && (await isUrlOnline(url))) {
if (url !== null && (await isValidUrl(url))) {
return [version, url]
}
}
Expand All @@ -55,7 +55,7 @@ export async function getSpecificVersionAndUrl(
// eslint-disable-next-line no-await-in-loop
const url = await getUrl(platform, specificVersion)
// eslint-disable-next-line no-await-in-loop
if (url !== null && (await isUrlOnline(url))) {
if (url !== null && (await isValidUrl(url))) {
return [specificVersion, url]
}
}
Expand Down

0 comments on commit edc37d2

Please sign in to comment.