UNPKG

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