| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 18:07:20 +08:00
										 |  |  | const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency"); | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 18:07:20 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class InferAsyncModulesPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap("InferAsyncModulesPlugin", compilation => { | 
					
						
							|  |  |  | 			const { moduleGraph } = compilation; | 
					
						
							|  |  |  | 			compilation.hooks.finishModules.tap( | 
					
						
							|  |  |  | 				"InferAsyncModulesPlugin", | 
					
						
							|  |  |  | 				modules => { | 
					
						
							|  |  |  | 					/** @type {Set<Module>} */ | 
					
						
							|  |  |  | 					const queue = new Set(); | 
					
						
							|  |  |  | 					for (const module of modules) { | 
					
						
							|  |  |  | 						if (module.buildMeta && module.buildMeta.async) { | 
					
						
							|  |  |  | 							queue.add(module); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					for (const module of queue) { | 
					
						
							|  |  |  | 						moduleGraph.setAsync(module); | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 						for (const [ | 
					
						
							|  |  |  | 							originModule, | 
					
						
							|  |  |  | 							connections | 
					
						
							|  |  |  | 						] of moduleGraph.getIncomingConnectionsByOriginModule(module)) { | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 							if ( | 
					
						
							| 
									
										
										
										
											2021-02-23 17:59:59 +08:00
										 |  |  | 								connections.some( | 
					
						
							|  |  |  | 									c => | 
					
						
							|  |  |  | 										c.dependency instanceof HarmonyImportDependency && | 
					
						
							|  |  |  | 										c.isTargetActive(undefined) | 
					
						
							|  |  |  | 								) | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 							) { | 
					
						
							| 
									
										
										
										
											2023-05-25 06:09:00 +08:00
										 |  |  | 								queue.add(/** @type {Module} */ (originModule)); | 
					
						
							| 
									
										
										
										
											2019-06-05 17:15:25 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = InferAsyncModulesPlugin; |