webpack/lib/ModuleWarning.js

36 lines
893 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 } = {}) {
super();
this.name = "ModuleWarning";
this.module = module;
this.message = "Module Warning";
2018-03-02 17:56:34 +08:00
if (from) {
this.message += ` (from ${from})`;
}
2018-03-02 17:56:34 +08:00
if (warning && typeof warning === "object" && warning.message) {
this.message += `:\n${warning.message}`;
2018-03-02 17:56:34 +08:00
} else if (warning) {
this.message += `:\n${warning}`;
}
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;