1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class WarnCaseSensitiveModulesPlugin {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 | apply(compiler) {
|
20 | compiler.hooks.compilation.tap(
|
21 | "WarnCaseSensitiveModulesPlugin",
|
22 | compilation => {
|
23 | compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
|
24 |
|
25 | const moduleWithoutCase = new Map();
|
26 | for (const module of compilation.modules) {
|
27 | const identifier = module.identifier();
|
28 | const lowerIdentifier = identifier.toLowerCase();
|
29 | let map = moduleWithoutCase.get(lowerIdentifier);
|
30 | if (map === undefined) {
|
31 | map = new Map();
|
32 | moduleWithoutCase.set(lowerIdentifier, map);
|
33 | }
|
34 | map.set(identifier, module);
|
35 | }
|
36 | for (const pair of moduleWithoutCase) {
|
37 | const map = pair[1];
|
38 | if (map.size > 1) {
|
39 | compilation.warnings.push(
|
40 | new CaseSensitiveModulesWarning(
|
41 | map.values(),
|
42 | compilation.moduleGraph
|
43 | )
|
44 | );
|
45 | }
|
46 | }
|
47 | });
|
48 | }
|
49 | );
|
50 | }
|
51 | }
|
52 |
|
53 | module.exports = WarnCaseSensitiveModulesPlugin;
|