| 
									
										
										
										
											2013-06-19 19:49:57 +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-09 02:11:26 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-30 00:14:40 +08:00
										 |  |  | const { SyncBailHook } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2019-12-16 20:21:39 +08:00
										 |  |  | const ChunkGraph = require("./ChunkGraph"); | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | const Compilation = require("./Compilation"); | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | const HotUpdateChunk = require("./HotUpdateChunk"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_AUTO, | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_DYNAMIC, | 
					
						
							|  |  |  | 	JAVASCRIPT_MODULE_TYPE_ESM, | 
					
						
							|  |  |  | 	WEBPACK_MODULE_TYPE_RUNTIME | 
					
						
							|  |  |  | } = require("./ModuleTypeConstants"); | 
					
						
							| 
									
										
										
										
											2018-11-12 21:13:55 +08:00
										 |  |  | const NormalModule = require("./NormalModule"); | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | const ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | const ImportMetaHotAcceptDependency = require("./dependencies/ImportMetaHotAcceptDependency"); | 
					
						
							|  |  |  | const ImportMetaHotDeclineDependency = require("./dependencies/ImportMetaHotDeclineDependency"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency"); | 
					
						
							|  |  |  | const ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency"); | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | const HotModuleReplacementRuntimeModule = require("./hmr/HotModuleReplacementRuntimeModule"); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +08:00
										 |  |  | const JavascriptParser = require("./javascript/JavascriptParser"); | 
					
						
							| 
									
										
										
										
											2019-10-22 15:27:52 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2020-09-11 18:37:17 +08:00
										 |  |  | 	evaluateToIdentifier | 
					
						
							| 
									
										
										
										
											2019-10-22 15:27:52 +08:00
										 |  |  | } = require("./javascript/JavascriptParserHelpers"); | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | const { find, isSubset } = require("./util/SetHelpers"); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | const TupleSet = require("./util/TupleSet"); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | const { compareModulesById } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	forEachRuntime, | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 	getRuntimeKey, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	intersectRuntime, | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 	keyToRuntime, | 
					
						
							|  |  |  | 	mergeRuntimeOwned, | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	subtractRuntime | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | } = require("./util/runtime"); | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** @typedef {import("estree").CallExpression} CallExpression */ | 
					
						
							|  |  |  | /** @typedef {import("estree").Expression} Expression */ | 
					
						
							| 
									
										
										
										
											2024-10-24 22:09:39 +08:00
										 |  |  | /** @typedef {import("estree").SpreadElement} SpreadElement */ | 
					
						
							| 
									
										
										
										
											2018-11-12 21:26:06 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** @typedef {import("./Chunk").ChunkId} ChunkId */ | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */ | 
					
						
							| 
									
										
										
										
											2020-07-17 20:57:11 +08:00
										 |  |  | /** @typedef {import("./Compilation").AssetInfo} AssetInfo */ | 
					
						
							| 
									
										
										
										
											2025-03-08 00:02:26 +08:00
										 |  |  | /** @typedef {import("./Compilation").Records} Records */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** @typedef {import("./Module").BuildInfo} BuildInfo */ | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | /** @typedef {import("./RuntimeModule")} RuntimeModule */ | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | /** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */ | 
					
						
							|  |  |  | /** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */ | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 21:26:06 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2024-06-11 21:09:50 +08:00
										 |  |  |  * @typedef {object} HMRJavascriptParserHooks | 
					
						
							| 
									
										
										
										
											2024-10-25 02:13:59 +08:00
										 |  |  |  * @property {SyncBailHook<[Expression | SpreadElement, string[]], void>} hotAcceptCallback | 
					
						
							|  |  |  |  * @property {SyncBailHook<[CallExpression, string[]], void>} hotAcceptWithoutCallback | 
					
						
							| 
									
										
										
										
											2018-11-12 21:26:06 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {number} HotIndex */ | 
					
						
							|  |  |  | /** @typedef {Record<string, string>} FullHashChunkModuleHashes */ | 
					
						
							|  |  |  | /** @typedef {Record<string, string>} ChunkModuleHashes */ | 
					
						
							|  |  |  | /** @typedef {Record<ChunkId, string>} ChunkHashes */ | 
					
						
							|  |  |  | /** @typedef {Record<ChunkId, string>} ChunkRuntime */ | 
					
						
							|  |  |  | /** @typedef {Record<ChunkId, ModuleId[]>} ChunkModuleIds */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | /** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */ | 
					
						
							|  |  |  | /** @typedef {Map<string, HotUpdateMainContentByRuntimeItem>} HotUpdateMainContentByRuntime */ | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 21:26:06 +08:00
										 |  |  | /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */ | 
					
						
							| 
									
										
										
										
											2018-07-06 18:51:14 +08:00
										 |  |  | const parserHooksMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | const PLUGIN_NAME = "HotModuleReplacementPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | class HotModuleReplacementPlugin { | 
					
						
							| 
									
										
										
										
											2018-11-12 21:26:06 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 	 * @returns {HMRJavascriptParserHooks} the attached hooks | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | 	static getParserHooks(parser) { | 
					
						
							| 
									
										
										
										
											2018-07-09 14:41:59 +08:00
										 |  |  | 		if (!(parser instanceof JavascriptParser)) { | 
					
						
							|  |  |  | 			throw new TypeError( | 
					
						
							|  |  |  | 				"The 'parser' argument must be an instance of JavascriptParser" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-07-06 18:51:14 +08:00
										 |  |  | 		let hooks = parserHooksMap.get(parser); | 
					
						
							|  |  |  | 		if (hooks === undefined) { | 
					
						
							|  |  |  | 			hooks = { | 
					
						
							|  |  |  | 				hotAcceptCallback: new SyncBailHook(["expression", "requests"]), | 
					
						
							|  |  |  | 				hotAcceptWithoutCallback: new SyncBailHook(["expression", "requests"]) | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			parserHooksMap.set(parser, hooks); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return hooks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-18 02:57:32 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		const { _backCompat: backCompat } = compiler; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		if (compiler.options.output.strictModuleErrorHandling === undefined) { | 
					
						
							| 
									
										
										
										
											2021-03-09 18:52:10 +08:00
										 |  |  | 			compiler.options.output.strictModuleErrorHandling = true; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 		const runtimeRequirements = [RuntimeGlobals.module]; | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 		 * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency | 
					
						
							|  |  |  | 		 * @returns {(expr: CallExpression) => boolean | undefined} callback | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 		const createAcceptHandler = (parser, ParamDependency) => { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 			const { hotAcceptCallback, hotAcceptWithoutCallback } = | 
					
						
							|  |  |  | 				HotModuleReplacementPlugin.getParserHooks(parser); | 
					
						
							| 
									
										
										
										
											2018-07-06 18:51:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			return (expr) => { | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				const module = parser.state.module; | 
					
						
							|  |  |  | 				const dep = new ConstDependency( | 
					
						
							|  |  |  | 					`${module.moduleArgument}.hot.accept`, | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					/** @type {Range} */ (expr.callee.range), | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 					runtimeRequirements | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 				dep.loc = /** @type {DependencyLocation} */ (expr.loc); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				module.addPresentationalDependency(dep); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 				/** @type {BuildInfo} */ | 
					
						
							|  |  |  | 				(module.buildInfo).moduleConcatenationBailout = | 
					
						
							|  |  |  | 					"Hot Module Replacement"; | 
					
						
							| 
									
										
										
										
											2024-10-24 22:09:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				if (expr.arguments.length >= 1) { | 
					
						
							| 
									
										
										
										
											2024-10-24 22:09:39 +08:00
										 |  |  | 					const arg = parser.evaluateExpression(expr.arguments[0]); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					/** @type {BasicEvaluatedExpression[]} */ | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					let params = []; | 
					
						
							|  |  |  | 					if (arg.isString()) { | 
					
						
							|  |  |  | 						params = [arg]; | 
					
						
							|  |  |  | 					} else if (arg.isArray()) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 						params = | 
					
						
							|  |  |  | 							/** @type {BasicEvaluatedExpression[]} */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							(arg.items).filter((param) => param.isString()); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					/** @type {string[]} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | 					const requests = []; | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					if (params.length > 0) { | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 						for (const [idx, param] of params.entries()) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 							const request = /** @type {string} */ (param.string); | 
					
						
							|  |  |  | 							const dep = new ParamDependency( | 
					
						
							|  |  |  | 								request, | 
					
						
							|  |  |  | 								/** @type {Range} */ (param.range) | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 							dep.optional = true; | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 							dep.loc = Object.create( | 
					
						
							|  |  |  | 								/** @type {DependencyLocation} */ (expr.loc) | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 							dep.loc.index = idx; | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 							module.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 							requests.push(request); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 						if (expr.arguments.length > 1) { | 
					
						
							|  |  |  | 							hotAcceptCallback.call(expr.arguments[1], requests); | 
					
						
							| 
									
										
										
										
											2021-03-09 18:52:10 +08:00
										 |  |  | 							for (let i = 1; i < expr.arguments.length; i++) { | 
					
						
							|  |  |  | 								parser.walkExpression(expr.arguments[i]); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 							return true; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 						hotAcceptWithoutCallback.call(expr, requests); | 
					
						
							|  |  |  | 						return true; | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				parser.walkExpressions(expr.arguments); | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 		 * @param {typeof ModuleHotDeclineDependency} ParamDependency dependency | 
					
						
							|  |  |  | 		 * @returns {(expr: CallExpression) => boolean | undefined} callback | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const createDeclineHandler = (parser, ParamDependency) => (expr) => { | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 			const module = parser.state.module; | 
					
						
							|  |  |  | 			const dep = new ConstDependency( | 
					
						
							|  |  |  | 				`${module.moduleArgument}.hot.decline`, | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 				/** @type {Range} */ (expr.callee.range), | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				runtimeRequirements | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 			dep.loc = /** @type {DependencyLocation} */ (expr.loc); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 			module.addPresentationalDependency(dep); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 			/** @type {BuildInfo} */ | 
					
						
							|  |  |  | 			(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement"; | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 			if (expr.arguments.length === 1) { | 
					
						
							|  |  |  | 				const arg = parser.evaluateExpression(expr.arguments[0]); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 				/** @type {BasicEvaluatedExpression[]} */ | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				let params = []; | 
					
						
							|  |  |  | 				if (arg.isString()) { | 
					
						
							|  |  |  | 					params = [arg]; | 
					
						
							|  |  |  | 				} else if (arg.isArray()) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					params = | 
					
						
							|  |  |  | 						/** @type {BasicEvaluatedExpression[]} */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						(arg.items).filter((param) => param.isString()); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				for (const [idx, param] of params.entries()) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					const dep = new ParamDependency( | 
					
						
							|  |  |  | 						/** @type {string} */ (param.string), | 
					
						
							|  |  |  | 						/** @type {Range} */ (param.range) | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					dep.optional = true; | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 					dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc)); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					dep.loc.index = idx; | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 					module.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 		 * @returns {(expr: Expression) => boolean | undefined} callback | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const createHMRExpressionHandler = (parser) => (expr) => { | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 			const module = parser.state.module; | 
					
						
							|  |  |  | 			const dep = new ConstDependency( | 
					
						
							|  |  |  | 				`${module.moduleArgument}.hot`, | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 				/** @type {Range} */ (expr.range), | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				runtimeRequirements | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 			dep.loc = /** @type {DependencyLocation} */ (expr.loc); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 			module.addPresentationalDependency(dep); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 			/** @type {BuildInfo} */ | 
					
						
							|  |  |  | 			(module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement"; | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const applyModuleHot = (parser) => { | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 			parser.hooks.evaluateIdentifier.for("module.hot").tap( | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					name: PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 					before: "NodeStuffPlugin" | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				(expr) => | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 					evaluateToIdentifier( | 
					
						
							| 
									
										
										
										
											2019-08-29 21:28:19 +08:00
										 |  |  | 						"module.hot", | 
					
						
							|  |  |  | 						"module", | 
					
						
							|  |  |  | 						() => ["hot"], | 
					
						
							|  |  |  | 						true | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 					)(expr) | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 			parser.hooks.call | 
					
						
							|  |  |  | 				.for("module.hot.accept") | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					createAcceptHandler(parser, ModuleHotAcceptDependency) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 			parser.hooks.call | 
					
						
							|  |  |  | 				.for("module.hot.decline") | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					createDeclineHandler(parser, ModuleHotDeclineDependency) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-07-05 17:25:34 +08:00
										 |  |  | 			parser.hooks.expression | 
					
						
							|  |  |  | 				.for("module.hot") | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 				.tap(PLUGIN_NAME, createHMRExpressionHandler(parser)); | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const applyImportMetaHot = (parser) => { | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 			parser.hooks.evaluateIdentifier | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				.for("import.meta.webpackHot") | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				.tap(PLUGIN_NAME, (expr) => | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 					evaluateToIdentifier( | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 						"import.meta.webpackHot", | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 						"import.meta", | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 						() => ["webpackHot"], | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 						true | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 					)(expr) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 			parser.hooks.call | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				.for("import.meta.webpackHot.accept") | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					createAcceptHandler(parser, ImportMetaHotAcceptDependency) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			parser.hooks.call | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				.for("import.meta.webpackHot.decline") | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 					createDeclineHandler(parser, ImportMetaHotDeclineDependency) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			parser.hooks.expression | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:44 +08:00
										 |  |  | 				.for("import.meta.webpackHot") | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 				.tap(PLUGIN_NAME, createHMRExpressionHandler(parser)); | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 			PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							| 
									
										
										
										
											2019-09-23 17:42:48 +08:00
										 |  |  | 				// This applies the HMR plugin only to the targeted compiler
 | 
					
						
							|  |  |  | 				// It should not affect child compilations
 | 
					
						
							|  |  |  | 				if (compilation.compiler !== compiler) return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				// #region module.hot.* API
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					ModuleHotAcceptDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					ModuleHotAcceptDependency, | 
					
						
							|  |  |  | 					new ModuleHotAcceptDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					ModuleHotDeclineDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					ModuleHotDeclineDependency, | 
					
						
							|  |  |  | 					new ModuleHotDeclineDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				// #endregion
 | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				// #region import.meta.webpackHot.* API
 | 
					
						
							| 
									
										
										
										
											2020-06-22 23:49:57 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					ImportMetaHotAcceptDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					ImportMetaHotAcceptDependency, | 
					
						
							|  |  |  | 					new ImportMetaHotAcceptDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					ImportMetaHotDeclineDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					ImportMetaHotDeclineDependency, | 
					
						
							|  |  |  | 					new ImportMetaHotDeclineDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | 				// #endregion
 | 
					
						
							| 
									
										
										
										
											2017-06-18 02:57:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 				/** @type {HotIndex} */ | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 				let hotIndex = 0; | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 				/** @type {FullHashChunkModuleHashes} */ | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 				const fullHashChunkModuleHashes = {}; | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 				/** @type {ChunkModuleHashes} */ | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 				const chunkModuleHashes = {}; | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 				compilation.hooks.record.tap(PLUGIN_NAME, (compilation, records) => { | 
					
						
							|  |  |  | 					if (records.hash === compilation.hash) return; | 
					
						
							|  |  |  | 					const chunkGraph = compilation.chunkGraph; | 
					
						
							|  |  |  | 					records.hash = compilation.hash; | 
					
						
							|  |  |  | 					records.hotIndex = hotIndex; | 
					
						
							|  |  |  | 					records.fullHashChunkModuleHashes = fullHashChunkModuleHashes; | 
					
						
							|  |  |  | 					records.chunkModuleHashes = chunkModuleHashes; | 
					
						
							|  |  |  | 					records.chunkHashes = {}; | 
					
						
							|  |  |  | 					records.chunkRuntime = {}; | 
					
						
							|  |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 						const chunkId = /** @type {ChunkId} */ (chunk.id); | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 						records.chunkHashes[chunkId] = /** @type {string} */ (chunk.hash); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 						records.chunkRuntime[chunkId] = getRuntimeKey(chunk.runtime); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					records.chunkModuleIds = {}; | 
					
						
							|  |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 						const chunkId = /** @type {ChunkId} */ (chunk.id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						records.chunkModuleIds[chunkId] = Array.from( | 
					
						
							|  |  |  | 							chunkGraph.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								compareModulesById(chunkGraph) | 
					
						
							|  |  |  | 							), | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							(m) => /** @type {ModuleId} */ (chunkGraph.getModuleId(m)) | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 				/** @type {TupleSet<Module, Chunk>} */ | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 				const updatedModules = new TupleSet(); | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 				/** @type {TupleSet<Module, Chunk>} */ | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 				const fullHashModules = new TupleSet(); | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 				/** @type {TupleSet<Module, RuntimeSpec>} */ | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 				const nonCodeGeneratedModules = new TupleSet(); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				compilation.hooks.fullHash.tap(PLUGIN_NAME, (hash) => { | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 					const chunkGraph = compilation.chunkGraph; | 
					
						
							| 
									
										
										
										
											2025-03-08 00:02:26 +08:00
										 |  |  | 					const records = /** @type {Records} */ (compilation.records); | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 						/** | 
					
						
							|  |  |  | 						 * @param {Module} module module | 
					
						
							|  |  |  | 						 * @returns {string} module hash | 
					
						
							|  |  |  | 						 */ | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						const getModuleHash = (module) => { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 							if ( | 
					
						
							|  |  |  | 								compilation.codeGenerationResults.has(module, chunk.runtime) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								return compilation.codeGenerationResults.getHash( | 
					
						
							|  |  |  | 									module, | 
					
						
							|  |  |  | 									chunk.runtime | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 							nonCodeGeneratedModules.add(module, chunk.runtime); | 
					
						
							|  |  |  | 							return chunkGraph.getModuleHash(module, chunk.runtime); | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 						}; | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 						const fullHashModulesInThisChunk = | 
					
						
							|  |  |  | 							chunkGraph.getChunkFullHashModulesSet(chunk); | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 						if (fullHashModulesInThisChunk !== undefined) { | 
					
						
							|  |  |  | 							for (const module of fullHashModulesInThisChunk) { | 
					
						
							|  |  |  | 								fullHashModules.add(module, chunk); | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 						const modules = chunkGraph.getChunkModulesIterable(chunk); | 
					
						
							|  |  |  | 						if (modules !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 							if (records.chunkModuleHashes) { | 
					
						
							|  |  |  | 								if (fullHashModulesInThisChunk !== undefined) { | 
					
						
							|  |  |  | 									for (const module of modules) { | 
					
						
							|  |  |  | 										const key = `${chunk.id}|${module.identifier()}`; | 
					
						
							|  |  |  | 										const hash = getModuleHash(module); | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											fullHashModulesInThisChunk.has( | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 												/** @type {RuntimeModule} */ | 
					
						
							|  |  |  | 												(module) | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 											) | 
					
						
							|  |  |  | 										) { | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												/** @type {FullHashChunkModuleHashes} */ | 
					
						
							|  |  |  | 												(records.fullHashChunkModuleHashes)[key] !== hash | 
					
						
							|  |  |  | 											) { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 												updatedModules.add(module, chunk); | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 											fullHashChunkModuleHashes[key] = hash; | 
					
						
							|  |  |  | 										} else { | 
					
						
							|  |  |  | 											if (records.chunkModuleHashes[key] !== hash) { | 
					
						
							|  |  |  | 												updatedModules.add(module, chunk); | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 											chunkModuleHashes[key] = hash; | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									for (const module of modules) { | 
					
						
							|  |  |  | 										const key = `${chunk.id}|${module.identifier()}`; | 
					
						
							|  |  |  | 										const hash = getModuleHash(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 										if (records.chunkModuleHashes[key] !== hash) { | 
					
						
							|  |  |  | 											updatedModules.add(module, chunk); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										chunkModuleHashes[key] = hash; | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 							} else if (fullHashModulesInThisChunk !== undefined) { | 
					
						
							|  |  |  | 								for (const module of modules) { | 
					
						
							|  |  |  | 									const key = `${chunk.id}|${module.identifier()}`; | 
					
						
							|  |  |  | 									const hash = getModuleHash(module); | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										fullHashModulesInThisChunk.has( | 
					
						
							|  |  |  | 											/** @type {RuntimeModule} */ (module) | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 									) { | 
					
						
							|  |  |  | 										fullHashChunkModuleHashes[key] = hash; | 
					
						
							|  |  |  | 									} else { | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 										chunkModuleHashes[key] = hash; | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 							} else { | 
					
						
							|  |  |  | 								for (const module of modules) { | 
					
						
							|  |  |  | 									const key = `${chunk.id}|${module.identifier()}`; | 
					
						
							|  |  |  | 									const hash = getModuleHash(module); | 
					
						
							|  |  |  | 									chunkModuleHashes[key] = hash; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 					hotIndex = records.hotIndex || 0; | 
					
						
							|  |  |  | 					if (updatedModules.size > 0) hotIndex++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					hash.update(`${hotIndex}`); | 
					
						
							| 
									
										
										
										
											2017-06-18 02:57:32 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 				compilation.hooks.processAssets.tap( | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 						name: PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 						stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL | 
					
						
							|  |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					() => { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 						const chunkGraph = compilation.chunkGraph; | 
					
						
							| 
									
										
										
										
											2025-03-08 00:02:26 +08:00
										 |  |  | 						const records = /** @type {Records} */ (compilation.records); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (records.hash === compilation.hash) return; | 
					
						
							|  |  |  | 						if ( | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 							!records.chunkModuleHashes || | 
					
						
							| 
									
										
										
										
											2021-08-04 05:51:25 +08:00
										 |  |  | 							!records.chunkHashes || | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							!records.chunkModuleIds | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 						) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							return; | 
					
						
							| 
									
										
										
										
											2020-07-08 23:20:14 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 						for (const [module, chunk] of fullHashModules) { | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 							const key = `${chunk.id}|${module.identifier()}`; | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 							const hash = nonCodeGeneratedModules.has(module, chunk.runtime) | 
					
						
							|  |  |  | 								? chunkGraph.getModuleHash(module, chunk.runtime) | 
					
						
							|  |  |  | 								: compilation.codeGenerationResults.getHash( | 
					
						
							|  |  |  | 										module, | 
					
						
							|  |  |  | 										chunk.runtime | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 									); | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 							if (records.chunkModuleHashes[key] !== hash) { | 
					
						
							|  |  |  | 								updatedModules.add(module, chunk); | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 							chunkModuleHashes[key] = hash; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 						/** @type {HotUpdateMainContentByRuntime} */ | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 						const hotUpdateMainContentByRuntime = new Map(); | 
					
						
							|  |  |  | 						let allOldRuntime; | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 						const chunkRuntime = | 
					
						
							|  |  |  | 							/** @type {ChunkRuntime} */ | 
					
						
							|  |  |  | 							(records.chunkRuntime); | 
					
						
							|  |  |  | 						for (const key of Object.keys(chunkRuntime)) { | 
					
						
							|  |  |  | 							const runtime = keyToRuntime(chunkRuntime[key]); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							allOldRuntime = mergeRuntimeOwned(allOldRuntime, runtime); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						forEachRuntime(allOldRuntime, (runtime) => { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 							const { path: filename, info: assetInfo } = | 
					
						
							|  |  |  | 								compilation.getPathWithInfo( | 
					
						
							| 
									
										
										
										
											2025-08-20 18:50:12 +08:00
										 |  |  | 									compilation.outputOptions.hotUpdateMainFilename, | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 									{ | 
					
						
							|  |  |  | 										hash: records.hash, | 
					
						
							|  |  |  | 										runtime | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 							hotUpdateMainContentByRuntime.set( | 
					
						
							|  |  |  | 								/** @type {string} */ (runtime), | 
					
						
							|  |  |  | 								{ | 
					
						
							|  |  |  | 									updatedChunkIds: new Set(), | 
					
						
							|  |  |  | 									removedChunkIds: new Set(), | 
					
						
							|  |  |  | 									removedModules: new Set(), | 
					
						
							|  |  |  | 									filename, | 
					
						
							|  |  |  | 									assetInfo | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 						if (hotUpdateMainContentByRuntime.size === 0) return; | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// Create a list of all active modules to verify which modules are removed completely
 | 
					
						
							| 
									
										
										
										
											2025-08-28 18:34:30 +08:00
										 |  |  | 						/** @type {Map<ModuleId, Module>} */ | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 						const allModules = new Map(); | 
					
						
							|  |  |  | 						for (const module of compilation.modules) { | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 							const id = | 
					
						
							|  |  |  | 								/** @type {ModuleId} */ | 
					
						
							|  |  |  | 								(chunkGraph.getModuleId(module)); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							allModules.set(id, module); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// List of completely removed modules
 | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 						/** @type {Set<string | number>} */ | 
					
						
							|  |  |  | 						const completelyRemovedModules = new Set(); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 05:51:25 +08:00
										 |  |  | 						for (const key of Object.keys(records.chunkHashes)) { | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 							const oldRuntime = keyToRuntime( | 
					
						
							|  |  |  | 								/** @type {ChunkRuntime} */ | 
					
						
							|  |  |  | 								(records.chunkRuntime)[key] | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							/** @type {Module[]} */ | 
					
						
							|  |  |  | 							const remainingModules = []; | 
					
						
							|  |  |  | 							// Check which modules are removed
 | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 							for (const id of records.chunkModuleIds[key]) { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								const module = allModules.get(id); | 
					
						
							|  |  |  | 								if (module === undefined) { | 
					
						
							|  |  |  | 									completelyRemovedModules.add(id); | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									remainingModules.push(module); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 							/** @type {ChunkId | null} */ | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 							let chunkId; | 
					
						
							|  |  |  | 							let newModules; | 
					
						
							|  |  |  | 							let newRuntimeModules; | 
					
						
							|  |  |  | 							let newFullHashModules; | 
					
						
							| 
									
										
										
										
											2021-09-02 16:00:24 +08:00
										 |  |  | 							let newDependentHashModules; | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 							let newRuntime; | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							let removedFromRuntime; | 
					
						
							| 
									
										
										
										
											2018-09-06 22:59:11 +08:00
										 |  |  | 							const currentChunk = find( | 
					
						
							|  |  |  | 								compilation.chunks, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								(chunk) => `${chunk.id}` === key | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							); | 
					
						
							|  |  |  | 							if (currentChunk) { | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								chunkId = currentChunk.id; | 
					
						
							| 
									
										
										
										
											2021-05-27 04:16:32 +08:00
										 |  |  | 								newRuntime = intersectRuntime( | 
					
						
							|  |  |  | 									currentChunk.runtime, | 
					
						
							|  |  |  | 									allOldRuntime | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 								if (newRuntime === undefined) continue; | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								newModules = chunkGraph | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 									.getChunkModules(currentChunk) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									.filter((module) => updatedModules.has(module, currentChunk)); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 								newRuntimeModules = [ | 
					
						
							|  |  |  | 									...chunkGraph.getChunkRuntimeModulesIterable(currentChunk) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								].filter((module) => updatedModules.has(module, currentChunk)); | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 								const fullHashModules = | 
					
						
							|  |  |  | 									chunkGraph.getChunkFullHashModulesIterable(currentChunk); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								newFullHashModules = | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 									fullHashModules && | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									[...fullHashModules].filter((module) => | 
					
						
							| 
									
										
										
										
											2020-07-28 20:06:04 +08:00
										 |  |  | 										updatedModules.has(module, currentChunk) | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 									); | 
					
						
							| 
									
										
										
										
											2021-09-02 16:00:24 +08:00
										 |  |  | 								const dependentHashModules = | 
					
						
							|  |  |  | 									chunkGraph.getChunkDependentHashModulesIterable(currentChunk); | 
					
						
							|  |  |  | 								newDependentHashModules = | 
					
						
							|  |  |  | 									dependentHashModules && | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									[...dependentHashModules].filter((module) => | 
					
						
							| 
									
										
										
										
											2021-09-02 16:00:24 +08:00
										 |  |  | 										updatedModules.has(module, currentChunk) | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								removedFromRuntime = subtractRuntime(oldRuntime, newRuntime); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 							} else { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								// chunk has completely removed
 | 
					
						
							| 
									
										
										
										
											2024-07-31 11:11:11 +08:00
										 |  |  | 								chunkId = `${Number(key)}` === key ? Number(key) : key; | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								removedFromRuntime = oldRuntime; | 
					
						
							|  |  |  | 								newRuntime = oldRuntime; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							if (removedFromRuntime) { | 
					
						
							|  |  |  | 								// chunk was removed from some runtimes
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								forEachRuntime(removedFromRuntime, (runtime) => { | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 									const item = | 
					
						
							|  |  |  | 										/** @type {HotUpdateMainContentByRuntimeItem} */ | 
					
						
							|  |  |  | 										( | 
					
						
							|  |  |  | 											hotUpdateMainContentByRuntime.get( | 
					
						
							|  |  |  | 												/** @type {string} */ (runtime) | 
					
						
							|  |  |  | 											) | 
					
						
							|  |  |  | 										); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 									item.removedChunkIds.add(/** @type {ChunkId} */ (chunkId)); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								}); | 
					
						
							|  |  |  | 								// dispose modules from the chunk in these runtimes
 | 
					
						
							|  |  |  | 								// where they are no longer in this runtime
 | 
					
						
							|  |  |  | 								for (const module of remainingModules) { | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 									const moduleKey = `${key}|${module.identifier()}`; | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 									const oldHash = records.chunkModuleHashes[moduleKey]; | 
					
						
							|  |  |  | 									const runtimes = chunkGraph.getModuleRuntimes(module); | 
					
						
							|  |  |  | 									if (oldRuntime === newRuntime && runtimes.has(newRuntime)) { | 
					
						
							|  |  |  | 										// Module is still in the same runtime combination
 | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 										const hash = nonCodeGeneratedModules.has(module, newRuntime) | 
					
						
							|  |  |  | 											? chunkGraph.getModuleHash(module, newRuntime) | 
					
						
							|  |  |  | 											: compilation.codeGenerationResults.getHash( | 
					
						
							|  |  |  | 													module, | 
					
						
							|  |  |  | 													newRuntime | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 												); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 										if (hash !== oldHash) { | 
					
						
							| 
									
										
										
										
											2023-05-05 07:19:11 +08:00
										 |  |  | 											if (module.type === WEBPACK_MODULE_TYPE_RUNTIME) { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 												newRuntimeModules = newRuntimeModules || []; | 
					
						
							|  |  |  | 												newRuntimeModules.push( | 
					
						
							|  |  |  | 													/** @type {RuntimeModule} */ (module) | 
					
						
							|  |  |  | 												); | 
					
						
							|  |  |  | 											} else { | 
					
						
							|  |  |  | 												newModules = newModules || []; | 
					
						
							|  |  |  | 												newModules.push(module); | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 									} else { | 
					
						
							|  |  |  | 										// module is no longer in this runtime combination
 | 
					
						
							|  |  |  | 										// We (incorrectly) assume that it's not in an overlapping runtime combination
 | 
					
						
							|  |  |  | 										// and dispose it from the main runtimes the chunk was removed from
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 										forEachRuntime(removedFromRuntime, (runtime) => { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 											// If the module is still used in this runtime, do not dispose it
 | 
					
						
							|  |  |  | 											// This could create a bad runtime state where the module is still loaded,
 | 
					
						
							|  |  |  | 											// but no chunk which contains it. This means we don't receive further HMR updates
 | 
					
						
							|  |  |  | 											// to this module and that's bad.
 | 
					
						
							|  |  |  | 											// TODO force load one of the chunks which contains the module
 | 
					
						
							|  |  |  | 											for (const moduleRuntime of runtimes) { | 
					
						
							|  |  |  | 												if (typeof moduleRuntime === "string") { | 
					
						
							|  |  |  | 													if (moduleRuntime === runtime) return; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 												} else if ( | 
					
						
							|  |  |  | 													moduleRuntime !== undefined && | 
					
						
							|  |  |  | 													moduleRuntime.has(/** @type {string} */ (runtime)) | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 												) { | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 													return; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 												} | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 											} | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 											const item = | 
					
						
							|  |  |  | 												/** @type {HotUpdateMainContentByRuntimeItem} */ ( | 
					
						
							|  |  |  | 													hotUpdateMainContentByRuntime.get( | 
					
						
							|  |  |  | 														/** @type {string} */ (runtime) | 
					
						
							|  |  |  | 													) | 
					
						
							|  |  |  | 												); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 											item.removedModules.add(module); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 										}); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							if ( | 
					
						
							|  |  |  | 								(newModules && newModules.length > 0) || | 
					
						
							|  |  |  | 								(newRuntimeModules && newRuntimeModules.length > 0) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								const hotUpdateChunk = new HotUpdateChunk(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								if (backCompat) { | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 									ChunkGraph.setChunkGraphForChunk(hotUpdateChunk, chunkGraph); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								hotUpdateChunk.id = chunkId; | 
					
						
							| 
									
										
										
										
											2024-10-30 17:52:12 +08:00
										 |  |  | 								hotUpdateChunk.runtime = currentChunk | 
					
						
							|  |  |  | 									? currentChunk.runtime | 
					
						
							|  |  |  | 									: newRuntime; | 
					
						
							| 
									
										
										
										
											2020-09-25 02:28:08 +08:00
										 |  |  | 								if (currentChunk) { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 									for (const group of currentChunk.groupsIterable) { | 
					
						
							| 
									
										
										
										
											2020-09-25 02:28:08 +08:00
										 |  |  | 										hotUpdateChunk.addGroup(group); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2020-09-25 02:28:08 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								chunkGraph.attachModules(hotUpdateChunk, newModules || []); | 
					
						
							|  |  |  | 								chunkGraph.attachRuntimeModules( | 
					
						
							|  |  |  | 									hotUpdateChunk, | 
					
						
							|  |  |  | 									newRuntimeModules || [] | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								if (newFullHashModules) { | 
					
						
							|  |  |  | 									chunkGraph.attachFullHashModules( | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 										hotUpdateChunk, | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 										newFullHashModules | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-09-02 16:00:24 +08:00
										 |  |  | 								if (newDependentHashModules) { | 
					
						
							|  |  |  | 									chunkGraph.attachDependentHashModules( | 
					
						
							|  |  |  | 										hotUpdateChunk, | 
					
						
							|  |  |  | 										newDependentHashModules | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 								const renderManifest = compilation.getRenderManifest({ | 
					
						
							|  |  |  | 									chunk: hotUpdateChunk, | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | 									hash: /** @type {string} */ (records.hash), | 
					
						
							|  |  |  | 									fullHash: /** @type {string} */ (records.hash), | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 									outputOptions: compilation.outputOptions, | 
					
						
							|  |  |  | 									moduleTemplates: compilation.moduleTemplates, | 
					
						
							|  |  |  | 									dependencyTemplates: compilation.dependencyTemplates, | 
					
						
							|  |  |  | 									codeGenerationResults: compilation.codeGenerationResults, | 
					
						
							|  |  |  | 									runtimeTemplate: compilation.runtimeTemplate, | 
					
						
							|  |  |  | 									moduleGraph: compilation.moduleGraph, | 
					
						
							|  |  |  | 									chunkGraph | 
					
						
							|  |  |  | 								}); | 
					
						
							|  |  |  | 								for (const entry of renderManifest) { | 
					
						
							|  |  |  | 									/** @type {string} */ | 
					
						
							|  |  |  | 									let filename; | 
					
						
							|  |  |  | 									/** @type {AssetInfo} */ | 
					
						
							|  |  |  | 									let assetInfo; | 
					
						
							|  |  |  | 									if ("filename" in entry) { | 
					
						
							|  |  |  | 										filename = entry.filename; | 
					
						
							|  |  |  | 										assetInfo = entry.info; | 
					
						
							|  |  |  | 									} else { | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 										({ path: filename, info: assetInfo } = | 
					
						
							|  |  |  | 											compilation.getPathWithInfo( | 
					
						
							|  |  |  | 												entry.filenameTemplate, | 
					
						
							|  |  |  | 												entry.pathOptions | 
					
						
							|  |  |  | 											)); | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 									const source = entry.render(); | 
					
						
							|  |  |  | 									compilation.additionalChunkAssets.push(filename); | 
					
						
							|  |  |  | 									compilation.emitAsset(filename, source, { | 
					
						
							|  |  |  | 										hotModuleReplacement: true, | 
					
						
							|  |  |  | 										...assetInfo | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2020-09-04 06:19:39 +08:00
										 |  |  | 									if (currentChunk) { | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 										currentChunk.files.add(filename); | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 										compilation.hooks.chunkAsset.call(currentChunk, filename); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								forEachRuntime(newRuntime, (runtime) => { | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 									const item = | 
					
						
							|  |  |  | 										/** @type {HotUpdateMainContentByRuntimeItem} */ ( | 
					
						
							|  |  |  | 											hotUpdateMainContentByRuntime.get( | 
					
						
							|  |  |  | 												/** @type {string} */ (runtime) | 
					
						
							|  |  |  | 											) | 
					
						
							|  |  |  | 										); | 
					
						
							| 
									
										
										
										
											2024-03-21 20:09:45 +08:00
										 |  |  | 									item.updatedChunkIds.add(/** @type {ChunkId} */ (chunkId)); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 						const completelyRemovedModulesArray = [...completelyRemovedModules]; | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 						const hotUpdateMainContentByFilename = new Map(); | 
					
						
							|  |  |  | 						for (const { | 
					
						
							|  |  |  | 							removedChunkIds, | 
					
						
							|  |  |  | 							removedModules, | 
					
						
							|  |  |  | 							updatedChunkIds, | 
					
						
							|  |  |  | 							filename, | 
					
						
							|  |  |  | 							assetInfo | 
					
						
							|  |  |  | 						} of hotUpdateMainContentByRuntime.values()) { | 
					
						
							|  |  |  | 							const old = hotUpdateMainContentByFilename.get(filename); | 
					
						
							|  |  |  | 							if ( | 
					
						
							|  |  |  | 								old && | 
					
						
							|  |  |  | 								(!isSubset(old.removedChunkIds, removedChunkIds) || | 
					
						
							|  |  |  | 									!isSubset(old.removedModules, removedModules) || | 
					
						
							|  |  |  | 									!isSubset(old.updatedChunkIds, updatedChunkIds)) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								compilation.warnings.push( | 
					
						
							|  |  |  | 									new WebpackError(`HotModuleReplacementPlugin
 | 
					
						
							|  |  |  | The configured output.hotUpdateMainFilename doesn't lead to unique filenames per runtime and HMR update differs between runtimes. | 
					
						
							|  |  |  | This might lead to incorrect runtime behavior of the applied update. | 
					
						
							|  |  |  | To fix this, make sure to include [runtime] in the output.hotUpdateMainFilename option, or use the default config.`)
 | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								for (const chunkId of removedChunkIds) { | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 									old.removedChunkIds.add(chunkId); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 								for (const chunkId of removedModules) { | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 									old.removedModules.add(chunkId); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 								for (const chunkId of updatedChunkIds) { | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 									old.updatedChunkIds.add(chunkId); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 								continue; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							hotUpdateMainContentByFilename.set(filename, { | 
					
						
							|  |  |  | 								removedChunkIds, | 
					
						
							|  |  |  | 								removedModules, | 
					
						
							|  |  |  | 								updatedChunkIds, | 
					
						
							|  |  |  | 								assetInfo | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 						for (const [ | 
					
						
							| 
									
										
										
										
											2020-11-28 22:48:01 +08:00
										 |  |  | 							filename, | 
					
						
							|  |  |  | 							{ removedChunkIds, removedModules, updatedChunkIds, assetInfo } | 
					
						
							|  |  |  | 						] of hotUpdateMainContentByFilename) { | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							const hotUpdateMainJson = { | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 								c: [...updatedChunkIds], | 
					
						
							|  |  |  | 								r: [...removedChunkIds], | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 								m: | 
					
						
							|  |  |  | 									removedModules.size === 0 | 
					
						
							|  |  |  | 										? completelyRemovedModulesArray | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 										: [ | 
					
						
							|  |  |  | 												...completelyRemovedModulesArray, | 
					
						
							|  |  |  | 												...Array.from( | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 													removedModules, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 													(m) => | 
					
						
							| 
									
										
										
										
											2024-08-06 11:08:48 +08:00
										 |  |  | 														/** @type {ModuleId} */ (chunkGraph.getModuleId(m)) | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 												) | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 											] | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-27 02:11:41 +08:00
										 |  |  | 							const source = new RawSource( | 
					
						
							|  |  |  | 								(filename.endsWith(".json") ? "" : "export default ") + | 
					
						
							|  |  |  | 									JSON.stringify(hotUpdateMainJson) | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2020-11-28 19:42:03 +08:00
										 |  |  | 							compilation.emitAsset(filename, source, { | 
					
						
							|  |  |  | 								hotModuleReplacement: true, | 
					
						
							|  |  |  | 								...assetInfo | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 				compilation.hooks.additionalTreeRuntimeRequirements.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 					(chunk, runtimeRequirements) => { | 
					
						
							|  |  |  | 						runtimeRequirements.add(RuntimeGlobals.hmrDownloadManifest); | 
					
						
							|  |  |  | 						runtimeRequirements.add(RuntimeGlobals.hmrDownloadUpdateHandlers); | 
					
						
							|  |  |  | 						runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution); | 
					
						
							|  |  |  | 						runtimeRequirements.add(RuntimeGlobals.moduleCache); | 
					
						
							|  |  |  | 						compilation.addRuntimeModule( | 
					
						
							|  |  |  | 							chunk, | 
					
						
							|  |  |  | 							new HotModuleReplacementRuntimeModule() | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_AUTO) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, (parser) => { | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 						applyModuleHot(parser); | 
					
						
							|  |  |  | 						applyImportMetaHot(parser); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, (parser) => { | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 						applyModuleHot(parser); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				normalModuleFactory.hooks.parser | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					.for(JAVASCRIPT_MODULE_TYPE_ESM) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					.tap(PLUGIN_NAME, (parser) => { | 
					
						
							| 
									
										
										
										
											2020-06-23 05:53:13 +08:00
										 |  |  | 						applyImportMetaHot(parser); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module) => { | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 					module.hot = true; | 
					
						
							|  |  |  | 					return module; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-01-03 19:27:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-12 21:13:55 +08:00
										 |  |  | 				NormalModule.getCompilationHooks(compilation).loader.tap( | 
					
						
							| 
									
										
										
										
											2023-04-01 01:56:32 +08:00
										 |  |  | 					PLUGIN_NAME, | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 					(context) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						context.hot = true; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-06-18 02:57:32 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = HotModuleReplacementPlugin; |