Skip to content

Commit 8fc0b03

Browse files
authored
refactor: remove is-absolute-url in favor of method (#3609)
1 parent 974ce25 commit 8fc0b03

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

lib/Server.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ class Server {
4949
};
5050
}
5151

52+
// eslint-disable-next-line class-methods-use-this
53+
static isAbsoluteURL(URL) {
54+
// Don't match Windows paths `c:\`
55+
if (/^[a-zA-Z]:\\/.test(URL)) {
56+
return false;
57+
}
58+
59+
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
60+
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
61+
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
62+
}
63+
5264
static async getHostname(hostname) {
5365
if (hostname === "local-ip") {
5466
return (await internalIp.v4()) || (await internalIp.v6()) || "0.0.0.0";
@@ -523,10 +535,8 @@ class Server {
523535
}
524536

525537
if (options.static) {
526-
const isAbsoluteUrl = require("is-absolute-url");
527-
528538
options.static.forEach((staticOption) => {
529-
if (isAbsoluteUrl(staticOption.directory)) {
539+
if (Server.isAbsoluteURL(staticOption.directory)) {
530540
throw new Error("Using a URL as static.directory is not supported");
531541
}
532542

@@ -1193,7 +1203,6 @@ class Server {
11931203
}
11941204

11951205
openBrowser(defaultOpenTarget) {
1196-
const isAbsoluteUrl = require("is-absolute-url");
11971206
const open = require("open");
11981207

11991208
Promise.all(
@@ -1203,7 +1212,7 @@ class Server {
12031212
if (item.target === "<url>") {
12041213
openTarget = defaultOpenTarget;
12051214
} else {
1206-
openTarget = isAbsoluteUrl(item.target)
1215+
openTarget = Server.isAbsoluteURL(item.target)
12071216
? item.target
12081217
: new URL(item.target, defaultOpenTarget).toString();
12091218
}

package-lock.json

-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"http-proxy-middleware": "^2.0.0",
4646
"internal-ip": "^6.2.0",
4747
"ipaddr.js": "^2.0.1",
48-
"is-absolute-url": "^3.0.3",
4948
"killable": "^1.0.1",
5049
"open": "^8.0.9",
5150
"p-retry": "^4.5.0",

0 commit comments

Comments
 (0)