'use strict';

var chalk = require('chalk');
var path = require('path');

function WebpackKarmaDieHardPlugin(options) {
  if (typeof(options) === "undefined") {
    options = {};
  }
  chalk.enabled = options.colors !== false
}

WebpackKarmaDieHardPlugin.prototype.apply = function(compiler) {
  compiler.plugin('done', function(stats) {
    // Need to report warnings and errors manually, since these will not bubble
    // up to the user.
    stats.compilation.warnings.forEach(function (warning) {
      console.warn(chalk.yellow("WARNING: ./"
          + path.relative("", warning.module.resource)));
      console.warn(chalk.yellow(warning.message || warning));
    });
    stats.compilation.errors.forEach(function (error) {
      console.error(chalk.red("ERROR: ./"
          + path.relative("", error.module.resource)));
      console.error(chalk.red(error.message || error));
    });
    if (stats.compilation.errors.length > 0) {
      // karma-webpack will hang indefinitely if no assets are produced, so just
      // blow up noisily.
      process.exit(1);
    }
  });
};

module.exports = WebpackKarmaDieHardPlugin;

'use strict';

var chalk = require('chalk');
var path = require('path');

function WebpackKarmaDieHardPlugin(options) {
  if (typeof(options) === "undefined") {
    options = {};
  }
  chalk.enabled = options.colors !== false
}

WebpackKarmaDieHardPlugin.prototype.apply = function(compiler) {
  compiler.plugin('done', function(stats) {
    // Need to report warnings and errors manually, since these will not bubble
    // up to the user.
    stats.compilation.warnings.forEach(function (warning) {
      if (warning.module) {
        console.warn(chalk.yellow("WARNING: ./"
            + path.relative("", warning.module.resource)));
      }
      console.warn(chalk.yellow(warning.message || warning));
    });
    stats.compilation.errors.forEach(function (error) {
      if (error.module) {
        console.error(chalk.red("ERROR: ./"
            + path.relative("", error.module.resource)));
      }
      console.error(chalk.red(error.message || error));
    });
    if (stats.compilation.errors.length > 0) {
      // karma-webpack will hang indefinitely if no assets are produced, so just
      // blow up noisily.
      process.exit(1);
    }
  });
};

module.exports = WebpackKarmaDieHardPlugin;

Fix bug reporting some kinds of warnings/errors
Fix bug reporting some kinds of warnings/errors

Some (unknown to me right now) errors and warnings from webpack may lack
the "module" field which provides the filename of the error. Avoid
attempts to access that attribute if it's not present.
