| 
									
										
										
										
											2014-06-03 14:45:26 +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-02-21 18:35:09 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { CachedSource, ConcatSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | const { UsageState } = require("./ExportsInfo"); | 
					
						
							| 
									
										
										
										
											2017-08-02 21:39:43 +08:00
										 |  |  | const Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | const CssModulesPlugin = require("./css/CssModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2024-08-12 21:53:44 +08:00
										 |  |  | const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./ExportsInfo")} ExportsInfo */ | 
					
						
							|  |  |  | /** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */ | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | /** @typedef {import("./Module").BuildMeta} BuildMeta */ | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | /** @typedef {import("./ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @param {Iterable<T>} iterable iterable | 
					
						
							|  |  |  |  * @returns {string} joined with comma | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const joinIterableWithComma = (iterable) => { | 
					
						
							| 
									
										
										
										
											2019-01-05 21:23:59 +08:00
										 |  |  | 	// This is more performant than Array.from().join(", ")
 | 
					
						
							|  |  |  | 	// as it doesn't create an array
 | 
					
						
							|  |  |  | 	let str = ""; | 
					
						
							|  |  |  | 	let first = true; | 
					
						
							|  |  |  | 	for (const item of iterable) { | 
					
						
							|  |  |  | 		if (first) { | 
					
						
							|  |  |  | 			first = false; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			str += ", "; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-05-21 15:44:06 +08:00
										 |  |  | 		str += item; | 
					
						
							| 
									
										
										
										
											2019-01-05 21:23:59 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return str; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {ConcatSource} source output | 
					
						
							|  |  |  |  * @param {string} indent spacing | 
					
						
							|  |  |  |  * @param {ExportsInfo} exportsInfo data | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  |  * @param {ModuleGraph} moduleGraph moduleGraph | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  |  * @param {RequestShortener} requestShortener requestShortener | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  |  * @param {Set<ExportInfo>} alreadyPrinted deduplication set | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | const printExportsInfoToSource = ( | 
					
						
							|  |  |  | 	source, | 
					
						
							|  |  |  | 	indent, | 
					
						
							|  |  |  | 	exportsInfo, | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 	moduleGraph, | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 	requestShortener, | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 	alreadyPrinted = new Set() | 
					
						
							|  |  |  | ) => { | 
					
						
							|  |  |  | 	const otherExportsInfo = exportsInfo.otherExportsInfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	let alreadyPrintedExports = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// determine exports to print
 | 
					
						
							|  |  |  | 	const printedExports = []; | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 	for (const exportInfo of exportsInfo.orderedExports) { | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 		if (!alreadyPrinted.has(exportInfo)) { | 
					
						
							|  |  |  | 			alreadyPrinted.add(exportInfo); | 
					
						
							|  |  |  | 			printedExports.push(exportInfo); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			alreadyPrintedExports++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	let showOtherExports = false; | 
					
						
							|  |  |  | 	if (!alreadyPrinted.has(otherExportsInfo)) { | 
					
						
							|  |  |  | 		alreadyPrinted.add(otherExportsInfo); | 
					
						
							|  |  |  | 		showOtherExports = true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		alreadyPrintedExports++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// print the exports
 | 
					
						
							|  |  |  | 	for (const exportInfo of printedExports) { | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 		const target = exportInfo.getTarget(moduleGraph); | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 		source.add( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			`${Template.toComment( | 
					
						
							| 
									
										
										
										
											2019-12-06 14:10:25 +08:00
										 |  |  | 				`${indent}export ${JSON.stringify(exportInfo.name).slice( | 
					
						
							|  |  |  | 					1, | 
					
						
							|  |  |  | 					-1 | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 				)} [${exportInfo.getProvidedInfo()}] [${exportInfo.getUsedInfo()}] [${exportInfo.getRenameInfo()}]${ | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 					target | 
					
						
							|  |  |  | 						? ` -> ${target.module.readableIdentifier(requestShortener)}${ | 
					
						
							|  |  |  | 								target.export | 
					
						
							|  |  |  | 									? ` .${target.export | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 											.map((e) => JSON.stringify(e).slice(1, -1)) | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 											.join(".")}`
 | 
					
						
							|  |  |  | 									: "" | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 							}`
 | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 						: "" | 
					
						
							|  |  |  | 				}`
 | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			)}\n`
 | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		if (exportInfo.exportsInfo) { | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 			printExportsInfoToSource( | 
					
						
							|  |  |  | 				source, | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 				`${indent}  `, | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 				exportInfo.exportsInfo, | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 				moduleGraph, | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 				requestShortener, | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 				alreadyPrinted | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-05 04:05:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 	if (alreadyPrintedExports) { | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 		source.add( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			`${Template.toComment( | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 				`${indent}... (${alreadyPrintedExports} already listed exports)` | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			)}\n`
 | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (showOtherExports) { | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 		const target = otherExportsInfo.getTarget(moduleGraph); | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 		if ( | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 			target || | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 			otherExportsInfo.provided !== false || | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 			otherExportsInfo.getUsed(undefined) !== UsageState.Unused | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 		) { | 
					
						
							|  |  |  | 			const title = | 
					
						
							|  |  |  | 				printedExports.length > 0 || alreadyPrintedExports > 0 | 
					
						
							|  |  |  | 					? "other exports" | 
					
						
							|  |  |  | 					: "exports"; | 
					
						
							|  |  |  | 			source.add( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 				`${Template.toComment( | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 					`${indent}${title} [${otherExportsInfo.getProvidedInfo()}] [${otherExportsInfo.getUsedInfo()}]${ | 
					
						
							|  |  |  | 						target | 
					
						
							|  |  |  | 							? ` -> ${target.module.readableIdentifier(requestShortener)}` | 
					
						
							|  |  |  | 							: "" | 
					
						
							|  |  |  | 					}`
 | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 				)}\n`
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:15:20 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | /** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource | undefined, full: WeakMap<Source, CachedSource> }>>} */ | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | const caches = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | const PLUGIN_NAME = "ModuleInfoHeaderPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | class ModuleInfoHeaderPlugin { | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {boolean=} verbose add more information like exports, runtime requirements and bailouts | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(verbose = true) { | 
					
						
							|  |  |  | 		this._verbose = verbose; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler | 
					
						
							| 
									
										
										
										
											2018-08-07 01:39:43 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 		const { _verbose: verbose } = this; | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { | 
					
						
							| 
									
										
										
										
											2024-08-12 21:53:44 +08:00
										 |  |  | 			const javascriptHooks = | 
					
						
							|  |  |  | 				JavascriptModulesPlugin.getCompilationHooks(compilation); | 
					
						
							|  |  |  | 			javascriptHooks.renderModulePackage.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 				( | 
					
						
							|  |  |  | 					moduleSource, | 
					
						
							|  |  |  | 					module, | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 					{ chunk, chunkGraph, moduleGraph, runtimeTemplate } | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 				) => { | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 					const { requestShortener } = runtimeTemplate; | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 					let cacheEntry; | 
					
						
							|  |  |  | 					let cache = caches.get(requestShortener); | 
					
						
							|  |  |  | 					if (cache === undefined) { | 
					
						
							|  |  |  | 						caches.set(requestShortener, (cache = new WeakMap())); | 
					
						
							|  |  |  | 						cache.set( | 
					
						
							|  |  |  | 							module, | 
					
						
							|  |  |  | 							(cacheEntry = { header: undefined, full: new WeakMap() }) | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 					} else { | 
					
						
							|  |  |  | 						cacheEntry = cache.get(module); | 
					
						
							|  |  |  | 						if (cacheEntry === undefined) { | 
					
						
							|  |  |  | 							cache.set( | 
					
						
							|  |  |  | 								module, | 
					
						
							|  |  |  | 								(cacheEntry = { header: undefined, full: new WeakMap() }) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} else if (!verbose) { | 
					
						
							|  |  |  | 							const cachedSource = cacheEntry.full.get(moduleSource); | 
					
						
							|  |  |  | 							if (cachedSource !== undefined) return cachedSource; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-07-08 16:58:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 					const source = new ConcatSource(); | 
					
						
							|  |  |  | 					let header = cacheEntry.header; | 
					
						
							|  |  |  | 					if (header === undefined) { | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | 						header = this.generateHeader(module, requestShortener); | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						cacheEntry.header = header; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					source.add(header); | 
					
						
							|  |  |  | 					if (verbose) { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 						const exportsType = /** @type {BuildMeta} */ (module.buildMeta) | 
					
						
							|  |  |  | 							.exportsType; | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						source.add( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 							`${Template.toComment( | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 								exportsType | 
					
						
							|  |  |  | 									? `${exportsType} exports` | 
					
						
							|  |  |  | 									: "unknown exports (runtime-defined)" | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 							)}\n`
 | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						); | 
					
						
							|  |  |  | 						if (exportsType) { | 
					
						
							|  |  |  | 							const exportsInfo = moduleGraph.getExportsInfo(module); | 
					
						
							|  |  |  | 							printExportsInfoToSource( | 
					
						
							|  |  |  | 								source, | 
					
						
							|  |  |  | 								"", | 
					
						
							|  |  |  | 								exportsInfo, | 
					
						
							|  |  |  | 								moduleGraph, | 
					
						
							|  |  |  | 								requestShortener | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						source.add( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 							`${Template.toComment( | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 								`runtime requirements: ${joinIterableWithComma( | 
					
						
							|  |  |  | 									chunkGraph.getModuleRuntimeRequirements(module, chunk.runtime) | 
					
						
							|  |  |  | 								)}`
 | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 							)}\n`
 | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 						const optimizationBailout = | 
					
						
							|  |  |  | 							moduleGraph.getOptimizationBailout(module); | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						if (optimizationBailout) { | 
					
						
							|  |  |  | 							for (const text of optimizationBailout) { | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 								const code = | 
					
						
							|  |  |  | 									typeof text === "function" ? text(requestShortener) : text; | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 								source.add(`${Template.toComment(`${code}`)}\n`); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-12-04 18:12:20 +08:00
										 |  |  | 						source.add(moduleSource); | 
					
						
							|  |  |  | 						return source; | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 					source.add(moduleSource); | 
					
						
							|  |  |  | 					const cachedSource = new CachedSource(source); | 
					
						
							|  |  |  | 					cacheEntry.full.set(moduleSource, cachedSource); | 
					
						
							|  |  |  | 					return cachedSource; | 
					
						
							| 
									
										
										
										
											2017-05-28 21:25:07 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			javascriptHooks.chunkHash.tap(PLUGIN_NAME, (_chunk, hash) => { | 
					
						
							|  |  |  | 				hash.update(PLUGIN_NAME); | 
					
						
							|  |  |  | 				hash.update("1"); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | 			const cssHooks = CssModulesPlugin.getCompilationHooks(compilation); | 
					
						
							|  |  |  | 			cssHooks.renderModulePackage.tap( | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 				PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | 				(moduleSource, module, { runtimeTemplate }) => { | 
					
						
							|  |  |  | 					const { requestShortener } = runtimeTemplate; | 
					
						
							|  |  |  | 					let cacheEntry; | 
					
						
							|  |  |  | 					let cache = caches.get(requestShortener); | 
					
						
							|  |  |  | 					if (cache === undefined) { | 
					
						
							|  |  |  | 						caches.set(requestShortener, (cache = new WeakMap())); | 
					
						
							|  |  |  | 						cache.set( | 
					
						
							|  |  |  | 							module, | 
					
						
							|  |  |  | 							(cacheEntry = { header: undefined, full: new WeakMap() }) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						cacheEntry = cache.get(module); | 
					
						
							|  |  |  | 						if (cacheEntry === undefined) { | 
					
						
							|  |  |  | 							cache.set( | 
					
						
							|  |  |  | 								module, | 
					
						
							|  |  |  | 								(cacheEntry = { header: undefined, full: new WeakMap() }) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} else if (!verbose) { | 
					
						
							|  |  |  | 							const cachedSource = cacheEntry.full.get(moduleSource); | 
					
						
							|  |  |  | 							if (cachedSource !== undefined) return cachedSource; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					const source = new ConcatSource(); | 
					
						
							|  |  |  | 					let header = cacheEntry.header; | 
					
						
							|  |  |  | 					if (header === undefined) { | 
					
						
							|  |  |  | 						header = this.generateHeader(module, requestShortener); | 
					
						
							|  |  |  | 						cacheEntry.header = header; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					source.add(header); | 
					
						
							|  |  |  | 					source.add(moduleSource); | 
					
						
							|  |  |  | 					const cachedSource = new CachedSource(source); | 
					
						
							|  |  |  | 					cacheEntry.full.set(moduleSource, cachedSource); | 
					
						
							|  |  |  | 					return cachedSource; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2025-04-23 20:03:37 +08:00
										 |  |  | 			cssHooks.chunkHash.tap(PLUGIN_NAME, (_chunk, hash) => { | 
					
						
							|  |  |  | 				hash.update(PLUGIN_NAME); | 
					
						
							| 
									
										
										
										
											2024-08-12 21:53:44 +08:00
										 |  |  | 				hash.update("1"); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-02-21 18:35:09 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener request shortener | 
					
						
							| 
									
										
										
										
											2024-08-12 21:53:44 +08:00
										 |  |  | 	 * @returns {RawSource} the header | 
					
						
							| 
									
										
										
										
											2024-08-12 02:17:52 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	generateHeader(module, requestShortener) { | 
					
						
							|  |  |  | 		const req = module.readableIdentifier(requestShortener); | 
					
						
							|  |  |  | 		const reqStr = req.replace(/\*\//g, "*_/"); | 
					
						
							|  |  |  | 		const reqStrStar = "*".repeat(reqStr.length); | 
					
						
							|  |  |  | 		const headerStr = `/*!****${reqStrStar}****!*\\\n  !*** ${reqStr} ***!\n  \\****${reqStrStar}****/\n`; | 
					
						
							|  |  |  | 		return new RawSource(headerStr); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-21 18:35:09 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 14:54:21 +08:00
										 |  |  | module.exports = ModuleInfoHeaderPlugin; |