WarnDeprecatedOptionPlugin.js 1.2 KB

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