From abf8e614626510db2814dbe29f643e10d88651b8 Mon Sep 17 00:00:00 2001 From: Teamop Date: Tue, 4 Sep 2018 00:07:34 +0800 Subject: [PATCH 1/2] fix(karma-webpack): fix output assets path --- src/karma-webpack.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index e5c0d4e..7eaf6a4 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -308,7 +308,7 @@ Plugin.prototype.readFile = function(file, callback) { os.tmpdir(), '_karma_webpack_', String(idx), - this.outputs.get(file) + this.outputs.get(file.replace(/\\/g, '/')) ), callback ); @@ -334,7 +334,11 @@ Plugin.prototype.readFile = function(file, callback) { } else { try { const fileContents = middleware.fileSystem.readFileSync( - path.join(os.tmpdir(), '_karma_webpack_', this.outputs.get(file)) + path.join( + os.tmpdir(), + '_karma_webpack_', + this.outputs.get(file.replace(/\\/g, '/')) + ) ); callback(null, fileContents); @@ -383,9 +387,6 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) { throw err; } - const outputPath = webpackPlugin.outputs.get(filename); - file.path = path.join(basePath, outputPath); - done(err, content && content.toString()); }); }; From eae102ed26fafe47a3167c9135d22d0d721e4bc5 Mon Sep 17 00:00:00 2001 From: Teamop Date: Fri, 7 Sep 2018 21:58:52 +0800 Subject: [PATCH 2/2] fix(karma-webpack): normalize asset paths --- src/karma-webpack.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index 7eaf6a4..f2f7644 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -16,6 +16,8 @@ const SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDepen let blocked = []; let isBlocked = false; +const normalize = (file) => file.replace(/\\/g, '/'); + const escapeRegExp = function(str) { // See details here https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'); @@ -268,7 +270,9 @@ Plugin.prototype.make = function(compilation, callback) { const dep = new SingleEntryDependency(entry); - const filename = path.relative(this.basePath, file).replace(/\\/g, '/'); + const filename = normalize( + path.relative(this.basePath, file).replace(/\\/g, '/') + ); const name = path.join( path.dirname(filename), path.basename(filename, path.extname(filename)) @@ -297,7 +301,7 @@ Plugin.prototype.make = function(compilation, callback) { Plugin.prototype.readFile = function(file, callback) { const middleware = this.middleware; const optionsCount = this.optionsCount; - + file = normalize(file); const doRead = function() { if (optionsCount > 1) { async.times( @@ -308,7 +312,7 @@ Plugin.prototype.readFile = function(file, callback) { os.tmpdir(), '_karma_webpack_', String(idx), - this.outputs.get(file.replace(/\\/g, '/')) + this.outputs.get(file) ), callback ); @@ -334,11 +338,7 @@ Plugin.prototype.readFile = function(file, callback) { } else { try { const fileContents = middleware.fileSystem.readFileSync( - path.join( - os.tmpdir(), - '_karma_webpack_', - this.outputs.get(file.replace(/\\/g, '/')) - ) + path.join(os.tmpdir(), '_karma_webpack_', this.outputs.get(file)) ); callback(null, fileContents); @@ -387,6 +387,11 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) { throw err; } + const outputPath = webpackPlugin.outputs.get( + normalize(filename.replace(/\\/g, '/')) + ); + file.path = normalize(path.join(basePath, outputPath)); + done(err, content && content.toString()); }); };