Skip to content

Commit 38ff513

Browse files
committed
Fix outputPath check for node < 0.12 and node < 5.0 for Windows
`path.isAbsolute` does not work on node < 0.12 Also, since node v5 `path.isAbsolute` returns true for `/` (which we want), but for older versions it does not. Fixes #132 and comment in e896293
1 parent 1a536a0 commit 38ff513

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

middleware.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var MemoryFileSystem = require("memory-fs");
66
var mime = require("mime");
77
var parseRange = require("range-parser");
8-
var path = require("path");
8+
var pathIsAbsolute = require("path-is-absolute");
99
var getFilenameFromUrl = require("./lib/GetFilenameFromUrl");
1010
var pathJoin = require("./lib/PathJoin");
1111

@@ -56,7 +56,8 @@ module.exports = function(compiler, options) {
5656
options.filename = new RegExp("^[\/]{0,1}" + str + "$");
5757
}
5858
}
59-
if(typeof compiler.outputPath === "string" && !path.isAbsolute(compiler.outputPath)) {
59+
if(typeof compiler.outputPath === "string" &&
60+
!pathIsAbsolute.posix(compiler.outputPath) && !pathIsAbsolute.win32(compiler.outputPath)) {
6061
throw new Error("`output.path` needs to be an absolute path or `/`.");
6162
}
6263

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"memory-fs": "~0.3.0",
1111
"mime": "^1.3.4",
12+
"path-is-absolute": "^1.0.0",
1213
"range-parser": "^1.0.3"
1314
},
1415
"devDependencies": {

test/FileSystem.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ describe("FileSystem", function() {
3434
middleware(compiler);
3535
}, /output\.path/);
3636
});
37+
38+
it("should not throw on valid outputPath config for Windows", function() {
39+
var compiler = fakeWebpack();
40+
compiler.outputPath = "C:/my/path";
41+
middleware(compiler);
42+
});
3743
});

0 commit comments

Comments
 (0)