[6a3a178] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Florent Cailhol @ooflorent
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const WebpackError = require("./WebpackError");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("./Compiler")} Compiler */
|
---|
| 11 |
|
---|
| 12 | class WarnDeprecatedOptionPlugin {
|
---|
| 13 | /**
|
---|
| 14 | * Create an instance of the plugin
|
---|
| 15 | * @param {string} option the target option
|
---|
| 16 | * @param {string | number} value the deprecated option value
|
---|
| 17 | * @param {string} suggestion the suggestion replacement
|
---|
| 18 | */
|
---|
| 19 | constructor(option, value, suggestion) {
|
---|
| 20 | this.option = option;
|
---|
| 21 | this.value = value;
|
---|
| 22 | this.suggestion = suggestion;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Apply the plugin
|
---|
| 27 | * @param {Compiler} compiler the compiler instance
|
---|
| 28 | * @returns {void}
|
---|
| 29 | */
|
---|
| 30 | apply(compiler) {
|
---|
| 31 | compiler.hooks.thisCompilation.tap(
|
---|
| 32 | "WarnDeprecatedOptionPlugin",
|
---|
| 33 | compilation => {
|
---|
| 34 | compilation.warnings.push(
|
---|
| 35 | new DeprecatedOptionWarning(this.option, this.value, this.suggestion)
|
---|
| 36 | );
|
---|
| 37 | }
|
---|
| 38 | );
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | class DeprecatedOptionWarning extends WebpackError {
|
---|
| 43 | constructor(option, value, suggestion) {
|
---|
| 44 | super();
|
---|
| 45 |
|
---|
| 46 | this.name = "DeprecatedOptionWarning";
|
---|
| 47 | this.message =
|
---|
| 48 | "configuration\n" +
|
---|
| 49 | `The value '${value}' for option '${option}' is deprecated. ` +
|
---|
| 50 | `Use '${suggestion}' instead.`;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | module.exports = WarnDeprecatedOptionPlugin;
|
---|