Skip to content

Commit 59b3979

Browse files
author
Andrey Taranov
committed
Fix Windows filename backslash incompatibility
With some loaders (specifically with babel) under Windows the file names in the source map already come converted to forward slashes. This is incompatible with RequestShortener so that the source map paths are not shortened to a relative path. This change makes RequestShortener tolerant to such cases while preserving existing behaviour. Fixes webpack#1770
1 parent 9766f2b commit 59b3979

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/RequestShortener.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var path = require("path");
66

77
function RequestShortener(directory) {
8+
directory = directory.replace(/\\/g, "/");
89
var parentDirectory = path.dirname(directory);
910
if(/[\/\\]$/.test(directory)) directory = directory.substr(0, directory.length - 1);
1011
if(directory) {
@@ -23,7 +24,7 @@ function RequestShortener(directory) {
2324
}
2425

2526
if(__dirname.length >= 2) {
26-
var buildins = path.join(__dirname, "..");
27+
var buildins = path.join(__dirname, "..").replace(/\\/g, "/");
2728
var buildinsAsModule = currentDirectoryRegExp && currentDirectoryRegExp.test(buildins);
2829
var buildinsRegExp = buildins.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2930
buildinsRegExp = new RegExp("^" + buildinsRegExp + "|(!)" + buildinsRegExp, "g");
@@ -40,6 +41,7 @@ module.exports = RequestShortener;
4041
RequestShortener.prototype.shorten = function(request) {
4142
if(!request)
4243
return request;
44+
request = request.replace(/\\/g, "/");
4345
if(this.buildinsAsModule && this.buildinsRegExp)
4446
request = request.replace(this.buildinsRegExp, "!(webpack)");
4547
if(this.currentDirectoryRegExp)
@@ -48,7 +50,6 @@ RequestShortener.prototype.shorten = function(request) {
4850
request = request.replace(this.parentDirectoryRegExp, "!..");
4951
if(!this.buildinsAsModule && this.buildinsRegExp)
5052
request = request.replace(this.buildinsRegExp, "!(webpack)");
51-
request = request.replace(/\\/g, "/");
5253
request = request.replace(this.nodeModulesRegExp, "/~/");
5354
request = request.replace(this.indexJsRegExp, "$1");
5455
return request.replace(/^!|!$/, "");

0 commit comments

Comments
 (0)