| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2020-07-30 17:18:09 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin"; | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | class FlagAllModulesAsUsedPlugin { | 
					
						
							|  |  |  | 	constructor(explanation) { | 
					
						
							|  |  |  | 		this.explanation = explanation; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | 
					
						
							|  |  |  | 			const moduleGraph = compilation.moduleGraph; | 
					
						
							|  |  |  | 			compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, modules => { | 
					
						
							|  |  |  | 				/** @type {RuntimeSpec} */ | 
					
						
							|  |  |  | 				let runtime = undefined; | 
					
						
							|  |  |  | 				for (const [name, { options }] of compilation.entries) { | 
					
						
							|  |  |  | 					runtime = mergeRuntimeOwned( | 
					
						
							|  |  |  | 						runtime, | 
					
						
							|  |  |  | 						getEntryRuntime(compilation, name, options) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for (const module of modules) { | 
					
						
							|  |  |  | 					const exportsInfo = moduleGraph.getExportsInfo(module); | 
					
						
							|  |  |  | 					exportsInfo.setUsedInUnknownWay(runtime); | 
					
						
							|  |  |  | 					moduleGraph.addExtraReason(module, this.explanation); | 
					
						
							|  |  |  | 					if (module.factoryMeta === undefined) { | 
					
						
							|  |  |  | 						module.factoryMeta = {}; | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 					module.factoryMeta.sideEffectFree = false; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-01-03 00:37:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = FlagAllModulesAsUsedPlugin; |