Skip to content

Commit 9ae47e5

Browse files
fix: remove normalize-url from deps (#623)
1 parent 71a9ce9 commit 9ae47e5

File tree

8 files changed

+159
-4645
lines changed

8 files changed

+159
-4645
lines changed

package-lock.json

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

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
},
4545
"dependencies": {
4646
"loader-utils": "^2.0.0",
47-
"normalize-url": "1.9.1",
4847
"schema-utils": "^3.0.0",
4948
"webpack-sources": "^1.1.0"
5049
},
@@ -75,7 +74,7 @@
7574
"npm-run-all": "^4.1.5",
7675
"prettier": "^2.1.2",
7776
"standard-version": "^9.0.0",
78-
"webpack": "^5.1.0",
77+
"webpack": "^5.1.3",
7978
"webpack-cli": "^4.1.0",
8079
"webpack-dev-server": "^3.7.2"
8180
},

src/hmr/hotModuleReplacement.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
func-names
66
*/
77

8-
const normalizeUrl = require('normalize-url');
8+
const normalizeUrl = require('./normalize-url');
99

1010
const srcByModuleId = Object.create(null);
1111

@@ -70,8 +70,7 @@ function getCurrentScriptUrl(moduleId) {
7070
const reg = new RegExp(`${filename}\\.js$`, 'g');
7171

7272
return normalizeUrl(
73-
src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`),
74-
{ stripWWW: false }
73+
src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`)
7574
);
7675
});
7776
};

src/hmr/normalize-url.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable */
2+
3+
function normalizeUrl(pathComponents) {
4+
return pathComponents
5+
.reduce(function (accumulator, item) {
6+
switch (item) {
7+
case '..':
8+
accumulator.pop();
9+
break;
10+
case '.':
11+
break;
12+
default:
13+
accumulator.push(item);
14+
}
15+
16+
return accumulator;
17+
}, [])
18+
.join('/');
19+
}
20+
21+
module.exports = function (urlString) {
22+
urlString = urlString.trim();
23+
24+
if (/^data:/i.test(urlString)) {
25+
return urlString;
26+
}
27+
28+
var protocol =
29+
urlString.indexOf('//') !== -1 ? urlString.split('//')[0] + '//' : '';
30+
var components = urlString.replace(new RegExp(protocol, 'i'), '').split('/');
31+
var host = components[0].toLowerCase().replace(/\.$/, '');
32+
33+
components[0] = '';
34+
35+
var path = normalizeUrl(components);
36+
37+
return protocol + host + path;
38+
};

0 commit comments

Comments
 (0)