ModuleWarning.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { cleanUp } = require("./ErrorHelpers");
  7. const WebpackError = require("./WebpackError");
  8. const makeSerializable = require("./util/makeSerializable");
  9. class ModuleWarning extends WebpackError {
  10. /**
  11. * @param {Error} warning error thrown
  12. * @param {{from?: string|null}} info additional info
  13. */
  14. constructor(warning, { from = null } = {}) {
  15. let message = "Module Warning";
  16. if (from) {
  17. message += ` (from ${from}):\n`;
  18. } else {
  19. message += ": ";
  20. }
  21. if (warning && typeof warning === "object" && warning.message) {
  22. message += warning.message;
  23. } else if (warning) {
  24. message += String(warning);
  25. }
  26. super(message);
  27. this.name = "ModuleWarning";
  28. this.warning = warning;
  29. this.details =
  30. warning && typeof warning === "object" && warning.stack
  31. ? cleanUp(warning.stack, this.message)
  32. : undefined;
  33. }
  34. serialize(context) {
  35. const { write } = context;
  36. write(this.warning);
  37. super.serialize(context);
  38. }
  39. deserialize(context) {
  40. const { read } = context;
  41. this.warning = read();
  42. super.deserialize(context);
  43. }
  44. }
  45. makeSerializable(ModuleWarning, "webpack/lib/ModuleWarning");
  46. module.exports = ModuleWarning;