Skip to content

Commit

Permalink
fix: remove normalize-url from deps (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Oct 19, 2020
1 parent 71a9ce9 commit 9ae47e5
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 4,645 deletions.
44 changes: 4 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
},
"dependencies": {
"loader-utils": "^2.0.0",
"normalize-url": "1.9.1",
"schema-utils": "^3.0.0",
"webpack-sources": "^1.1.0"
},
Expand Down Expand Up @@ -75,7 +74,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"webpack": "^5.1.0",
"webpack": "^5.1.3",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.7.2"
},
Expand Down
5 changes: 2 additions & 3 deletions src/hmr/hotModuleReplacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
func-names
*/

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

const srcByModuleId = Object.create(null);

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

return normalizeUrl(
src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`),
{ stripWWW: false }
src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`)
);
});
};
Expand Down
38 changes: 38 additions & 0 deletions src/hmr/normalize-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable */

function normalizeUrl(pathComponents) {
return pathComponents
.reduce(function (accumulator, item) {
switch (item) {
case '..':
accumulator.pop();
break;
case '.':
break;
default:
accumulator.push(item);
}

return accumulator;
}, [])
.join('/');
}

module.exports = function (urlString) {
urlString = urlString.trim();

if (/^data:/i.test(urlString)) {
return urlString;
}

var protocol =
urlString.indexOf('//') !== -1 ? urlString.split('//')[0] + '//' : '';
var components = urlString.replace(new RegExp(protocol, 'i'), '').split('/');
var host = components[0].toLowerCase().replace(/\.$/, '');

components[0] = '';

var path = normalizeUrl(components);

return protocol + host + path;
};
Loading

0 comments on commit 9ae47e5

Please sign in to comment.