Merge pull request #1015 from vaddisrinivas/main
fix(cli): replace is-url validation to support network hostnames like 'gateway'
This commit is contained in:
9
bin/utils/url.ts
vendored
9
bin/utils/url.ts
vendored
@@ -1,5 +1,4 @@
|
|||||||
import * as psl from 'psl';
|
import * as psl from 'psl';
|
||||||
import isUrl from 'is-url';
|
|
||||||
|
|
||||||
// Extracts the domain from a given URL.
|
// Extracts the domain from a given URL.
|
||||||
export function getDomain(inputUrl: string): string | null {
|
export function getDomain(inputUrl: string): string | null {
|
||||||
@@ -32,10 +31,10 @@ export function appendProtocol(inputUrl: string): string {
|
|||||||
// Normalizes the URL by ensuring it has a protocol and is valid.
|
// Normalizes the URL by ensuring it has a protocol and is valid.
|
||||||
export function normalizeUrl(urlToNormalize: string): string {
|
export function normalizeUrl(urlToNormalize: string): string {
|
||||||
const urlWithProtocol = appendProtocol(urlToNormalize);
|
const urlWithProtocol = appendProtocol(urlToNormalize);
|
||||||
|
try {
|
||||||
if (isUrl(urlWithProtocol)) {
|
new URL(urlWithProtocol);
|
||||||
return urlWithProtocol;
|
return urlWithProtocol;
|
||||||
} else {
|
} catch (err) {
|
||||||
throw new Error(`Your url "${urlWithProtocol}" is invalid`);
|
throw new Error(`Your url "${urlWithProtocol}" is invalid: ${(err as Error).message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@
|
|||||||
"commander": "^11.1.0",
|
"commander": "^11.1.0",
|
||||||
"file-type": "^18.7.0",
|
"file-type": "^18.7.0",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"is-url": "^1.2.4",
|
|
||||||
"loglevel": "^1.9.2",
|
"loglevel": "^1.9.2",
|
||||||
"ora": "^7.0.1",
|
"ora": "^7.0.1",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
@@ -70,7 +69,6 @@
|
|||||||
"@rollup/plugin-replace": "^5.0.7",
|
"@rollup/plugin-replace": "^5.0.7",
|
||||||
"@rollup/plugin-terser": "^0.4.4",
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/is-url": "^1.2.32",
|
|
||||||
"@types/node": "^20.17.10",
|
"@types/node": "^20.17.10",
|
||||||
"@types/page-icon": "^0.3.6",
|
"@types/page-icon": "^0.3.6",
|
||||||
"@types/prompts": "^2.4.9",
|
"@types/prompts": "^2.4.9",
|
||||||
|
|||||||
Reference in New Issue
Block a user