Skip to content

Commit

Permalink
fix(karma-webpack): normalize paths (windows) (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabbas-ali authored and michael-ciniawsky committed Sep 7, 2018
1 parent e2b444b commit b334eb5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/karma-webpack.js
Expand Up @@ -15,6 +15,8 @@ var SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDepende
var blocked = []
var isBlocked = false

const normalize = (file) => file.replace(/\\/g, '/')

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

var dep = new SingleEntryDependency(entry)

var filename = path.relative(this.basePath, file).replace(/\\/g, '/')
var filename = normalize(path.relative(this.basePath, file))
var name = path.join(path.dirname(filename), path.basename(filename, path.extname(filename)))

this.entries[name] = filename
Expand All @@ -231,7 +233,7 @@ Plugin.prototype.make = function(compilation, callback) {
Plugin.prototype.readFile = function(file, callback) {
var middleware = this.middleware
var optionsCount = this.optionsCount

file = normalize(file)
var doRead = function() {
if (optionsCount > 1) {
async.times(optionsCount, function(idx, callback) {
Expand Down Expand Up @@ -294,7 +296,7 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
throw err
}

var outputPath = webpackPlugin.outputs[filename]
var outputPath = webpackPlugin.outputs[normalize(filename)]
file.path = path.join(basePath, outputPath)

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

0 comments on commit b334eb5

Please sign in to comment.