Skip to content

Commit ccf6513

Browse files
committed
Merge pull request webpack#661 from corporateanon/fix-windows-compiler
Compiler fails under Windows
2 parents 414302c + 87decf4 commit ccf6513

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

lib/Compiler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
var path = require("path");
56
var clone = require("clone");
67
var Tapable = require("tapable");
78

@@ -235,9 +236,9 @@ Compiler.prototype.emitAssets = function(compilation, callback) {
235236
if(queryStringIdx >= 0) {
236237
targetFile = targetFile.substr(0, queryStringIdx);
237238
}
238-
if(targetFile.indexOf("/") >= 0) {
239-
var idx = targetFile.lastIndexOf("/");
240-
var dir = targetFile.substr(0, idx);
239+
240+
if(targetFile.match(/\/|\\/)) {
241+
var dir = path.dirname(targetFile);
241242
this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut.bind(this));
242243
} else writeOut.call(this);
243244
function writeOut(err) {

test/Compiler.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe("Compiler", function() {
1212
options.entry = entry;
1313
options.context = path.join(__dirname, "fixtures");
1414
options.output.pathinfo = true;
15+
var logs = {
16+
mkdirp: [],
17+
writeFile: [],
18+
};
1519

1620
var c = new Compiler();
1721
c.options = new WebpackOptionsApply().process(options, c);
@@ -20,9 +24,11 @@ describe("Compiler", function() {
2024
c.outputFileSystem = {
2125
join: path.join.bind(path),
2226
mkdirp: function(path, callback) {
27+
logs.mkdirp.push(path);
2328
callback();
2429
},
2530
writeFile: function(name, content, callback) {
31+
logs.writeFile.push(name, content);
2632
files[name] = content.toString("utf-8");
2733
callback();
2834
}
@@ -44,9 +50,26 @@ describe("Compiler", function() {
4450
stats.errors[0].should.be.instanceOf(Error);
4551
throw stats.errors[0];
4652
}
53+
stats.logs = logs;
4754
callback(stats, files);
4855
});
4956
}
57+
it("should compile a single file to deep output", function(done) {
58+
var sep = path.sep;
59+
60+
compile("./c", {
61+
output: {
62+
path: 'what',
63+
filename: 'the' + sep + 'hell.js',
64+
}
65+
}, function(stats, files) {
66+
stats.logs.mkdirp.should.eql([
67+
'what',
68+
'what' + sep + 'the',
69+
]);
70+
done();
71+
});
72+
});
5073
it("should compile a single file", function(done) {
5174
compile("./c", {}, function(stats, files) {
5275
files.should.have.property("bundle.js").have.type("string");
@@ -135,4 +158,4 @@ describe("Compiler", function() {
135158
done();
136159
});
137160
});
138-
});
161+
});

0 commit comments

Comments
 (0)