UNPKG

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