Skip to content

Commit 83c9b35

Browse files
committed
refactor: remove is-absolute-url in favor of method
1 parent 1307332 commit 83c9b35

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

lib/Server.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ class Server {
136136
return compilers.map((compiler) => compiler.options);
137137
}
138138

139+
// eslint-disable-next-line class-methods-use-this
140+
isAbsoluteURL(URL) {
141+
if (typeof URL !== "string") {
142+
throw new TypeError(`Expected a \`string\`, got \`${typeof URL}\``);
143+
}
144+
145+
// Don't match Windows paths `c:\`
146+
if (/^[a-zA-Z]:\\/.test(URL)) {
147+
return false;
148+
}
149+
150+
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
151+
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
152+
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(URL);
153+
}
154+
139155
// eslint-disable-next-line class-methods-use-this
140156
normalizeOptions(options) {
141157
// TODO: improve this to not use .find for compiler watchOptions
@@ -532,10 +548,8 @@ class Server {
532548
}
533549

534550
if (options.static) {
535-
const isAbsoluteUrl = require("is-absolute-url");
536-
537551
options.static.forEach((staticOption) => {
538-
if (isAbsoluteUrl(staticOption.directory)) {
552+
if (this.isAbsoluteURL(staticOption.directory)) {
539553
throw new Error("Using a URL as static.directory is not supported");
540554
}
541555

@@ -1202,7 +1216,6 @@ class Server {
12021216
}
12031217

12041218
openBrowser(defaultOpenTarget) {
1205-
const isAbsoluteUrl = require("is-absolute-url");
12061219
const open = require("open");
12071220

12081221
Promise.all(
@@ -1212,7 +1225,7 @@ class Server {
12121225
if (item.target === "<url>") {
12131226
openTarget = defaultOpenTarget;
12141227
} else {
1215-
openTarget = isAbsoluteUrl(item.target)
1228+
openTarget = this.isAbsoluteURL(item.target)
12161229
? item.target
12171230
: new URL(item.target, defaultOpenTarget).toString();
12181231
}

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)