Skip to content

Commit

Permalink
Fix outputPath check for node < 0.12 and node < 5.0 for Windows
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
SpaceK33z committed Sep 25, 2016
1 parent 1a536a0 commit 38ff513
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var MemoryFileSystem = require("memory-fs");
var mime = require("mime");
var parseRange = require("range-parser");
var path = require("path");
var pathIsAbsolute = require("path-is-absolute");
var getFilenameFromUrl = require("./lib/GetFilenameFromUrl");
var pathJoin = require("./lib/PathJoin");

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

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"memory-fs": "~0.3.0",
"mime": "^1.3.4",
"path-is-absolute": "^1.0.0",
"range-parser": "^1.0.3"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions test/FileSystem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ describe("FileSystem", function() {
middleware(compiler);
}, /output\.path/);
});

it("should not throw on valid outputPath config for Windows", function() {
var compiler = fakeWebpack();
compiler.outputPath = "C:/my/path";
middleware(compiler);
});
});

0 comments on commit 38ff513

Please sign in to comment.