Skip to content

Commit b334eb5

Browse files
alabbas-alimichael-ciniawsky
authored andcommitted
fix(karma-webpack): normalize paths (windows) (#353)
1 parent e2b444b commit b334eb5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/karma-webpack.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDepende
1515
var blocked = []
1616
var isBlocked = false
1717

18+
const normalize = (file) => file.replace(/\\/g, '/')
19+
1820
var escapeRegExp = function(str) {
1921
// See details here https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
2022
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')
@@ -208,7 +210,7 @@ Plugin.prototype.make = function(compilation, callback) {
208210

209211
var dep = new SingleEntryDependency(entry)
210212

211-
var filename = path.relative(this.basePath, file).replace(/\\/g, '/')
213+
var filename = normalize(path.relative(this.basePath, file))
212214
var name = path.join(path.dirname(filename), path.basename(filename, path.extname(filename)))
213215

214216
this.entries[name] = filename
@@ -231,7 +233,7 @@ Plugin.prototype.make = function(compilation, callback) {
231233
Plugin.prototype.readFile = function(file, callback) {
232234
var middleware = this.middleware
233235
var optionsCount = this.optionsCount
234-
236+
file = normalize(file)
235237
var doRead = function() {
236238
if (optionsCount > 1) {
237239
async.times(optionsCount, function(idx, callback) {
@@ -294,7 +296,7 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
294296
throw err
295297
}
296298

297-
var outputPath = webpackPlugin.outputs[filename]
299+
var outputPath = webpackPlugin.outputs[normalize(filename)]
298300
file.path = path.join(basePath, outputPath)
299301

300302
done(err, content && content.toString())
@@ -316,4 +318,4 @@ module.exports = {
316318
webpackPlugin: ['type', Plugin],
317319
'preprocessor:webpack': ['factory', createPreprocesor],
318320
'middleware:webpackBlocker': ['factory', createWebpackBlocker]
319-
}
321+
}

0 commit comments

Comments
 (0)