WarnCaseSensitiveModulesPlugin.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
  7. /** @typedef {import("./Compiler")} Compiler */
  8. /** @typedef {import("./Module")} Module */
  9. class WarnCaseSensitiveModulesPlugin {
  10. /**
  11. * Apply the plugin
  12. * @param {Compiler} compiler the compiler instance
  13. * @returns {void}
  14. */
  15. apply(compiler) {
  16. compiler.hooks.compilation.tap(
  17. "WarnCaseSensitiveModulesPlugin",
  18. compilation => {
  19. compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
  20. /** @type {Map<string, Map<string, Module>>} */
  21. const moduleWithoutCase = new Map();
  22. for (const module of compilation.modules) {
  23. const identifier = module.identifier();
  24. const lowerIdentifier = identifier.toLowerCase();
  25. let map = moduleWithoutCase.get(lowerIdentifier);
  26. if (map === undefined) {
  27. map = new Map();
  28. moduleWithoutCase.set(lowerIdentifier, map);
  29. }
  30. map.set(identifier, module);
  31. }
  32. for (const pair of moduleWithoutCase) {
  33. const map = pair[1];
  34. if (map.size > 1) {
  35. compilation.warnings.push(
  36. new CaseSensitiveModulesWarning(
  37. map.values(),
  38. compilation.moduleGraph
  39. )
  40. );
  41. }
  42. }
  43. });
  44. }
  45. );
  46. }
  47. }
  48. module.exports = WarnCaseSensitiveModulesPlugin;