WarnCaseSensitiveModulesPlugin.js 1016 B

12345678910111213141516171819202122232425262728293031323334353637
  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. class WarnCaseSensitiveModulesPlugin {
  8. apply(compiler) {
  9. compiler.hooks.compilation.tap(
  10. "WarnCaseSensitiveModulesPlugin",
  11. compilation => {
  12. compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
  13. const moduleWithoutCase = new Map();
  14. for (const module of compilation.modules) {
  15. const identifier = module.identifier().toLowerCase();
  16. const array = moduleWithoutCase.get(identifier);
  17. if (array) {
  18. array.push(module);
  19. } else {
  20. moduleWithoutCase.set(identifier, [module]);
  21. }
  22. }
  23. for (const pair of moduleWithoutCase) {
  24. const array = pair[1];
  25. if (array.length > 1) {
  26. compilation.warnings.push(new CaseSensitiveModulesWarning(array));
  27. }
  28. }
  29. });
  30. }
  31. );
  32. }
  33. }
  34. module.exports = WarnCaseSensitiveModulesPlugin;