Merge pull request #116 from aminya/is-url-online [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-08-09 00:55:25 -07:00 committed by GitHub
commit 58016a1d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 18 additions and 112 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/setup_cpp.mjs vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -61,7 +61,7 @@
"exec-powershell": "workspace:*", "exec-powershell": "workspace:*",
"execa": "^5.1.1", "execa": "^5.1.1",
"extension-tools": "workspace:*", "extension-tools": "workspace:*",
"get-works": "workspace:*", "is-url-online": "^1.5.0",
"mri": "^1.2.0", "mri": "^1.2.0",
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1", "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
"numerous": "1.0.3", "numerous": "1.0.3",

View File

@ -1,40 +0,0 @@
<h1 align="center">get-works</h1>
<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
<a href="#" target="_blank">
<img alt="License: Apache--2.0" src="https://img.shields.io/badge/License-Apache--2.0-yellow.svg" />
</a>
</p>
> Check if the GET request for the given URL works
## Install
```sh
npm install --save get-works
```
## Usage
<!-- INSERT GENERATED DOCS START -->
### `getWorks` (function)
Check if the GET request for the given URL works
**Parameters:**
- url (`string`) - The given URL
**returns:** Promise<boolean>
<!-- INSERT GENERATED DOCS END -->
## 🤝 Contributing
You can sponsor my work here:
https://github.com/sponsors/aminya
Pull requests, issues and feature requests are welcome.
See the [Contributing guide](https://github.com/aminya/setup-cpp/blob/master/CONTRIBUTING.md).

View File

@ -1,26 +0,0 @@
{
"name": "get-works",
"version": "1.0.0",
"description": "Check if the GET request for the given URL works",
"homepage": "https://github.com/aminya/setup-cpp",
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "./dist/index.js",
"source": "./src/index.ts",
"scripts": {
"build": "tsc"
},
"dependencies": {
"root-tools": "workspace:*"
},
"keywords": [
"url",
"link",
"uri",
"working",
"check",
"alive",
"ok",
"broken"
]
}

View File

@ -1,19 +0,0 @@
import * as https from "https"
/**
* Check if the GET request for the given URL works
*
* @param url The given URL
* @returns A promise that resolves to a boolean indicating if the URL works
*/
export function getWorks(url: string): Promise<boolean> {
return new Promise<boolean>((resolve) => {
https.get(url, (res) => {
if (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode <= 399) {
resolve(true)
} else {
resolve(false)
}
})
})
}

View File

@ -1,7 +0,0 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./src"]
}

View File

@ -35,7 +35,7 @@ importers:
execa: ^5.1.1 execa: ^5.1.1
extension-tools: workspace:* extension-tools: workspace:*
gen-readme: ^1.6.0 gen-readme: ^1.6.0
get-works: workspace:* is-url-online: ^1.5.0
jest: ^28.1.3 jest: ^28.1.3
loose-ts-check: ^1.2.0 loose-ts-check: ^1.2.0
mri: ^1.2.0 mri: ^1.2.0
@ -71,7 +71,7 @@ importers:
exec-powershell: link:packages/exec-powershell exec-powershell: link:packages/exec-powershell
execa: 5.1.1 execa: 5.1.1
extension-tools: link:packages/extension-tools extension-tools: link:packages/extension-tools
get-works: link:packages/get-works is-url-online: 1.5.0
mri: 1.2.0 mri: 1.2.0
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1 msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
numerous: 1.0.3 numerous: 1.0.3
@ -133,12 +133,6 @@ importers:
packages/extension-tools: packages/extension-tools:
specifiers: {} specifiers: {}
packages/get-works:
specifiers:
root-tools: workspace:*
dependencies:
root-tools: link:../root-tools
packages/root-tools: packages/root-tools:
specifiers: specifiers:
'@types/which': ^2.0.1 '@types/which': ^2.0.1
@ -5766,6 +5760,10 @@ packages:
resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==} resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==}
dev: true dev: true
/is-url-online/1.5.0:
resolution: {integrity: sha512-uN7eZhWzxuiJs0OeMIzzMcU5OqUrS0OBoLrorPi3gExjsIO1zkaT5kXfsSbai7FmPzLNg2j8NdbJqgr5l8S2xw==}
dev: false
/is-url/1.2.4: /is-url/1.2.4:
resolution: {integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==} resolution: {integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==}
dev: true dev: true

View File

@ -1,6 +1,6 @@
import { setupLLVM, VERSIONS, getUrl, setupClangTools, getLinuxUrl } from "../llvm" import { setupLLVM, VERSIONS, getUrl, setupClangTools, getLinuxUrl } from "../llvm"
import { getSpecificVersionAndUrl } from "../../utils/setup/version" import { getSpecificVersionAndUrl } from "../../utils/setup/version"
import { getWorks } from "get-works" import { isUrlOnline } from "is-url-online"
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers" import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
import ciDetect from "@npmcli/ci-detect" import ciDetect from "@npmcli/ci-detect"
import execa from "execa" import execa from "execa"
@ -14,7 +14,7 @@ jest.setTimeout(400000)
async function testUrl(version: string) { async function testUrl(version: string) {
const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, process.platform, version, getUrl) const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, process.platform, version, getUrl)
if (!(await getWorks(url))) { if (!(await isUrlOnline(url))) {
throw new Error(`Failed to install Version: ${version} => ${specificVersion} \n URL: ${url}`) throw new Error(`Failed to install Version: ${version} => ${specificVersion} \n URL: ${url}`)
} }
} }

View File

@ -1,7 +1,7 @@
import * as path from "path" import * as path from "path"
import semverLte from "semver/functions/lte" import semverLte from "semver/functions/lte"
import semverMajor from "semver/functions/major" import semverMajor from "semver/functions/major"
import { getWorks } from "get-works" import { isUrlOnline } from "is-url-online"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { extractExe, extractTarByExe } from "../utils/setup/extract" import { extractExe, extractTarByExe } from "../utils/setup/extract"
import { import {
@ -231,7 +231,7 @@ async function getWin32Url(version: string): Promise<string | null> {
let fallback = false let fallback = false
if (olderThan9_1) { if (olderThan9_1) {
url = getReleaseUrl(version, prefix, suffix) url = getReleaseUrl(version, prefix, suffix)
if (!(await getWorks(url))) { if (!(await isUrlOnline(url))) {
fallback = true // fallback to github fallback = true // fallback to github
} }
} }

View File

@ -1,4 +1,4 @@
import { getWorks } from "get-works" import { isUrlOnline } from "is-url-online"
import semverCompare from "semver/functions/compare" import semverCompare from "semver/functions/compare"
import semverCoerce from "semver/functions/coerce" import semverCoerce from "semver/functions/coerce"
import semverValid from "semver/functions/valid" import semverValid from "semver/functions/valid"
@ -42,7 +42,7 @@ export async function getSpecificVersionAndUrl(
if (platform === "linux" && version.includes("ubuntu")) { if (platform === "linux" && version.includes("ubuntu")) {
const url = await getUrl(platform, version) const url = await getUrl(platform, version)
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
if (url !== null && (await getWorks(url))) { if (url !== null && (await isUrlOnline(url))) {
return [version, url] return [version, url]
} }
} }
@ -55,7 +55,7 @@ export async function getSpecificVersionAndUrl(
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const url = await getUrl(platform, specificVersion) const url = await getUrl(platform, specificVersion)
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
if (url !== null && (await getWorks(url))) { if (url !== null && (await isUrlOnline(url))) {
return [specificVersion, url] return [specificVersion, url]
} }
} }