ModuleWarning.js 901 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const WebpackError = require("./WebpackError");
  7. const { cleanUp } = require("./ErrorHelpers");
  8. class ModuleWarning extends WebpackError {
  9. constructor(module, warning, { from = null } = {}) {
  10. let message = "Module Warning";
  11. if (from) {
  12. message += ` (from ${from}):\n`;
  13. } else {
  14. message += ": ";
  15. }
  16. if (warning && typeof warning === "object" && warning.message) {
  17. message += warning.message;
  18. } else if (warning) {
  19. message += warning;
  20. }
  21. super(message);
  22. this.name = "ModuleWarning";
  23. this.module = module;
  24. this.warning = warning;
  25. this.details =
  26. warning && typeof warning === "object" && warning.stack
  27. ? cleanUp(warning.stack, this.message)
  28. : undefined;
  29. Error.captureStackTrace(this, this.constructor);
  30. }
  31. }
  32. module.exports = ModuleWarning;