Skip to content

Commit

Permalink
handle errors/warnings in child compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBorg committed Oct 9, 2018
1 parent 79140d3 commit 4131c51
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 13,21 @@ var WebpackNotifierPlugin = module.exports = function(options) {
};

WebpackNotifierPlugin.prototype.compileMessage = function(stats) {
function findFirstDFS(compilation, key) {
var match = compilation[key][0];
if (match) {
return match;
}

var children = compilation.children;

This comment has been minimized.

Copy link
@Gvozd

Gvozd Dec 6, 2020

Collaborator

@RobertBorg
I cover the plugin with tests
Please tell me the case when the error comes from the child compilation?
Probably some kind of plugin like extract-text-webpack-plugin, but I couldn't find a suitable plugin

This comment has been minimized.

Copy link
@RobertBorg

RobertBorg Dec 6, 2020

Author

if i remember correctly it was a warning in a child compilation from mini-css-extract-plugin. I'm not sure i've ever seen the issue with a error coming from a child compilation.

This comment has been minimized.

Copy link
@Gvozd

Gvozd Dec 6, 2020

Collaborator

Thanks
I was unable to repeat the problem with mini-css-extract-plugin

But looking at his code with a fresh mind, I managed to make a mock test plugin to simulate this behavior.

for (var i = 0; i < children.length; i) {
match = findFirstDFS(children[i], key);
if (match) {
return match;
}
}
}

if (this.isFirstBuild) {
this.isFirstBuild = false;

Expand All @@ -23,10 38,10 @@ WebpackNotifierPlugin.prototype.compileMessage = function(stats) {

var error;
if (stats.hasErrors()) {
error = stats.compilation.errors[0];
error = findFirstDFS(stats.compilation, 'errors');

} else if (stats.hasWarnings() && !this.options.excludeWarnings) {
error = stats.compilation.warnings[0];
error = findFirstDFS(stats.compilation, 'warnings');

} else if (!this.lastBuildSucceeded || this.options.alwaysNotify) {
this.lastBuildSucceeded = true;
Expand Down

0 comments on commit 4131c51

Please sign in to comment.