webpack/lib/ModuleWarning.js

37 lines
901 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const WebpackError = require("./WebpackError");
const { cleanUp } = require("./ErrorHelpers");
class ModuleWarning extends WebpackError {
2018-04-29 15:44:38 +08:00
constructor(module, warning, { from = null } = {}) {
let message = "Module Warning";
2018-03-02 17:56:34 +08:00
if (from) {
2018-06-05 16:43:10 +08:00
message += ` (from ${from}):\n`;
} else {
message += ": ";
}
2018-03-02 17:56:34 +08:00
if (warning && typeof warning === "object" && warning.message) {
2018-06-05 16:43:10 +08:00
message += warning.message;
2018-03-02 17:56:34 +08:00
} else if (warning) {
2018-06-05 16:43:10 +08:00
message += warning;
}
super(message);
this.name = "ModuleWarning";
this.module = module;
this.warning = warning;
2018-02-25 09:00:20 +08:00
this.details =
warning && typeof warning === "object" && warning.stack
? cleanUp(warning.stack, this.message)
: undefined;
Error.captureStackTrace(this, this.constructor);
}
}
module.exports = ModuleWarning;