Skip to content

Commit 073917d

Browse files
jamesgeorge007hiroppy
authored andcommitted
refactor: lib/util.js (#452)
* feat: refactor * fix: revert * fix: lint
1 parent 4399cbc commit 073917d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

lib/util.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ function getPaths(publicPath, compiler, url) {
2525
compilers[i].options.output.publicPath;
2626

2727
if (compilerPublicPath) {
28-
if (compilerPublicPath.indexOf('/') === 0) {
29-
compilerPublicPathBase = compilerPublicPath;
30-
} else {
31-
// handle the case where compilerPublicPath is a URL with hostname
32-
compilerPublicPathBase = parse(compilerPublicPath).pathname;
33-
}
28+
compilerPublicPathBase =
29+
compilerPublicPath.indexOf('/') === 0
30+
? compilerPublicPath // eslint-disable-next-line
31+
: // handle the case where compilerPublicPath is a URL with hostname
32+
parse(compilerPublicPath).pathname;
3433

3534
// check the url vs the path part of the compilerPublicPath
3635
if (url.indexOf(compilerPublicPathBase) === 0) {
@@ -66,21 +65,19 @@ module.exports = {
6665
const urlObject = parse(url);
6766
let filename;
6867

68+
const hostNameIsTheSame = localPrefix.hostname === urlObject.hostname;
69+
6970
// publicPath has the hostname that is not the same as request url's, should fail
7071
if (
7172
localPrefix.hostname !== null &&
7273
urlObject.hostname !== null &&
73-
localPrefix.hostname !== urlObject.hostname
74+
!hostNameIsTheSame
7475
) {
7576
return false;
7677
}
7778

7879
// publicPath is not in url, so it should fail
79-
if (
80-
publicPath &&
81-
localPrefix.hostname === urlObject.hostname &&
82-
url.indexOf(publicPath) !== 0
83-
) {
80+
if (publicPath && hostNameIsTheSame && url.indexOf(publicPath) !== 0) {
8481
return false;
8582
}
8683

0 commit comments

Comments
 (0)