| 
									
										
										
										
											2016-09-06 05:41:03 +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-10 18:59:56 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2017-12-01 17:42:43 +08:00
										 |  |  | const Queue = require("./util/Queue"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 03:12:09 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | /** @typedef {import("./DependenciesBlock")} DependenciesBlock */ | 
					
						
							|  |  |  | /** @typedef {import("./Dependency")} Dependency */ | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | /** @typedef {import("./Dependency").ExportSpec} ExportSpec */ | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | /** @typedef {import("./Dependency").ExportsSpec} ExportsSpec */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./ExportsInfo")} ExportsInfo */ | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-07-28 03:12:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | const PLUGIN_NAME = "FlagDependencyExportsPlugin"; | 
					
						
							|  |  |  | const PLUGIN_LOGGER_NAME = `webpack.${PLUGIN_NAME}`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 18:59:56 +08:00
										 |  |  | class FlagDependencyExportsPlugin { | 
					
						
							| 
									
										
										
										
											2018-07-28 03:12:09 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-04-23 16:48:36 +08:00
										 |  |  | 	 * Apply the plugin | 
					
						
							| 
									
										
										
										
											2018-07-28 03:12:09 +08:00
										 |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-10 18:59:56 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 		compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | 
					
						
							|  |  |  | 			const moduleGraph = compilation.moduleGraph; | 
					
						
							|  |  |  | 			const cache = compilation.getCache(PLUGIN_NAME); | 
					
						
							|  |  |  | 			compilation.hooks.finishModules.tapAsync( | 
					
						
							|  |  |  | 				PLUGIN_NAME, | 
					
						
							|  |  |  | 				(modules, callback) => { | 
					
						
							|  |  |  | 					const logger = compilation.getLogger(PLUGIN_LOGGER_NAME); | 
					
						
							|  |  |  | 					let statRestoredFromMemCache = 0; | 
					
						
							|  |  |  | 					let statRestoredFromCache = 0; | 
					
						
							|  |  |  | 					let statNoExports = 0; | 
					
						
							|  |  |  | 					let statFlaggedUncached = 0; | 
					
						
							|  |  |  | 					let statNotCached = 0; | 
					
						
							|  |  |  | 					let statQueueItemsProcessed = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					const { moduleMemCaches } = compilation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/** @type {Queue<Module>} */ | 
					
						
							|  |  |  | 					const queue = new Queue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// Step 1: Try to restore cached provided export info from cache
 | 
					
						
							|  |  |  | 					logger.time("restore cached provided exports"); | 
					
						
							|  |  |  | 					asyncLib.each( | 
					
						
							|  |  |  | 						modules, | 
					
						
							|  |  |  | 						(module, callback) => { | 
					
						
							|  |  |  | 							const exportsInfo = moduleGraph.getExportsInfo(module); | 
					
						
							|  |  |  | 							// If the module doesn't have an exportsType, it's a module
 | 
					
						
							|  |  |  | 							// without declared exports.
 | 
					
						
							|  |  |  | 							if (!module.buildMeta || !module.buildMeta.exportsType) { | 
					
						
							|  |  |  | 								if (exportsInfo.otherExportsInfo.provided !== null) { | 
					
						
							|  |  |  | 									// It's a module without declared exports
 | 
					
						
							|  |  |  | 									statNoExports++; | 
					
						
							| 
									
										
										
										
											2021-04-23 19:48:31 +08:00
										 |  |  | 									exportsInfo.setHasProvideInfo(); | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 									exportsInfo.setUnknownExportsProvided(); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 									return callback(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							// If the module has no hash, it's uncacheable
 | 
					
						
							|  |  |  | 							if (typeof module.buildInfo.hash !== "string") { | 
					
						
							|  |  |  | 								statFlaggedUncached++; | 
					
						
							|  |  |  | 								// Enqueue uncacheable module for determining the exports
 | 
					
						
							|  |  |  | 								queue.enqueue(module); | 
					
						
							|  |  |  | 								exportsInfo.setHasProvideInfo(); | 
					
						
							|  |  |  | 								return callback(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							const memCache = moduleMemCaches && moduleMemCaches.get(module); | 
					
						
							|  |  |  | 							const memCacheValue = memCache && memCache.get(this); | 
					
						
							|  |  |  | 							if (memCacheValue !== undefined) { | 
					
						
							|  |  |  | 								statRestoredFromMemCache++; | 
					
						
							|  |  |  | 								exportsInfo.restoreProvided(memCacheValue); | 
					
						
							|  |  |  | 								return callback(); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							cache.get( | 
					
						
							|  |  |  | 								module.identifier(), | 
					
						
							|  |  |  | 								module.buildInfo.hash, | 
					
						
							|  |  |  | 								(err, result) => { | 
					
						
							|  |  |  | 									if (err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									if (result !== undefined) { | 
					
						
							|  |  |  | 										statRestoredFromCache++; | 
					
						
							|  |  |  | 										exportsInfo.restoreProvided(result); | 
					
						
							|  |  |  | 									} else { | 
					
						
							|  |  |  | 										statNotCached++; | 
					
						
							|  |  |  | 										// Without cached info enqueue module for determining the exports
 | 
					
						
							|  |  |  | 										queue.enqueue(module); | 
					
						
							|  |  |  | 										exportsInfo.setHasProvideInfo(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 									callback(); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						err => { | 
					
						
							|  |  |  | 							logger.timeEnd("restore cached provided exports"); | 
					
						
							|  |  |  | 							if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** @type {Set<Module>} */ | 
					
						
							|  |  |  | 							const modulesToStore = new Set(); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** @type {Map<Module, Set<Module>>} */ | 
					
						
							|  |  |  | 							const dependencies = new Map(); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** @type {Module} */ | 
					
						
							|  |  |  | 							let module; | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** @type {ExportsInfo} */ | 
					
						
							|  |  |  | 							let exportsInfo; | 
					
						
							| 
									
										
										
										
											2019-01-23 17:05:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** @type {Map<Dependency, ExportsSpec>} */ | 
					
						
							|  |  |  | 							const exportsSpecsFromDependencies = new Map(); | 
					
						
							| 
									
										
										
										
											2021-04-13 23:33:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							let cacheable = true; | 
					
						
							|  |  |  | 							let changed = false; | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							/** | 
					
						
							|  |  |  | 							 * @param {DependenciesBlock} depBlock the dependencies block | 
					
						
							|  |  |  | 							 * @returns {void} | 
					
						
							|  |  |  | 							 */ | 
					
						
							|  |  |  | 							const processDependenciesBlock = depBlock => { | 
					
						
							|  |  |  | 								for (const dep of depBlock.dependencies) { | 
					
						
							|  |  |  | 									processDependency(dep); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								for (const block of depBlock.blocks) { | 
					
						
							|  |  |  | 									processDependenciesBlock(block); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							/** | 
					
						
							|  |  |  | 							 * @param {Dependency} dep the dependency | 
					
						
							|  |  |  | 							 * @returns {void} | 
					
						
							|  |  |  | 							 */ | 
					
						
							|  |  |  | 							const processDependency = dep => { | 
					
						
							|  |  |  | 								const exportDesc = dep.getExports(moduleGraph); | 
					
						
							|  |  |  | 								if (!exportDesc) return; | 
					
						
							|  |  |  | 								exportsSpecsFromDependencies.set(dep, exportDesc); | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							/** | 
					
						
							|  |  |  | 							 * @param {Dependency} dep dependency | 
					
						
							|  |  |  | 							 * @param {ExportsSpec} exportDesc info | 
					
						
							|  |  |  | 							 * @returns {void} | 
					
						
							|  |  |  | 							 */ | 
					
						
							|  |  |  | 							const processExportsSpec = (dep, exportDesc) => { | 
					
						
							|  |  |  | 								const exports = exportDesc.exports; | 
					
						
							|  |  |  | 								const globalCanMangle = exportDesc.canMangle; | 
					
						
							|  |  |  | 								const globalFrom = exportDesc.from; | 
					
						
							|  |  |  | 								const globalPriority = exportDesc.priority; | 
					
						
							|  |  |  | 								const globalTerminalBinding = | 
					
						
							|  |  |  | 									exportDesc.terminalBinding || false; | 
					
						
							|  |  |  | 								const exportDeps = exportDesc.dependencies; | 
					
						
							|  |  |  | 								if (exportDesc.hideExports) { | 
					
						
							|  |  |  | 									for (const name of exportDesc.hideExports) { | 
					
						
							|  |  |  | 										const exportInfo = exportsInfo.getExportInfo(name); | 
					
						
							|  |  |  | 										exportInfo.unsetTarget(dep); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 								if (exports === true) { | 
					
						
							|  |  |  | 									// unknown exports
 | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										exportsInfo.setUnknownExportsProvided( | 
					
						
							|  |  |  | 											globalCanMangle, | 
					
						
							|  |  |  | 											exportDesc.excludeExports, | 
					
						
							|  |  |  | 											globalFrom && dep, | 
					
						
							|  |  |  | 											globalFrom, | 
					
						
							|  |  |  | 											globalPriority | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 									) { | 
					
						
							|  |  |  | 										changed = true; | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								} else if (Array.isArray(exports)) { | 
					
						
							|  |  |  | 									/** | 
					
						
							|  |  |  | 									 * merge in new exports | 
					
						
							|  |  |  | 									 * @param {ExportsInfo} exportsInfo own exports info | 
					
						
							|  |  |  | 									 * @param {(ExportSpec | string)[]} exports list of exports | 
					
						
							|  |  |  | 									 */ | 
					
						
							|  |  |  | 									const mergeExports = (exportsInfo, exports) => { | 
					
						
							|  |  |  | 										for (const exportNameOrSpec of exports) { | 
					
						
							|  |  |  | 											let name; | 
					
						
							|  |  |  | 											let canMangle = globalCanMangle; | 
					
						
							|  |  |  | 											let terminalBinding = globalTerminalBinding; | 
					
						
							|  |  |  | 											let exports = undefined; | 
					
						
							|  |  |  | 											let from = globalFrom; | 
					
						
							|  |  |  | 											let fromExport = undefined; | 
					
						
							|  |  |  | 											let priority = globalPriority; | 
					
						
							|  |  |  | 											let hidden = false; | 
					
						
							|  |  |  | 											if (typeof exportNameOrSpec === "string") { | 
					
						
							|  |  |  | 												name = exportNameOrSpec; | 
					
						
							|  |  |  | 											} else { | 
					
						
							|  |  |  | 												name = exportNameOrSpec.name; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.canMangle !== undefined) | 
					
						
							|  |  |  | 													canMangle = exportNameOrSpec.canMangle; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.export !== undefined) | 
					
						
							|  |  |  | 													fromExport = exportNameOrSpec.export; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.exports !== undefined) | 
					
						
							|  |  |  | 													exports = exportNameOrSpec.exports; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.from !== undefined) | 
					
						
							|  |  |  | 													from = exportNameOrSpec.from; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.priority !== undefined) | 
					
						
							|  |  |  | 													priority = exportNameOrSpec.priority; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.terminalBinding !== undefined) | 
					
						
							|  |  |  | 													terminalBinding = exportNameOrSpec.terminalBinding; | 
					
						
							|  |  |  | 												if (exportNameOrSpec.hidden !== undefined) | 
					
						
							|  |  |  | 													hidden = exportNameOrSpec.hidden; | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2021-02-23 04:55:35 +08:00
										 |  |  | 											const exportInfo = exportsInfo.getExportInfo(name); | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												exportInfo.provided === false || | 
					
						
							|  |  |  | 												exportInfo.provided === null | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												exportInfo.provided = true; | 
					
						
							|  |  |  | 												changed = true; | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												exportInfo.canMangleProvide !== false && | 
					
						
							|  |  |  | 												canMangle === false | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												exportInfo.canMangleProvide = false; | 
					
						
							|  |  |  | 												changed = true; | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if (terminalBinding && !exportInfo.terminalBinding) { | 
					
						
							|  |  |  | 												exportInfo.terminalBinding = true; | 
					
						
							|  |  |  | 												changed = true; | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if (exports) { | 
					
						
							|  |  |  | 												const nestedExportsInfo = | 
					
						
							|  |  |  | 													exportInfo.createNestedExportsInfo(); | 
					
						
							|  |  |  | 												mergeExports(nestedExportsInfo, exports); | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												from && | 
					
						
							|  |  |  | 												(hidden | 
					
						
							|  |  |  | 													? exportInfo.unsetTarget(dep) | 
					
						
							|  |  |  | 													: exportInfo.setTarget( | 
					
						
							|  |  |  | 															dep, | 
					
						
							|  |  |  | 															from, | 
					
						
							|  |  |  | 															fromExport === undefined ? [name] : fromExport, | 
					
						
							|  |  |  | 															priority | 
					
						
							|  |  |  | 													  )) | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												changed = true; | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											// Recalculate target exportsInfo
 | 
					
						
							|  |  |  | 											const target = exportInfo.getTarget(moduleGraph); | 
					
						
							|  |  |  | 											let targetExportsInfo = undefined; | 
					
						
							|  |  |  | 											if (target) { | 
					
						
							|  |  |  | 												const targetModuleExportsInfo = | 
					
						
							|  |  |  | 													moduleGraph.getExportsInfo(target.module); | 
					
						
							|  |  |  | 												targetExportsInfo = | 
					
						
							|  |  |  | 													targetModuleExportsInfo.getNestedExportsInfo( | 
					
						
							|  |  |  | 														target.export | 
					
						
							|  |  |  | 													); | 
					
						
							|  |  |  | 												// add dependency for this module
 | 
					
						
							|  |  |  | 												const set = dependencies.get(target.module); | 
					
						
							|  |  |  | 												if (set === undefined) { | 
					
						
							|  |  |  | 													dependencies.set(target.module, new Set([module])); | 
					
						
							|  |  |  | 												} else { | 
					
						
							|  |  |  | 													set.add(module); | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 												} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											} | 
					
						
							| 
									
										
										
										
											2020-08-12 00:06:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											if (exportInfo.exportsInfoOwned) { | 
					
						
							|  |  |  | 												if ( | 
					
						
							|  |  |  | 													exportInfo.exportsInfo.setRedirectNamedTo( | 
					
						
							|  |  |  | 														targetExportsInfo | 
					
						
							|  |  |  | 													) | 
					
						
							| 
									
										
										
										
											2020-08-13 00:05:58 +08:00
										 |  |  | 												) { | 
					
						
							|  |  |  | 													changed = true; | 
					
						
							| 
									
										
										
										
											2019-03-14 19:06:59 +08:00
										 |  |  | 												} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 											} else if (exportInfo.exportsInfo !== targetExportsInfo) { | 
					
						
							|  |  |  | 												exportInfo.exportsInfo = targetExportsInfo; | 
					
						
							|  |  |  | 												changed = true; | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 											} | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 									}; | 
					
						
							|  |  |  | 									mergeExports(exportsInfo, exports); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								// store dependencies
 | 
					
						
							|  |  |  | 								if (exportDeps) { | 
					
						
							|  |  |  | 									cacheable = false; | 
					
						
							|  |  |  | 									for (const exportDependency of exportDeps) { | 
					
						
							|  |  |  | 										// add dependency for this module
 | 
					
						
							|  |  |  | 										const set = dependencies.get(exportDependency); | 
					
						
							|  |  |  | 										if (set === undefined) { | 
					
						
							|  |  |  | 											dependencies.set(exportDependency, new Set([module])); | 
					
						
							|  |  |  | 										} else { | 
					
						
							|  |  |  | 											set.add(module); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							const notifyDependencies = () => { | 
					
						
							|  |  |  | 								const deps = dependencies.get(module); | 
					
						
							|  |  |  | 								if (deps !== undefined) { | 
					
						
							|  |  |  | 									for (const dep of deps) { | 
					
						
							|  |  |  | 										queue.enqueue(dep); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							logger.time("figure out provided exports"); | 
					
						
							|  |  |  | 							while (queue.length > 0) { | 
					
						
							|  |  |  | 								module = queue.dequeue(); | 
					
						
							| 
									
										
										
										
											2018-12-30 16:03:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								statQueueItemsProcessed++; | 
					
						
							| 
									
										
										
										
											2020-08-14 12:29:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								exportsInfo = moduleGraph.getExportsInfo(module); | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								cacheable = true; | 
					
						
							|  |  |  | 								changed = false; | 
					
						
							| 
									
										
										
										
											2021-04-23 19:48:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								exportsSpecsFromDependencies.clear(); | 
					
						
							|  |  |  | 								moduleGraph.freeze(); | 
					
						
							|  |  |  | 								processDependenciesBlock(module); | 
					
						
							|  |  |  | 								moduleGraph.unfreeze(); | 
					
						
							|  |  |  | 								for (const [dep, exportsSpec] of exportsSpecsFromDependencies) { | 
					
						
							|  |  |  | 									processExportsSpec(dep, exportsSpec); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2018-12-30 21:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								if (cacheable) { | 
					
						
							|  |  |  | 									modulesToStore.add(module); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-04-23 19:48:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 								if (changed) { | 
					
						
							|  |  |  | 									notifyDependencies(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 							logger.timeEnd("figure out provided exports"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							logger.log( | 
					
						
							|  |  |  | 								`${Math.round( | 
					
						
							|  |  |  | 									(100 * (statFlaggedUncached + statNotCached)) / | 
					
						
							|  |  |  | 										(statRestoredFromMemCache + | 
					
						
							|  |  |  | 											statRestoredFromCache + | 
					
						
							|  |  |  | 											statNotCached + | 
					
						
							|  |  |  | 											statFlaggedUncached + | 
					
						
							|  |  |  | 											statNoExports) | 
					
						
							|  |  |  | 								)}% of exports of modules have been determined (${statNoExports} no declared exports, ${statNotCached} not cached, ${statFlaggedUncached} flagged uncacheable, ${statRestoredFromCache} from cache, ${statRestoredFromMemCache} from mem cache, ${ | 
					
						
							|  |  |  | 									statQueueItemsProcessed - statNotCached - statFlaggedUncached | 
					
						
							|  |  |  | 								} additional calculations due to dependencies)`
 | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							logger.time("store provided exports into cache"); | 
					
						
							|  |  |  | 							asyncLib.each( | 
					
						
							|  |  |  | 								modulesToStore, | 
					
						
							|  |  |  | 								(module, callback) => { | 
					
						
							|  |  |  | 									if (typeof module.buildInfo.hash !== "string") { | 
					
						
							|  |  |  | 										// not cacheable
 | 
					
						
							|  |  |  | 										return callback(); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									const cachedData = moduleGraph | 
					
						
							|  |  |  | 										.getExportsInfo(module) | 
					
						
							|  |  |  | 										.getRestoreProvidedData(); | 
					
						
							|  |  |  | 									const memCache = | 
					
						
							|  |  |  | 										moduleMemCaches && moduleMemCaches.get(module); | 
					
						
							|  |  |  | 									if (memCache) { | 
					
						
							|  |  |  | 										memCache.set(this, cachedData); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									cache.store( | 
					
						
							|  |  |  | 										module.identifier(), | 
					
						
							|  |  |  | 										module.buildInfo.hash, | 
					
						
							|  |  |  | 										cachedData, | 
					
						
							|  |  |  | 										callback | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								}, | 
					
						
							|  |  |  | 								err => { | 
					
						
							|  |  |  | 									logger.timeEnd("store provided exports into cache"); | 
					
						
							|  |  |  | 									callback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/** @type {WeakMap<Module, any>} */ | 
					
						
							|  |  |  | 			const providedExportsCache = new WeakMap(); | 
					
						
							|  |  |  | 			compilation.hooks.rebuildModule.tap(PLUGIN_NAME, module => { | 
					
						
							|  |  |  | 				providedExportsCache.set( | 
					
						
							|  |  |  | 					module, | 
					
						
							|  |  |  | 					moduleGraph.getExportsInfo(module).getRestoreProvidedData() | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2023-03-31 23:18:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 			compilation.hooks.finishRebuildingModule.tap(PLUGIN_NAME, module => { | 
					
						
							|  |  |  | 				moduleGraph | 
					
						
							|  |  |  | 					.getExportsInfo(module) | 
					
						
							|  |  |  | 					.restoreProvided(providedExportsCache.get(module)); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-10 18:59:56 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-09-06 05:41:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 18:59:56 +08:00
										 |  |  | module.exports = FlagDependencyExportsPlugin; |