| 
									
										
										
										
											2014-03-31 17:33:17 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-03-31 17:33:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning"); | 
					
						
							| 
									
										
										
										
											2014-03-31 17:33:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-03 04:05:46 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2021-04-09 21:41:27 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2023-04-13 09:01:40 +08:00
										 |  |  | /** @typedef {import("./NormalModule")} NormalModule */ | 
					
						
							| 
									
										
										
										
											2018-11-03 04:05:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "WarnCaseSensitiveModulesPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | class WarnCaseSensitiveModulesPlugin { | 
					
						
							| 
									
										
										
										
											2018-11-03 04:05:46 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | 
					
						
							|  |  |  | 			compilation.hooks.seal.tap(PLUGIN_NAME, () => { | 
					
						
							|  |  |  | 				/** @type {Map<string, Map<string, Module>>} */ | 
					
						
							|  |  |  | 				const moduleWithoutCase = new Map(); | 
					
						
							|  |  |  | 				for (const module of compilation.modules) { | 
					
						
							|  |  |  | 					const identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2023-04-13 08:51:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					// Ignore `data:` URLs, because it's not a real path
 | 
					
						
							|  |  |  | 					if ( | 
					
						
							|  |  |  | 						/** @type {NormalModule} */ | 
					
						
							|  |  |  | 						(module).resourceResolveData !== undefined && | 
					
						
							|  |  |  | 						/** @type {NormalModule} */ | 
					
						
							|  |  |  | 						(module).resourceResolveData.encodedContent !== undefined | 
					
						
							|  |  |  | 					) { | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2023-04-13 08:51:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					const lowerIdentifier = identifier.toLowerCase(); | 
					
						
							|  |  |  | 					let map = moduleWithoutCase.get(lowerIdentifier); | 
					
						
							|  |  |  | 					if (map === undefined) { | 
					
						
							|  |  |  | 						map = new Map(); | 
					
						
							|  |  |  | 						moduleWithoutCase.set(lowerIdentifier, map); | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 					map.set(identifier, module); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for (const pair of moduleWithoutCase) { | 
					
						
							|  |  |  | 					const map = pair[1]; | 
					
						
							|  |  |  | 					if (map.size > 1) { | 
					
						
							|  |  |  | 						compilation.warnings.push( | 
					
						
							|  |  |  | 							new CaseSensitiveModulesWarning( | 
					
						
							|  |  |  | 								map.values(), | 
					
						
							|  |  |  | 								compilation.moduleGraph | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-04 15:32:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = WarnCaseSensitiveModulesPlugin; |