1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
|
---|
9 |
|
---|
10 | /** @typedef {import("./Compiler")} Compiler */
|
---|
11 | /** @typedef {import("./Module")} Module */
|
---|
12 |
|
---|
13 | class WarnCaseSensitiveModulesPlugin {
|
---|
14 | /**
|
---|
15 | * Apply the plugin
|
---|
16 | * @param {Compiler} compiler the compiler instance
|
---|
17 | * @returns {void}
|
---|
18 | */
|
---|
19 | apply(compiler) {
|
---|
20 | compiler.hooks.compilation.tap(
|
---|
21 | "WarnCaseSensitiveModulesPlugin",
|
---|
22 | compilation => {
|
---|
23 | compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
|
---|
24 | /** @type {Map<string, Map<string, Module>>} */
|
---|
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;
|
---|