-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(karma-webpack): handle outputPath
correctly
#360
Changes from 3 commits
2c0715f
8b5a22d
7666ead
3470e92
a3a22b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,15 @@ var isBlocked = false | |
|
||
const normalize = (file) => file.replace(/\\/g, '/') | ||
|
||
var getJsOutput = (outputPathArray) => { | ||
for (var _i = 0; _i < outputPathArray.length; _i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - var _i
+ var i |
||
if (outputPathArray[_i].indexOf(".js") != -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How des this work? Could you give a five examples please? What happens if e.g There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - !=
+ !== There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are right. I did not consider this case actually? I have in my webpack config 3 entries. like In any case i will add .js.map to if condition which should solve this case also :) |
||
return outputPathArray[_i] | ||
} | ||
} | ||
return null | ||
} | ||
|
||
var escapeRegExp = function(str) { | ||
// See details here https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex | ||
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') | ||
|
@@ -130,7 +139,10 @@ function Plugin( | |
if ({}.hasOwnProperty.call(this.entries, entry)) { | ||
var entryPath = this.entries[entry] | ||
var outputPath = stats.assetsByChunkName[entry] | ||
this.outputs[entryPath] = outputPath | ||
if (Array.isArray(outputPath)) | ||
outputPath = getJsOutput(outputPath) | ||
if (outputPath != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - !=
+ !== |
||
this.outputs[entryPath] = outputPath | ||
} | ||
} | ||
|
||
|
@@ -237,11 +249,7 @@ Plugin.prototype.readFile = function(file, callback) { | |
var doRead = function() { | ||
if (optionsCount > 1) { | ||
async.times(optionsCount, function(idx, callback) { | ||
if (Array.isArray(this.outputs[file])) { | ||
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file][0]), callback); | ||
} else { | ||
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file]), callback); | ||
} | ||
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file]), callback) | ||
}.bind(this), function(err, contents) { | ||
if (err) { | ||
return callback(err) | ||
|
@@ -258,12 +266,7 @@ Plugin.prototype.readFile = function(file, callback) { | |
}) | ||
} else { | ||
try { | ||
var fileContents = '' | ||
if (Array.isArray(this.outputs[file])) { | ||
fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file][0])); | ||
} else { | ||
fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file])); | ||
} | ||
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file])) | ||
|
||
callback(undefined, fileContents) | ||
} catch (e) { | ||
|
@@ -306,11 +309,7 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) { | |
} | ||
|
||
var outputPath = webpackPlugin.outputs[normalize(filename)] | ||
if( Array.isArray(outputPath)){ | ||
file.path = normalize(path.join(basePath, outputPath[0])); | ||
} else { | ||
file.path = normalize(path.join(basePath, outputPath)); | ||
} | ||
file.path = normalize(path.join(basePath, outputPath)) | ||
|
||
done(err, content && content.toString()) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.