From b334eb5e5ba962afacc41ddf398112c75ce8a1ab Mon Sep 17 00:00:00 2001 From: Alabbas Alhaj ali <8499432+alabbas-ali@users.noreply.github.com> Date: Fri, 7 Sep 2018 13:45:43 +0200 Subject: [PATCH] fix(karma-webpack): normalize paths (`windows`) (#353) --- src/karma-webpack.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index f3930a5..388e442 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -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, '\\$&') @@ -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 @@ -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) { @@ -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()) @@ -316,4 +318,4 @@ module.exports = { webpackPlugin: ['type', Plugin], 'preprocessor:webpack': ['factory', createPreprocesor], 'middleware:webpackBlocker': ['factory', createWebpackBlocker] -} +} \ No newline at end of file