WarnDeprecatedOptionPlugin.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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("./errors/WebpackError");
  7. /** @import Compiler from "./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. /** @type {string} */
  18. this.option = option;
  19. /** @type {string | number} */
  20. this.value = value;
  21. /** @type {string} */
  22. this.suggestion = suggestion;
  23. }
  24. /**
  25. * Applies the plugin by registering its hooks on the compiler.
  26. * @param {Compiler} compiler the compiler instance
  27. * @returns {void}
  28. */
  29. apply(compiler) {
  30. compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
  31. compilation.warnings.push(
  32. new DeprecatedOptionWarning(this.option, this.value, this.suggestion)
  33. );
  34. });
  35. }
  36. }
  37. class DeprecatedOptionWarning extends WebpackError {
  38. /**
  39. * Create an instance deprecated option warning
  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. /** @type {string} */
  47. this.name = "DeprecatedOptionWarning";
  48. /** @type {string} */
  49. this.message =
  50. "configuration\n" +
  51. `The value '${value}' for option '${option}' is deprecated. ` +
  52. `Use '${suggestion}' instead.`;
  53. }
  54. }
  55. module.exports = WarnDeprecatedOptionPlugin;