WarnDeprecatedOptionPlugin.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. const PLUGIN_NAME = "WarnDeprecatedOptionPlugin";
  9. class WarnDeprecatedOptionPlugin {
  10. /**
  11. * Create an instance of the plugin
  12. * @param {string} option the target option
  13. * @param {string | number} value the deprecated option value
  14. * @param {string} suggestion the suggestion replacement
  15. */
  16. constructor(option, value, suggestion) {
  17. this.option = option;
  18. this.value = value;
  19. this.suggestion = suggestion;
  20. }
  21. /**
  22. * Apply the plugin
  23. * @param {Compiler} compiler the compiler instance
  24. * @returns {void}
  25. */
  26. apply(compiler) {
  27. compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
  28. compilation.warnings.push(
  29. new DeprecatedOptionWarning(this.option, this.value, this.suggestion)
  30. );
  31. });
  32. }
  33. }
  34. class DeprecatedOptionWarning extends WebpackError {
  35. /**
  36. * Create an instance deprecated option warning
  37. * @param {string} option the target option
  38. * @param {string | number} value the deprecated option value
  39. * @param {string} suggestion the suggestion replacement
  40. */
  41. constructor(option, value, suggestion) {
  42. super();
  43. this.name = "DeprecatedOptionWarning";
  44. this.message =
  45. "configuration\n" +
  46. `The value '${value}' for option '${option}' is deprecated. ` +
  47. `Use '${suggestion}' instead.`;
  48. }
  49. }
  50. module.exports = WarnDeprecatedOptionPlugin;