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