Skip to content

Commit 73d350a

Browse files
revert: PR #79 (#135)
You need run `isUrlRequest` before run `urlToRequest`.
1 parent aca43da commit 73d350a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ loaderUtils.stringifyRequest(this, "\\\\network-drive\\test.js");
115115

116116
Converts some resource URL to a webpack module request.
117117

118+
> i Before call `urlToRequest` you need call `isUrlRequest` to ensure it is requestable url
119+
120+
```javascript
121+
const url = "path/to/module.js";
122+
123+
if (loaderUtils.isUrlRequest(url)) {
124+
// Logic for requestable url
125+
const request = loaderUtils.urlToRequest(url);
126+
} else {
127+
// Logic for not requestable url
128+
}
129+
```
130+
131+
Simple example:
132+
118133
```javascript
119134
const url = "path/to/module.js";
120135
const request = loaderUtils.urlToRequest(url); // "./path/to/module.js"

lib/urlToRequest.js

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ function urlToRequest(url, root) {
4141
'.'
4242
);
4343
}
44-
} else if (/^(?:https?:)?\/\//.test(url)) {
45-
// Preserve http and https urls
46-
request = url;
4744
} else if (/^\.\.?\//.test(url)) {
4845
// A relative url stays
4946
request = url;

test/urlToRequest.test.js

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ ExpectedError.prototype.matches = function(err) {
1313
describe('urlToRequest()', () => {
1414
[
1515
// without root
16-
[['//google.com'], '//google.com', 'should handle scheme-agnostic urls'],
17-
[['http://google.com'], 'http://google.com', 'should handle http urls'],
18-
[['https://google.com'], 'https://google.com', 'should handle https urls'],
1916
[
2017
['path/to/thing'],
2118
'./path/to/thing',

0 commit comments

Comments
 (0)