WarnDeprecatedOptionPlugin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /**
  38. * Create an instance deprecated option warning
  39. *
  40. * @param {string} option the target option
  41. * @param {string | number} value the deprecated option value
  42. * @param {string} suggestion the suggestion replacement
  43. */
  44. constructor(option, value, suggestion) {
  45. super();
  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. module.exports = WarnDeprecatedOptionPlugin;