|
7 | 7 |
|
8 | 8 | /** @import Compiler from "../Compiler" */ |
9 | 9 | /** @import Module from "../module/Module" */ |
10 | | -/** @import ModuleGraph from "../graph/ModuleGraph" */ |
11 | 10 | /** @import NormalModule from "../module/NormalModule" */ |
12 | 11 |
|
13 | | -const WebpackError = require("../errors/WebpackError"); |
14 | | - |
15 | | -/** |
16 | | - * Sorts the conflicting modules by identifier to keep warning output stable. |
17 | | - * @param {Module[]} modules the modules to be sorted |
18 | | - * @returns {Module[]} sorted version of original modules |
19 | | - */ |
20 | | -const sortModules = (modules) => |
21 | | - modules.sort((a, b) => { |
22 | | - const aIdent = a.identifier(); |
23 | | - const bIdent = b.identifier(); |
24 | | - /* istanbul ignore next */ |
25 | | - if (aIdent < bIdent) return -1; |
26 | | - /* istanbul ignore next */ |
27 | | - if (aIdent > bIdent) return 1; |
28 | | - /* istanbul ignore next */ |
29 | | - return 0; |
30 | | - }); |
31 | | - |
32 | | -/** |
33 | | - * Formats the conflicting modules and one representative incoming reason for |
34 | | - * each module into the warning body. |
35 | | - * @param {Module[]} modules each module from throw |
36 | | - * @param {ModuleGraph} moduleGraph the module graph |
37 | | - * @returns {string} each message from provided modules |
38 | | - */ |
39 | | -const createModulesListMessage = (modules, moduleGraph) => |
40 | | - modules |
41 | | - .map((m) => { |
42 | | - let message = `* ${m.identifier()}`; |
43 | | - const validReasons = [ |
44 | | - ...moduleGraph.getIncomingConnectionsByOriginModule(m).keys() |
45 | | - ].filter(Boolean); |
46 | | - |
47 | | - if (validReasons.length > 0) { |
48 | | - message += `\n Used by ${validReasons.length} module(s), i. e.`; |
49 | | - message += `\n ${ |
50 | | - /** @type {Module[]} */ (validReasons)[0].identifier() |
51 | | - }`; |
52 | | - } |
53 | | - return message; |
54 | | - }) |
55 | | - .join("\n"); |
56 | | - |
57 | | -/** |
58 | | - * Warning emitted when webpack finds modules whose identifiers differ only by |
59 | | - * letter casing, which can behave inconsistently across filesystems. |
60 | | - */ |
61 | | -class CaseSensitiveModulesWarning extends WebpackError { |
62 | | - /** |
63 | | - * Builds a warning message that lists the case-conflicting modules and |
64 | | - * representative importers that caused them to be included. |
65 | | - * @param {Iterable<Module>} modules modules that were detected |
66 | | - * @param {ModuleGraph} moduleGraph the module graph |
67 | | - */ |
68 | | - constructor(modules, moduleGraph) { |
69 | | - const sortedModules = sortModules([...modules]); |
70 | | - const modulesList = createModulesListMessage(sortedModules, moduleGraph); |
71 | | - super(`There are multiple modules with names that only differ in casing. |
72 | | -This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. |
73 | | -Use equal casing. Compare these module identifiers: |
74 | | -${modulesList}`); |
75 | | - |
76 | | - /** @type {string} */ |
77 | | - this.name = "CaseSensitiveModulesWarning"; |
78 | | - /** @type {Module} */ |
79 | | - this.module = sortedModules[0]; |
80 | | - } |
81 | | -} |
| 12 | +const CaseSensitiveModulesWarning = require("../errors/CaseSensitiveModulesWarning"); |
82 | 13 |
|
83 | 14 | const PLUGIN_NAME = "WarnCaseSensitiveModulesPlugin"; |
84 | 15 |
|
|
0 commit comments