| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2017-01-24 03:31:53 +08:00
										 |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-11 12:27:09 +08:00
										 |  |  | const asyncLib = require("neo-async"); | 
					
						
							| 
									
										
										
										
											2017-11-10 18:02:45 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { CachedSource } = require("webpack-sources"); | 
					
						
							|  |  |  | const { | 
					
						
							|  |  |  | 	Tapable, | 
					
						
							|  |  |  | 	SyncHook, | 
					
						
							|  |  |  | 	SyncBailHook, | 
					
						
							|  |  |  | 	SyncWaterfallHook, | 
					
						
							|  |  |  | 	AsyncSeriesHook | 
					
						
							|  |  |  | } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | const EntryModuleNotFoundError = require("./EntryModuleNotFoundError"); | 
					
						
							|  |  |  | const ModuleNotFoundError = require("./ModuleNotFoundError"); | 
					
						
							|  |  |  | const ModuleDependencyWarning = require("./ModuleDependencyWarning"); | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | const ModuleDependencyError = require("./ModuleDependencyError"); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | const ChunkGroup = require("./ChunkGroup"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | const Chunk = require("./Chunk"); | 
					
						
							|  |  |  | const Entrypoint = require("./Entrypoint"); | 
					
						
							|  |  |  | const MainTemplate = require("./MainTemplate"); | 
					
						
							|  |  |  | const ChunkTemplate = require("./ChunkTemplate"); | 
					
						
							|  |  |  | const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate"); | 
					
						
							|  |  |  | const ModuleTemplate = require("./ModuleTemplate"); | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | const RuntimeTemplate = require("./RuntimeTemplate"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | const Dependency = require("./Dependency"); | 
					
						
							|  |  |  | const ChunkRenderError = require("./ChunkRenderError"); | 
					
						
							| 
									
										
										
										
											2017-12-19 23:41:56 +08:00
										 |  |  | const AsyncDependencyToInitialChunkError = require("./AsyncDependencyToInitialChunkError"); | 
					
						
							| 
									
										
										
										
											2017-04-06 19:52:06 +08:00
										 |  |  | const Stats = require("./Stats"); | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | const Semaphore = require("./util/Semaphore"); | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | const createHash = require("./util/createHash"); | 
					
						
							| 
									
										
										
										
											2017-10-13 01:12:48 +08:00
										 |  |  | const Queue = require("./util/Queue"); | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | const GraphHelpers = require("./GraphHelpers"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const byId = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if (a.id > b.id) return 1; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-08-18 19:35:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | const byIdOrIdentifier = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if (a.id > b.id) return 1; | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 	const identA = a.identifier(); | 
					
						
							|  |  |  | 	const identB = b.identifier(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (identA < identB) return -1; | 
					
						
							|  |  |  | 	if (identA > identB) return 1; | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const byIndexOrIdentifier = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.index < b.index) return -1; | 
					
						
							|  |  |  | 	if (a.index > b.index) return 1; | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 	const identA = a.identifier(); | 
					
						
							|  |  |  | 	const identB = b.identifier(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (identA < identB) return -1; | 
					
						
							|  |  |  | 	if (identA > identB) return 1; | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-08-18 19:35:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-03 23:23:41 +08:00
										 |  |  | const byNameOrHash = (a, b) => { | 
					
						
							|  |  |  | 	if (a.name < b.name) return -1; | 
					
						
							|  |  |  | 	if (a.name > b.name) return 1; | 
					
						
							|  |  |  | 	if (a.fullHash < b.fullHash) return -1; | 
					
						
							|  |  |  | 	if (a.fullhash > b.fullHash) return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const iterationBlockVariable = (variables, fn) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for ( | 
					
						
							|  |  |  | 		let indexVariable = 0; | 
					
						
							|  |  |  | 		indexVariable < variables.length; | 
					
						
							|  |  |  | 		indexVariable++ | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2017-12-28 18:39:29 +08:00
										 |  |  | 		const varDep = variables[indexVariable].dependencies; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexVDep = 0; indexVDep < varDep.length; indexVDep++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			fn(varDep[indexVDep]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const iterationOfArrayCallback = (arr, fn) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for (let index = 0; index < arr.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		fn(arr[index]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | function addAllToSet(set, otherSet) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	for (const item of otherSet) { | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 		set.add(item); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | class Compilation extends Tapable { | 
					
						
							|  |  |  | 	constructor(compiler) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks = { | 
					
						
							|  |  |  | 			buildModule: new SyncHook(["module"]), | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 			rebuildModule: new SyncHook(["module"]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			failedModule: new SyncHook(["module", "error"]), | 
					
						
							|  |  |  | 			succeedModule: new SyncHook(["module"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			finishModules: new SyncHook(["modules"]), | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 			finishRebuildingModule: new SyncHook(["module"]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			unseal: new SyncHook([]), | 
					
						
							|  |  |  | 			seal: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			optimizeDependenciesBasic: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			optimizeDependencies: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			optimizeDependenciesAdvanced: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			afterOptimizeDependencies: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			optimize: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			optimizeModulesBasic: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			optimizeModules: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			optimizeModulesAdvanced: new SyncBailHook(["modules"]), | 
					
						
							|  |  |  | 			afterOptimizeModules: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			optimizeChunksBasic: new SyncBailHook(["chunks", "chunkGroups"]), | 
					
						
							|  |  |  | 			optimizeChunks: new SyncBailHook(["chunks", "chunkGroups"]), | 
					
						
							|  |  |  | 			optimizeChunksAdvanced: new SyncBailHook(["chunks", "chunkGroups"]), | 
					
						
							|  |  |  | 			afterOptimizeChunks: new SyncHook(["chunks", "chunkGroups"]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			optimizeTree: new AsyncSeriesHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 			afterOptimizeTree: new SyncHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			optimizeChunkModulesBasic: new SyncBailHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 			optimizeChunkModules: new SyncBailHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 			optimizeChunkModulesAdvanced: new SyncBailHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 			afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]), | 
					
						
							|  |  |  | 			shouldRecord: new SyncBailHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			reviveModules: new SyncHook(["modules", "records"]), | 
					
						
							|  |  |  | 			optimizeModuleOrder: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 			advancedOptimizeModuleOrder: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 			beforeModuleIds: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 			moduleIds: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 			optimizeModuleIds: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 			afterOptimizeModuleIds: new SyncHook(["modules"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			reviveChunks: new SyncHook(["chunks", "records"]), | 
					
						
							|  |  |  | 			optimizeChunkOrder: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 			beforeChunkIds: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 			optimizeChunkIds: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 			afterOptimizeChunkIds: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			recordModules: new SyncHook(["modules", "records"]), | 
					
						
							|  |  |  | 			recordChunks: new SyncHook(["chunks", "records"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			beforeHash: new SyncHook([]), | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 			contentHash: new SyncHook(["chunk"]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			afterHash: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			recordHash: new SyncHook(["records"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			record: new SyncHook(["compilation", "records"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			beforeModuleAssets: new SyncHook([]), | 
					
						
							|  |  |  | 			shouldGenerateChunkAssets: new SyncBailHook([]), | 
					
						
							|  |  |  | 			beforeChunkAssets: new SyncHook([]), | 
					
						
							|  |  |  | 			additionalChunkAssets: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			additionalAssets: new AsyncSeriesHook([]), | 
					
						
							|  |  |  | 			optimizeChunkAssets: new AsyncSeriesHook(["chunks"]), | 
					
						
							|  |  |  | 			afterOptimizeChunkAssets: new SyncHook(["chunks"]), | 
					
						
							|  |  |  | 			optimizeAssets: new AsyncSeriesHook(["assets"]), | 
					
						
							|  |  |  | 			afterOptimizeAssets: new SyncHook(["assets"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			needAdditionalSeal: new SyncBailHook([]), | 
					
						
							|  |  |  | 			afterSeal: new AsyncSeriesHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			chunkHash: new SyncHook(["chunk", "chunkHash"]), | 
					
						
							|  |  |  | 			moduleAsset: new SyncHook(["module", "filename"]), | 
					
						
							|  |  |  | 			chunkAsset: new SyncHook(["chunk", "filename"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			assetPath: new SyncWaterfallHook(["filename", "data"]), // TODO MainTemplate
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			needAdditionalPass: new SyncBailHook([]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			childCompiler: new SyncHook([ | 
					
						
							|  |  |  | 				"childCompiler", | 
					
						
							|  |  |  | 				"compilerName", | 
					
						
							|  |  |  | 				"compilerIndex" | 
					
						
							|  |  |  | 			]), | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// TODO the following hooks are weirdly located here
 | 
					
						
							|  |  |  | 			// TODO move them for webpack 5
 | 
					
						
							|  |  |  | 			normalModuleLoader: new SyncHook(["loaderContext", "module"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			optimizeExtractedChunksBasic: new SyncBailHook(["chunks"]), | 
					
						
							|  |  |  | 			optimizeExtractedChunks: new SyncBailHook(["chunks"]), | 
					
						
							|  |  |  | 			optimizeExtractedChunksAdvanced: new SyncBailHook(["chunks"]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			afterOptimizeExtractedChunks: new SyncHook(["chunks"]) | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		this._pluginCompat.tap("Compilation", options => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			switch (options.name) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				case "optimize-tree": | 
					
						
							|  |  |  | 				case "additional-assets": | 
					
						
							|  |  |  | 				case "optimize-chunk-assets": | 
					
						
							|  |  |  | 				case "optimize-assets": | 
					
						
							|  |  |  | 				case "after-seal": | 
					
						
							|  |  |  | 					options.async = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-03-30 08:33:19 +08:00
										 |  |  | 		this.name = undefined; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.compiler = compiler; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolverFactory = compiler.resolverFactory; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.inputFileSystem = compiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 		this.requestShortener = compiler.requestShortener; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const options = (this.options = compiler.options); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.outputOptions = options && options.output; | 
					
						
							|  |  |  | 		this.bail = options && options.bail; | 
					
						
							|  |  |  | 		this.profile = options && options.profile; | 
					
						
							|  |  |  | 		this.performance = options && options.performance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.mainTemplate = new MainTemplate(this.outputOptions); | 
					
						
							|  |  |  | 		this.chunkTemplate = new ChunkTemplate(this.outputOptions); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.hotUpdateChunkTemplate = new HotUpdateChunkTemplate( | 
					
						
							|  |  |  | 			this.outputOptions | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		this.runtimeTemplate = new RuntimeTemplate( | 
					
						
							|  |  |  | 			this.outputOptions, | 
					
						
							|  |  |  | 			this.requestShortener | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		this.moduleTemplates = { | 
					
						
							| 
									
										
										
										
											2018-04-28 00:53:07 +08:00
										 |  |  | 			javascript: new ModuleTemplate(this.runtimeTemplate, "javascript"), | 
					
						
							|  |  |  | 			webassembly: new ModuleTemplate(this.runtimeTemplate, "webassembly") | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 		this.semaphore = new Semaphore(options.parallelism || 100); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.entries = []; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._preparedEntrypoints = []; | 
					
						
							|  |  |  | 		this.entrypoints = new Map(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.chunks = []; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.chunkGroups = []; | 
					
						
							|  |  |  | 		this.namedChunkGroups = new Map(); | 
					
						
							|  |  |  | 		this.namedChunks = new Map(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.modules = []; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this._modules = new Map(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.cache = null; | 
					
						
							|  |  |  | 		this.records = null; | 
					
						
							|  |  |  | 		this.nextFreeModuleIndex = undefined; | 
					
						
							|  |  |  | 		this.nextFreeModuleIndex2 = undefined; | 
					
						
							|  |  |  | 		this.additionalChunkAssets = []; | 
					
						
							|  |  |  | 		this.assets = {}; | 
					
						
							|  |  |  | 		this.errors = []; | 
					
						
							|  |  |  | 		this.warnings = []; | 
					
						
							|  |  |  | 		this.children = []; | 
					
						
							|  |  |  | 		this.dependencyFactories = new Map(); | 
					
						
							|  |  |  | 		this.dependencyTemplates = new Map(); | 
					
						
							| 
									
										
										
										
											2017-07-14 18:50:39 +08:00
										 |  |  | 		this.dependencyTemplates.set("hash", ""); | 
					
						
							| 
									
										
										
										
											2017-04-13 19:43:51 +08:00
										 |  |  | 		this.childrenCounters = {}; | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 		this.usedChunkIds = null; | 
					
						
							|  |  |  | 		this.usedModuleIds = null; | 
					
						
							| 
									
										
										
										
											2018-03-29 01:10:28 +08:00
										 |  |  | 		this.fileTimestamps = undefined; | 
					
						
							|  |  |  | 		this.contextTimestamps = undefined; | 
					
						
							| 
									
										
										
										
											2018-03-29 01:05:29 +08:00
										 |  |  | 		this.compilationDependencies = undefined; | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this._buildingModules = new Map(); | 
					
						
							|  |  |  | 		this._rebuildingModules = new Map(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-22 23:10:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 19:52:06 +08:00
										 |  |  | 	getStats() { | 
					
						
							|  |  |  | 		return new Stats(this); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-22 23:10:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	addModule(module, cacheGroup) { | 
					
						
							|  |  |  | 		const identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 		const alreadyAddedModule = this._modules.get(identifier); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (alreadyAddedModule) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 			return { | 
					
						
							|  |  |  | 				module: alreadyAddedModule, | 
					
						
							|  |  |  | 				issuer: false, | 
					
						
							|  |  |  | 				build: false, | 
					
						
							|  |  |  | 				dependencies: false | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 		const cacheName = (cacheGroup || "m") + identifier; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.cache && this.cache[cacheName]) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			const cacheModule = this.cache[cacheName]; | 
					
						
							| 
									
										
										
										
											2013-02-01 01:00:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (typeof cacheModule.updateCacheModule === "function") { | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | 				cacheModule.updateCacheModule(module); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			let rebuild = true; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.fileTimestamps && this.contextTimestamps) { | 
					
						
							|  |  |  | 				rebuild = cacheModule.needRebuild( | 
					
						
							|  |  |  | 					this.fileTimestamps, | 
					
						
							|  |  |  | 					this.contextTimestamps | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!rebuild) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				cacheModule.disconnect(); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 				this._modules.set(identifier, cacheModule); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				this.modules.push(cacheModule); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				for (const err of cacheModule.errors) { | 
					
						
							|  |  |  | 					this.errors.push(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				for (const err of cacheModule.warnings) { | 
					
						
							|  |  |  | 					this.warnings.push(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					module: cacheModule, | 
					
						
							|  |  |  | 					issuer: true, | 
					
						
							|  |  |  | 					build: false, | 
					
						
							|  |  |  | 					dependencies: true | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 			cacheModule.unbuild(); | 
					
						
							|  |  |  | 			module = cacheModule; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this._modules.set(identifier, module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.cache) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			this.cache[cacheName] = module; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.modules.push(module); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			module: module, | 
					
						
							|  |  |  | 			issuer: true, | 
					
						
							|  |  |  | 			build: true, | 
					
						
							|  |  |  | 			dependencies: true | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	getModule(module) { | 
					
						
							|  |  |  | 		const identifier = module.identifier(); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		return this._modules.get(identifier); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	findModule(identifier) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		return this._modules.get(identifier); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	waitForBuildingFinished(module, callback) { | 
					
						
							|  |  |  | 		let callbackList = this._buildingModules.get(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (callbackList) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			callbackList.push(() => callback()); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			process.nextTick(callback); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buildModule(module, optional, origin, dependencies, thisCallback) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		let callbackList = this._buildingModules.get(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (callbackList) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			callbackList.push(thisCallback); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this._buildingModules.set(module, (callbackList = [thisCallback])); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const callback = err => { | 
					
						
							|  |  |  | 			this._buildingModules.delete(module); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const cb of callbackList) { | 
					
						
							|  |  |  | 				cb(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 		this.hooks.buildModule.call(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		module.build( | 
					
						
							|  |  |  | 			this.options, | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			this.resolverFactory.get("normal", module.resolveOptions), | 
					
						
							|  |  |  | 			this.inputFileSystem, | 
					
						
							|  |  |  | 			error => { | 
					
						
							|  |  |  | 				const errors = module.errors; | 
					
						
							|  |  |  | 				for (let indexError = 0; indexError < errors.length; indexError++) { | 
					
						
							|  |  |  | 					const err = errors[indexError]; | 
					
						
							|  |  |  | 					err.origin = origin; | 
					
						
							|  |  |  | 					err.dependencies = dependencies; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					if (optional) { | 
					
						
							|  |  |  | 						this.warnings.push(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						this.errors.push(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const warnings = module.warnings; | 
					
						
							|  |  |  | 				for ( | 
					
						
							|  |  |  | 					let indexWarning = 0; | 
					
						
							|  |  |  | 					indexWarning < warnings.length; | 
					
						
							|  |  |  | 					indexWarning++ | 
					
						
							|  |  |  | 				) { | 
					
						
							|  |  |  | 					const war = warnings[indexWarning]; | 
					
						
							|  |  |  | 					war.origin = origin; | 
					
						
							|  |  |  | 					war.dependencies = dependencies; | 
					
						
							|  |  |  | 					this.warnings.push(war); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				module.dependencies.sort(Dependency.compare); | 
					
						
							|  |  |  | 				if (error) { | 
					
						
							|  |  |  | 					this.hooks.failedModule.call(module, error); | 
					
						
							|  |  |  | 					return callback(error); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				this.hooks.succeedModule.call(module); | 
					
						
							|  |  |  | 				return callback(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	processModuleDependencies(module, callback) { | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 		const dependencies = new Map(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const addDependency = dep => { | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 			const resourceIdent = dep.getResourceIdentifier(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (resourceIdent) { | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 				const factory = this.dependencyFactories.get(dep.constructor); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (factory === undefined) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						`No module factory available for dependency type: ${ | 
					
						
							|  |  |  | 							dep.constructor.name | 
					
						
							|  |  |  | 						}`
 | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 				let innerMap = dependencies.get(factory); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (innerMap === undefined) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					dependencies.set(factory, (innerMap = new Map())); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 				let list = innerMap.get(resourceIdent); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (list === undefined) innerMap.set(resourceIdent, (list = [])); | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 				list.push(dep); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const addDependenciesBlock = block => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, addDependency); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.blocks) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.blocks, addDependenciesBlock); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, addDependency); | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 16:06:40 +08:00
										 |  |  | 		try { | 
					
						
							|  |  |  | 			addDependenciesBlock(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		} catch (e) { | 
					
						
							| 
									
										
										
										
											2017-11-19 16:06:40 +08:00
										 |  |  | 			callback(e); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const sortedDependencies = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const pair1 of dependencies) { | 
					
						
							|  |  |  | 			for (const pair2 of pair1[1]) { | 
					
						
							| 
									
										
										
										
											2017-11-19 07:22:38 +08:00
										 |  |  | 				sortedDependencies.push({ | 
					
						
							|  |  |  | 					factory: pair1[0], | 
					
						
							|  |  |  | 					dependencies: pair2[1] | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.addModuleDependencies( | 
					
						
							|  |  |  | 			module, | 
					
						
							|  |  |  | 			sortedDependencies, | 
					
						
							|  |  |  | 			this.bail, | 
					
						
							|  |  |  | 			null, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 			callback | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	addModuleDependencies( | 
					
						
							|  |  |  | 		module, | 
					
						
							|  |  |  | 		dependencies, | 
					
						
							|  |  |  | 		bail, | 
					
						
							|  |  |  | 		cacheGroup, | 
					
						
							|  |  |  | 		recursive, | 
					
						
							|  |  |  | 		callback | 
					
						
							|  |  |  | 	) { | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 		const start = this.profile && Date.now(); | 
					
						
							|  |  |  | 		const currentProfile = this.profile && {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		asyncLib.forEach( | 
					
						
							|  |  |  | 			dependencies, | 
					
						
							|  |  |  | 			(item, callback) => { | 
					
						
							|  |  |  | 				const dependencies = item.dependencies; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const errorAndCallback = err => { | 
					
						
							|  |  |  | 					err.origin = module; | 
					
						
							| 
									
										
										
										
											2018-06-04 16:10:23 +08:00
										 |  |  | 					err.dependencies = dependencies; | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 					this.errors.push(err); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (bail) { | 
					
						
							|  |  |  | 						callback(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						callback(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				const warningAndCallback = err => { | 
					
						
							|  |  |  | 					err.origin = module; | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 					this.warnings.push(err); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					callback(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 				const semaphore = this.semaphore; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				semaphore.acquire(() => { | 
					
						
							|  |  |  | 					const factory = item.factory; | 
					
						
							|  |  |  | 					factory.create( | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							contextInfo: { | 
					
						
							|  |  |  | 								issuer: module.nameForCondition && module.nameForCondition(), | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 								compiler: this.compiler.name | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							}, | 
					
						
							|  |  |  | 							resolveOptions: module.resolveOptions, | 
					
						
							|  |  |  | 							context: module.context, | 
					
						
							|  |  |  | 							dependencies: dependencies | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						(err, dependentModule) => { | 
					
						
							|  |  |  | 							let afterFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							const isOptional = () => { | 
					
						
							|  |  |  | 								return dependencies.every(d => d.optional); | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							const errorOrWarningAndCallback = err => { | 
					
						
							|  |  |  | 								if (isOptional()) { | 
					
						
							|  |  |  | 									return warningAndCallback(err); | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									return errorAndCallback(err); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							if (err) { | 
					
						
							|  |  |  | 								semaphore.release(); | 
					
						
							|  |  |  | 								return errorOrWarningAndCallback( | 
					
						
							| 
									
										
										
										
											2018-06-04 16:10:23 +08:00
										 |  |  | 									new ModuleNotFoundError(module, err) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							if (!dependentModule) { | 
					
						
							|  |  |  | 								semaphore.release(); | 
					
						
							|  |  |  | 								return process.nextTick(callback); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							if (currentProfile) { | 
					
						
							|  |  |  | 								afterFactory = Date.now(); | 
					
						
							|  |  |  | 								currentProfile.factory = afterFactory - start; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							const iterationDependencies = depend => { | 
					
						
							|  |  |  | 								for (let index = 0; index < depend.length; index++) { | 
					
						
							|  |  |  | 									const dep = depend[index]; | 
					
						
							|  |  |  | 									dep.module = dependentModule; | 
					
						
							|  |  |  | 									dependentModule.addReason(module, dep); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 							const addModuleResult = this.addModule( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								dependentModule, | 
					
						
							|  |  |  | 								cacheGroup | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							dependentModule = addModuleResult.module; | 
					
						
							|  |  |  | 							iterationDependencies(dependencies); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							const afterBuild = () => { | 
					
						
							|  |  |  | 								if (currentProfile) { | 
					
						
							|  |  |  | 									const afterBuilding = Date.now(); | 
					
						
							|  |  |  | 									currentProfile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								if (recursive && addModuleResult.dependencies) { | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 									this.processModuleDependencies(dependentModule, callback); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} else { | 
					
						
							|  |  |  | 									return callback(); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							if (addModuleResult.issuer) { | 
					
						
							|  |  |  | 								if (currentProfile) { | 
					
						
							|  |  |  | 									dependentModule.profile = currentProfile; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								dependentModule.issuer = module; | 
					
						
							|  |  |  | 							} else { | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 								if (this.profile) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									if (module.profile) { | 
					
						
							|  |  |  | 										const time = Date.now() - start; | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											!module.profile.dependencies || | 
					
						
							|  |  |  | 											time > module.profile.dependencies | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											module.profile.dependencies = time; | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							if (addModuleResult.build) { | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 								this.buildModule( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									dependentModule, | 
					
						
							|  |  |  | 									isOptional(), | 
					
						
							|  |  |  | 									module, | 
					
						
							|  |  |  | 									dependencies, | 
					
						
							|  |  |  | 									err => { | 
					
						
							|  |  |  | 										if (err) { | 
					
						
							|  |  |  | 											semaphore.release(); | 
					
						
							|  |  |  | 											return errorOrWarningAndCallback(err); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										if (currentProfile) { | 
					
						
							|  |  |  | 											const afterBuilding = Date.now(); | 
					
						
							|  |  |  | 											currentProfile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										semaphore.release(); | 
					
						
							|  |  |  | 										afterBuild(); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							} else { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 								semaphore.release(); | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 								this.waitForBuildingFinished(dependentModule, afterBuild); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			err => { | 
					
						
							|  |  |  | 				// In V8, the Error objects keep a reference to the functions on the stack. These warnings &
 | 
					
						
							|  |  |  | 				// errors are created inside closures that keep a reference to the Compilation, so errors are
 | 
					
						
							|  |  |  | 				// leaking the Compilation object.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					err.stack = err.stack; | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	_addModuleChain(context, dependency, onModule, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-04 10:17:23 +08:00
										 |  |  | 		const start = this.profile && Date.now(); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 		const currentProfile = this.profile && {}; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const errorAndCallback = this.bail | 
					
						
							|  |  |  | 			? err => { | 
					
						
							|  |  |  | 					callback(err); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 			  } | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			: err => { | 
					
						
							|  |  |  | 					err.dependencies = [dependency]; | 
					
						
							|  |  |  | 					this.errors.push(err); | 
					
						
							|  |  |  | 					callback(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 			  }; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			typeof dependency !== "object" || | 
					
						
							|  |  |  | 			dependency === null || | 
					
						
							|  |  |  | 			!dependency.constructor | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			throw new Error("Parameter 'dependency' must be a Dependency"); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const moduleFactory = this.dependencyFactories.get(dependency.constructor); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!moduleFactory) { | 
					
						
							|  |  |  | 			throw new Error( | 
					
						
							|  |  |  | 				`No dependency factory available for this dependency type: ${ | 
					
						
							|  |  |  | 					dependency.constructor.name | 
					
						
							|  |  |  | 				}`
 | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 		this.semaphore.acquire(() => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			moduleFactory.create( | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					contextInfo: { | 
					
						
							|  |  |  | 						issuer: "", | 
					
						
							|  |  |  | 						compiler: this.compiler.name | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					context: context, | 
					
						
							|  |  |  | 					dependencies: [dependency] | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				(err, module) => { | 
					
						
							|  |  |  | 					if (err) { | 
					
						
							|  |  |  | 						this.semaphore.release(); | 
					
						
							|  |  |  | 						return errorAndCallback(new EntryModuleNotFoundError(err)); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					let afterFactory; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (currentProfile) { | 
					
						
							|  |  |  | 						afterFactory = Date.now(); | 
					
						
							|  |  |  | 						currentProfile.factory = afterFactory - start; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const addModuleResult = this.addModule(module); | 
					
						
							|  |  |  | 					module = addModuleResult.module; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					onModule(module); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					dependency.module = module; | 
					
						
							|  |  |  | 					module.addReason(null, dependency); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const afterBuild = () => { | 
					
						
							|  |  |  | 						if (currentProfile) { | 
					
						
							|  |  |  | 							const afterBuilding = Date.now(); | 
					
						
							|  |  |  | 							currentProfile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (addModuleResult.dependencies) { | 
					
						
							|  |  |  | 							this.processModuleDependencies(module, err => { | 
					
						
							|  |  |  | 								if (err) return callback(err); | 
					
						
							|  |  |  | 								callback(null, module); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							return callback(null, module); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (addModuleResult.issuer) { | 
					
						
							|  |  |  | 						if (currentProfile) { | 
					
						
							|  |  |  | 							module.profile = currentProfile; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (addModuleResult.build) { | 
					
						
							|  |  |  | 						this.buildModule(module, false, null, null, err => { | 
					
						
							|  |  |  | 							if (err) { | 
					
						
							|  |  |  | 								this.semaphore.release(); | 
					
						
							|  |  |  | 								return errorAndCallback(err); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							if (currentProfile) { | 
					
						
							|  |  |  | 								const afterBuilding = Date.now(); | 
					
						
							|  |  |  | 								currentProfile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							this.semaphore.release(); | 
					
						
							|  |  |  | 							afterBuild(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-08-11 22:11:17 +08:00
										 |  |  | 						this.semaphore.release(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						this.waitForBuildingFinished(module, afterBuild); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:22:10 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	addEntry(context, entry, name, callback) { | 
					
						
							|  |  |  | 		const slot = { | 
					
						
							|  |  |  | 			name: name, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			request: entry.request, | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			module: null | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._preparedEntrypoints.push(slot); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this._addModuleChain( | 
					
						
							|  |  |  | 			context, | 
					
						
							|  |  |  | 			entry, | 
					
						
							|  |  |  | 			module => { | 
					
						
							|  |  |  | 				this.entries.push(module); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			(err, module) => { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (module) { | 
					
						
							|  |  |  | 					slot.module = module; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					const idx = this._preparedEntrypoints.indexOf(slot); | 
					
						
							|  |  |  | 					this._preparedEntrypoints.splice(idx, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return callback(null, module); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	prefetch(context, dependency, callback) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this._addModuleChain( | 
					
						
							|  |  |  | 			context, | 
					
						
							|  |  |  | 			dependency, | 
					
						
							|  |  |  | 			module => { | 
					
						
							|  |  |  | 				module.prefetched = true; | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			callback | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rebuildModule(module, thisCallback) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		let callbackList = this._rebuildingModules.get(module); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (callbackList) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			callbackList.push(thisCallback); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this._rebuildingModules.set(module, (callbackList = [thisCallback])); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		const callback = err => { | 
					
						
							|  |  |  | 			this._rebuildingModules.delete(module); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const cb of callbackList) { | 
					
						
							|  |  |  | 				cb(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 		this.hooks.rebuildModule.call(module); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		const oldDependencies = module.dependencies.slice(); | 
					
						
							|  |  |  | 		const oldVariables = module.variables.slice(); | 
					
						
							|  |  |  | 		const oldBlocks = module.blocks.slice(); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 		module.unbuild(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.buildModule(module, false, module, null, err => { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 				this.hooks.finishRebuildingModule.call(module); | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.processModuleDependencies(module, err => { | 
					
						
							|  |  |  | 				if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 				this.removeReasonsOfDependencyBlock(module, { | 
					
						
							|  |  |  | 					dependencies: oldDependencies, | 
					
						
							|  |  |  | 					variables: oldVariables, | 
					
						
							|  |  |  | 					blocks: oldBlocks | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:39:42 +08:00
										 |  |  | 				this.hooks.finishRebuildingModule.call(module); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				callback(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	finish() { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const modules = this.modules; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.finishModules.call(modules); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let index = 0; index < modules.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const module = modules[index]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			this.reportDependencyErrorsAndWarnings(module, [module]); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	unseal() { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.unseal.call(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.chunks.length = 0; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.chunkGroups.length = 0; | 
					
						
							|  |  |  | 		this.namedChunks.clear(); | 
					
						
							|  |  |  | 		this.namedChunkGroups.clear(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.additionalChunkAssets.length = 0; | 
					
						
							|  |  |  | 		this.assets = {}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const module of this.modules) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			module.unseal(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	seal(callback) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.seal.call(); | 
					
						
							| 
									
										
										
										
											2017-08-08 15:40:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while ( | 
					
						
							|  |  |  | 			this.hooks.optimizeDependenciesBasic.call(this.modules) || | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.optimizeDependencies.call(this.modules) || | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.hooks.optimizeDependenciesAdvanced.call(this.modules) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			/* empty */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.afterOptimizeDependencies.call(this.modules); | 
					
						
							| 
									
										
										
										
											2017-08-08 15:40:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		this.nextFreeModuleIndex = 0; | 
					
						
							|  |  |  | 		this.nextFreeModuleIndex2 = 0; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const preparedEntrypoint of this._preparedEntrypoints) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const module = preparedEntrypoint.module; | 
					
						
							|  |  |  | 			const name = preparedEntrypoint.name; | 
					
						
							|  |  |  | 			const chunk = this.addChunk(name); | 
					
						
							|  |  |  | 			const entrypoint = new Entrypoint(name); | 
					
						
							|  |  |  | 			entrypoint.setRuntimeChunk(chunk); | 
					
						
							|  |  |  | 			entrypoint.addOrigin(null, name, preparedEntrypoint.request); | 
					
						
							|  |  |  | 			this.namedChunkGroups.set(name, entrypoint); | 
					
						
							|  |  |  | 			this.entrypoints.set(name, entrypoint); | 
					
						
							|  |  |  | 			this.chunkGroups.push(entrypoint); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			GraphHelpers.connectChunkGroupAndChunk(entrypoint, chunk); | 
					
						
							|  |  |  | 			GraphHelpers.connectChunkAndModule(chunk, module); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			chunk.entryModule = module; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunk.name = name; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.assignIndex(module); | 
					
						
							|  |  |  | 			this.assignDepth(module); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-22 21:20:56 +08:00
										 |  |  | 		this.processDependenciesBlocksForChunkGroups(this.chunkGroups.slice()); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		this.sortModules(this.modules); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.optimize.call(); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while ( | 
					
						
							|  |  |  | 			this.hooks.optimizeModulesBasic.call(this.modules) || | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.optimizeModules.call(this.modules) || | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.hooks.optimizeModulesAdvanced.call(this.modules) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			/* empty */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.afterOptimizeModules.call(this.modules); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while ( | 
					
						
							|  |  |  | 			this.hooks.optimizeChunksBasic.call(this.chunks, this.chunkGroups) || | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			this.hooks.optimizeChunks.call(this.chunks, this.chunkGroups) || | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.hooks.optimizeChunksAdvanced.call(this.chunks, this.chunkGroups) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			/* empty */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this.hooks.afterOptimizeChunks.call(this.chunks, this.chunkGroups); | 
					
						
							| 
									
										
										
										
											2015-04-21 01:39:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		this.hooks.optimizeTree.callAsync(this.chunks, this.modules, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.afterOptimizeTree.call(this.chunks, this.modules); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			while ( | 
					
						
							|  |  |  | 				this.hooks.optimizeChunkModulesBasic.call(this.chunks, this.modules) || | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				this.hooks.optimizeChunkModules.call(this.chunks, this.modules) || | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				this.hooks.optimizeChunkModulesAdvanced.call(this.chunks, this.modules) | 
					
						
							|  |  |  | 			) { | 
					
						
							|  |  |  | 				/* empty */ | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.afterOptimizeChunkModules.call(this.chunks, this.modules); | 
					
						
							| 
									
										
										
										
											2017-05-10 19:15:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			const shouldRecord = this.hooks.shouldRecord.call() !== false; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.reviveModules.call(this.modules, this.records); | 
					
						
							|  |  |  | 			this.hooks.optimizeModuleOrder.call(this.modules); | 
					
						
							|  |  |  | 			this.hooks.advancedOptimizeModuleOrder.call(this.modules); | 
					
						
							|  |  |  | 			this.hooks.beforeModuleIds.call(this.modules); | 
					
						
							|  |  |  | 			this.hooks.moduleIds.call(this.modules); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.applyModuleIds(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.optimizeModuleIds.call(this.modules); | 
					
						
							|  |  |  | 			this.hooks.afterOptimizeModuleIds.call(this.modules); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.sortItemsWithModuleIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.reviveChunks.call(this.chunks, this.records); | 
					
						
							|  |  |  | 			this.hooks.optimizeChunkOrder.call(this.chunks); | 
					
						
							|  |  |  | 			this.hooks.beforeChunkIds.call(this.chunks); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.applyChunkIds(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.optimizeChunkIds.call(this.chunks); | 
					
						
							|  |  |  | 			this.hooks.afterOptimizeChunkIds.call(this.chunks); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.sortItemsWithChunkIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (shouldRecord) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				this.hooks.recordModules.call(this.modules, this.records); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				this.hooks.recordChunks.call(this.chunks, this.records); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.beforeHash.call(); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.createHash(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.afterHash.call(); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (shouldRecord) { | 
					
						
							|  |  |  | 				this.hooks.recordHash.call(this.records); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.beforeModuleAssets.call(); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.createModuleAssets(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.hooks.shouldGenerateChunkAssets.call() !== false) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				this.hooks.beforeChunkAssets.call(); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				this.createChunkAssets(); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.additionalChunkAssets.call(this.chunks); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			this.summarizeDependencies(); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (shouldRecord) { | 
					
						
							|  |  |  | 				this.hooks.record.call(this, this.records); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.additionalAssets.callAsync(err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				this.hooks.optimizeChunkAssets.callAsync(this.chunks, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (err) { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 					this.hooks.afterOptimizeChunkAssets.call(this.chunks); | 
					
						
							|  |  |  | 					this.hooks.optimizeAssets.callAsync(this.assets, err => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (err) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 							return callback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 						this.hooks.afterOptimizeAssets.call(this.assets); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (this.hooks.needAdditionalSeal.call()) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 							this.unseal(); | 
					
						
							|  |  |  | 							return this.seal(callback); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 						return this.hooks.afterSeal.callAsync(callback); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sortModules(modules) { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 		modules.sort(byIndexOrIdentifier); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 	reportDependencyErrorsAndWarnings(module, blocks) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const block = blocks[indexBlock]; | 
					
						
							|  |  |  | 			const dependencies = block.dependencies; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (let indexDep = 0; indexDep < dependencies.length; indexDep++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 				const d = dependencies[indexDep]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				const warnings = d.getWarnings(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (warnings) { | 
					
						
							|  |  |  | 					for (let indexWar = 0; indexWar < warnings.length; indexWar++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 						const w = warnings[indexWar]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 						const warning = new ModuleDependencyWarning(module, w, d.loc); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 						this.warnings.push(warning); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 				const errors = d.getErrors(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (errors) { | 
					
						
							|  |  |  | 					for (let indexErr = 0; indexErr < errors.length; indexErr++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 						const e = errors[indexErr]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 						const error = new ModuleDependencyError(module, e, d.loc); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 						this.errors.push(error); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 			this.reportDependencyErrorsAndWarnings(module, block.blocks); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 	addChunkInGroup(groupOptions, module, loc, request) { | 
					
						
							|  |  |  | 		if (typeof groupOptions === "string") { | 
					
						
							|  |  |  | 			groupOptions = { name: groupOptions }; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const name = groupOptions.name; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (name) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const chunkGroup = this.namedChunkGroups.get(name); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (chunkGroup !== undefined) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				chunkGroup.addOptions(groupOptions); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (module) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					chunkGroup.addOrigin(module, loc, request); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				return chunkGroup; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const chunkGroup = new ChunkGroup(groupOptions); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (module) chunkGroup.addOrigin(module, loc, request); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const chunk = this.addChunk(name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		GraphHelpers.connectChunkGroupAndChunk(chunkGroup, chunk); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.chunkGroups.push(chunkGroup); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (name) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			this.namedChunkGroups.set(name, chunkGroup); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return chunkGroup; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	addChunk(name) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (name) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const chunk = this.namedChunks.get(name); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (chunk !== undefined) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				return chunk; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-01-24 20:32:58 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const chunk = new Chunk(name); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.chunks.push(chunk); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (name) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			this.namedChunks.set(name, chunk); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return chunk; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	assignIndex(module) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const assignIndexToModule = module => { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			// enter module
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (typeof module.index !== "number") { | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 				module.index = this.nextFreeModuleIndex++; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// leave module
 | 
					
						
							| 
									
										
										
										
											2018-04-11 04:11:19 +08:00
										 |  |  | 				queue.push(() => (module.index2 = this.nextFreeModuleIndex2++)); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				// enter it as block
 | 
					
						
							|  |  |  | 				assignIndexToDependencyBlock(module); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const assignIndexToDependency = dependency => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (dependency.module) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				queue.push(() => assignIndexToModule(dependency.module)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const assignIndexToDependencyBlock = block => { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			let allDependencies = []; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			const iteratorDependency = d => allDependencies.push(d); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			const iteratorBlock = b => | 
					
						
							|  |  |  | 				queue.push(() => assignIndexToDependencyBlock(b)); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.blocks) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 				const blocks = block.blocks; | 
					
						
							|  |  |  | 				let indexBlock = blocks.length; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				while (indexBlock--) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					iteratorBlock(blocks[indexBlock]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			let indexAll = allDependencies.length; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			while (indexAll--) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iteratorAllDependencies(allDependencies[indexAll]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const queue = [ | 
					
						
							|  |  |  | 			() => { | 
					
						
							|  |  |  | 				assignIndexToModule(module); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		]; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const iteratorAllDependencies = d => { | 
					
						
							|  |  |  | 			queue.push(() => assignIndexToDependency(d)); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (queue.length) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			queue.pop()(); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	assignDepth(module) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 		const queue = new Set([module]); | 
					
						
							|  |  |  | 		let depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		module.depth = 0; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 		const enqueueJob = module => { | 
					
						
							|  |  |  | 			const d = module.depth; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (typeof d === "number" && d <= depth) return; | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 			queue.add(module); | 
					
						
							|  |  |  | 			module.depth = depth; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const assignDepthToDependency = (dependency, depth) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (dependency.module) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 				enqueueJob(dependency.module); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 		const assignDepthToDependencyBlock = block => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.variables) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, assignDepthToDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.dependencies) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, assignDepthToDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block.blocks) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 				iterationOfArrayCallback(block.blocks, assignDepthToDependencyBlock); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (module of queue) { | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 			queue.delete(module); | 
					
						
							|  |  |  | 			depth = module.depth; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 21:31:18 +08:00
										 |  |  | 			depth++; | 
					
						
							|  |  |  | 			assignDepthToDependencyBlock(module); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 	// This method creates the Chunk graph from the Module graph
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	processDependenciesBlocksForChunkGroups(inputChunkGroups) { | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// Process is splitting into two parts:
 | 
					
						
							|  |  |  | 		// Part one traverse the module graph and builds a very basic chunks graph
 | 
					
						
							|  |  |  | 		//   in chunkDependencies.
 | 
					
						
							|  |  |  | 		// Part two traverse every possible way through the basic chunk graph and
 | 
					
						
							|  |  |  | 		//   tracks the available modules. While traversing it connects chunks with
 | 
					
						
							|  |  |  | 		//   eachother and Blocks with Chunks. It stops traversing when all modules
 | 
					
						
							|  |  |  | 		//   for a chunk are already available. So it doesn't connect unneeded chunks.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 		const chunkDependencies = new Map(); // Map<Chunk, Array<{Module, Chunk}>>
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const allCreatedChunkGroups = new Set(); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 20:26:05 +08:00
										 |  |  | 		// PREPARE
 | 
					
						
							|  |  |  | 		const blockInfoMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const iteratorDependency = d => { | 
					
						
							|  |  |  | 			// We skip Dependencies without Reference
 | 
					
						
							|  |  |  | 			const ref = d.getReference(); | 
					
						
							|  |  |  | 			if (!ref) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// We skip Dependencies without Module pointer
 | 
					
						
							|  |  |  | 			const refModule = ref.module; | 
					
						
							|  |  |  | 			if (!refModule) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// We skip weak Dependencies
 | 
					
						
							|  |  |  | 			if (ref.weak) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			blockInfoModules.add(refModule); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const iteratorBlockPrepare = b => { | 
					
						
							|  |  |  | 			blockInfoBlocks.push(b); | 
					
						
							|  |  |  | 			blockQueue.push(b); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let block, blockQueue, blockInfoModules, blockInfoBlocks; | 
					
						
							|  |  |  | 		for (const module of this.modules) { | 
					
						
							|  |  |  | 			blockQueue = [module]; | 
					
						
							|  |  |  | 			while (blockQueue.length > 0) { | 
					
						
							|  |  |  | 				block = blockQueue.pop(); | 
					
						
							|  |  |  | 				blockInfoModules = new Set(); | 
					
						
							|  |  |  | 				blockInfoBlocks = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (block.variables) { | 
					
						
							|  |  |  | 					iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (block.dependencies) { | 
					
						
							|  |  |  | 					iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (block.blocks) { | 
					
						
							|  |  |  | 					iterationOfArrayCallback(block.blocks, iteratorBlockPrepare); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				const blockInfo = { | 
					
						
							|  |  |  | 					modules: blockInfoModules, | 
					
						
							|  |  |  | 					blocks: blockInfoBlocks | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				blockInfoMap.set(block, blockInfo); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// PART ONE
 | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const blockChunkGroups = new Map(); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Start with the provided modules/chunks
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const queue = inputChunkGroups.map(chunkGroup => ({ | 
					
						
							|  |  |  | 			block: chunkGroup.chunks[0].entryModule, | 
					
						
							|  |  |  | 			module: chunkGroup.chunks[0].entryModule, | 
					
						
							|  |  |  | 			chunk: chunkGroup.chunks[0], | 
					
						
							|  |  |  | 			chunkGroup | 
					
						
							| 
									
										
										
										
											2017-10-11 15:38:09 +08:00
										 |  |  | 		})); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 20:26:05 +08:00
										 |  |  | 		let module, chunk, chunkGroup; | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// For each async Block in graph
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const iteratorBlock = b => { | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			// 1. We create a chunk for this Block
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			// but only once (blockChunkGroups map)
 | 
					
						
							|  |  |  | 			let c = blockChunkGroups.get(b); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (c === undefined) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				c = this.namedChunkGroups.get(b.chunkName); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (c && c.isInitial()) { | 
					
						
							|  |  |  | 					this.errors.push( | 
					
						
							|  |  |  | 						new AsyncDependencyToInitialChunkError(b.chunkName, module, b.loc) | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					c = chunkGroup; | 
					
						
							| 
									
										
										
										
											2017-10-17 15:06:05 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					c = this.addChunkInGroup( | 
					
						
							|  |  |  | 						b.groupOptions || b.chunkName, | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						b.loc, | 
					
						
							|  |  |  | 						b.request | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					blockChunkGroups.set(b, c); | 
					
						
							|  |  |  | 					allCreatedChunkGroups.add(c); | 
					
						
							| 
									
										
										
										
											2017-10-17 15:06:05 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				// TODO webpack 5 remove addOptions check
 | 
					
						
							|  |  |  | 				if (c.addOptions) c.addOptions(b.groupOptions); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				c.addOrigin(module, b.loc, b.request); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// 2. We store the Block+Chunk mapping as dependency for the chunk
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			let deps = chunkDependencies.get(chunkGroup); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!deps) chunkDependencies.set(chunkGroup, (deps = [])); | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 			deps.push({ | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 				block: b, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				chunkGroup: c | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// 3. We enqueue the DependenciesBlock for traversal
 | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 			queue.push({ | 
					
						
							|  |  |  | 				block: b, | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				module: module, | 
					
						
							|  |  |  | 				chunk: c.chunks[0], | 
					
						
							|  |  |  | 				chunkGroup: c | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// Iterative traversal of the Module graph
 | 
					
						
							|  |  |  | 		// Recursive would be simpler to write but could result in Stack Overflows
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (queue.length) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const queueItem = queue.pop(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			module = queueItem.module; | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 			block = queueItem.block; | 
					
						
							|  |  |  | 			chunk = queueItem.chunk; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup = queueItem.chunkGroup; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 20:26:05 +08:00
										 |  |  | 			// get prepared block info
 | 
					
						
							|  |  |  | 			const blockInfo = blockInfoMap.get(block); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// Traverse all referenced modules
 | 
					
						
							|  |  |  | 			for (const refModule of blockInfo.modules) { | 
					
						
							|  |  |  | 				// We connect Module and Chunk when not already done
 | 
					
						
							|  |  |  | 				if (chunk.addModule(refModule)) { | 
					
						
							|  |  |  | 					refModule.addChunk(chunk); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// And enqueue the Module for traversal
 | 
					
						
							|  |  |  | 					queue.push({ | 
					
						
							|  |  |  | 						block: refModule, | 
					
						
							|  |  |  | 						module: refModule, | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						chunkGroup | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-27 20:26:05 +08:00
										 |  |  | 			// Traverse all Blocks
 | 
					
						
							|  |  |  | 			iterationOfArrayCallback(blockInfo.blocks, iteratorBlock); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// PART TWO
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let availableModules; | 
					
						
							|  |  |  | 		let newAvailableModules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const queue2 = new Queue( | 
					
						
							|  |  |  | 			inputChunkGroups.map(chunkGroup => ({ | 
					
						
							|  |  |  | 				chunkGroup, | 
					
						
							|  |  |  | 				availableModules: new Set() | 
					
						
							|  |  |  | 			})) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// Helper function to check if all modules of a chunk are available
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const areModulesAvailable = (chunkGroup, availableModules) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				for (const module of chunk.modulesIterable) { | 
					
						
							|  |  |  | 					if (!availableModules.has(module)) return false; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-06-15 04:46:26 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		// For each edge in the basic chunk graph
 | 
					
						
							|  |  |  | 		const filterFn = dep => { | 
					
						
							|  |  |  | 			// Filter egdes that are not needed because all modules are already available
 | 
					
						
							|  |  |  | 			// This also filters circular dependencies in the chunks graph
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const depChunkGroup = dep.chunkGroup; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (areModulesAvailable(depChunkGroup, newAvailableModules)) return false; // break all modules are already available
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const minAvailableModulesMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Iterative traversing of the basic chunk graph
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		while (queue2.length) { | 
					
						
							| 
									
										
										
										
											2017-10-13 01:12:48 +08:00
										 |  |  | 			const queueItem = queue2.dequeue(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup = queueItem.chunkGroup; | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			availableModules = queueItem.availableModules; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// 1. Get minimal available modules
 | 
					
						
							|  |  |  | 			// It doesn't make sense to traverse a chunk again with more available modules.
 | 
					
						
							|  |  |  | 			// This step calculates the minimal available modules and skips traversal when
 | 
					
						
							|  |  |  | 			// the list didn't shrink.
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			let minAvailableModules = minAvailableModulesMap.get(chunkGroup); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (minAvailableModules === undefined) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				minAvailableModulesMap.set(chunkGroup, new Set(availableModules)); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				let deletedModules = false; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const m of minAvailableModules) { | 
					
						
							|  |  |  | 					if (!availableModules.has(m)) { | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 						minAvailableModules.delete(m); | 
					
						
							|  |  |  | 						deletedModules = true; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (!deletedModules) continue; | 
					
						
							| 
									
										
										
										
											2017-10-13 01:12:48 +08:00
										 |  |  | 				availableModules = minAvailableModules; | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			// 2. Get the edges at this point of the graph
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const deps = chunkDependencies.get(chunkGroup); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!deps) continue; | 
					
						
							|  |  |  | 			if (deps.length === 0) continue; | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			// 3. Create a new Set of available modules at this points
 | 
					
						
							|  |  |  | 			newAvailableModules = new Set(availableModules); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				for (const m of chunk.modulesIterable) { | 
					
						
							|  |  |  | 					newAvailableModules.add(m); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			// 4. Filter edges with available modules
 | 
					
						
							|  |  |  | 			const filteredDeps = deps.filter(filterFn); | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			// 5. Foreach remaining edge
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const nextChunkGroups = new Set(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (let i = 0; i < filteredDeps.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 				const dep = filteredDeps[i]; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				const depChunkGroup = dep.chunkGroup; | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 				const depBlock = dep.block; | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:27:17 +08:00
										 |  |  | 				// 6. Connect block with chunk
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				GraphHelpers.connectDependenciesBlockAndChunkGroup( | 
					
						
							|  |  |  | 					depBlock, | 
					
						
							|  |  |  | 					depChunkGroup | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// 7. Connect chunk with parent
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				GraphHelpers.connectChunkGroupParentAndChild(chunkGroup, depChunkGroup); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				nextChunkGroups.add(depChunkGroup); | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// 8. Enqueue further traversal
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const nextChunkGroup of nextChunkGroups) { | 
					
						
							| 
									
										
										
										
											2017-10-13 01:12:48 +08:00
										 |  |  | 				queue2.enqueue({ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					chunkGroup: nextChunkGroup, | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 					availableModules: newAvailableModules | 
					
						
							| 
									
										
										
										
											2017-06-09 16:30:36 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		// Remove all unconnected chunk groups
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of allCreatedChunkGroups) { | 
					
						
							|  |  |  | 			if (chunkGroup.getNumberOfParents() === 0) { | 
					
						
							|  |  |  | 				for (const chunk of chunkGroup.chunks) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					const idx = this.chunks.indexOf(chunk); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (idx >= 0) this.chunks.splice(idx, 1); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					chunk.remove("unconnected"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				chunkGroup.remove("unconnected"); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-10-11 15:44:45 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 	removeReasonsOfDependencyBlock(module, block) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const iteratorDependency = d => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!d.module) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (d.module.removeReason(module, d)) { | 
					
						
							|  |  |  | 				for (const chunk of d.module.chunksIterable) { | 
					
						
							| 
									
										
										
										
											2018-01-24 03:08:32 +08:00
										 |  |  | 					this.patchChunksAfterReasonRemoval(d.module, chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (block.blocks) { | 
					
						
							|  |  |  | 			iterationOfArrayCallback(block.blocks, block => | 
					
						
							|  |  |  | 				this.removeReasonsOfDependencyBlock(module, block) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (block.variables) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	patchChunksAfterReasonRemoval(module, chunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!module.hasReasons()) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			this.removeReasonsOfDependencyBlock(module, module); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!module.hasReasonForChunk(chunk)) { | 
					
						
							|  |  |  | 			if (module.removeChunk(chunk)) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 				this.removeChunkFromDependencies(module, chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	removeChunkFromDependencies(block, chunk) { | 
					
						
							|  |  |  | 		const iteratorDependency = d => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!d.module) { | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 			this.patchChunksAfterReasonRemoval(d.module, chunk); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const blocks = block.blocks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const chunks = blocks[indexBlock].chunks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 				const blockChunk = chunks[indexChunk]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				chunk.removeChunk(blockChunk); | 
					
						
							|  |  |  | 				blockChunk.removeParent(chunk); | 
					
						
							|  |  |  | 				this.removeChunkFromDependencies(chunks, blockChunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-11-02 19:17:05 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	applyModuleIds() { | 
					
						
							| 
									
										
										
										
											2017-12-28 18:39:29 +08:00
										 |  |  | 		const unusedIds = []; | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		let nextFreeModuleId = 0; | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 		const usedIds = new Set(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.usedModuleIds) { | 
					
						
							|  |  |  | 			for (const id of this.usedModuleIds) { | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 				usedIds.add(id); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const modules1 = this.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexModule1 = 0; indexModule1 < modules1.length; indexModule1++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const module1 = modules1[indexModule1]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (module1.id !== null) { | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 				usedIds.add(module1.id); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (usedIds.size > 0) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			let usedIdMax = -1; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const usedIdKey of usedIds) { | 
					
						
							|  |  |  | 				if (typeof usedIdKey !== "number") { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				usedIdMax = Math.max(usedIdMax, usedIdKey); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			let lengthFreeModules = (nextFreeModuleId = usedIdMax + 1); | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			while (lengthFreeModules--) { | 
					
						
							|  |  |  | 				if (!usedIds.has(lengthFreeModules)) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 					unusedIds.push(lengthFreeModules); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const modules2 = this.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const module2 = modules2[indexModule2]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (module2.id === null) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (unusedIds.length > 0) { | 
					
						
							|  |  |  | 					module2.id = unusedIds.pop(); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					module2.id = nextFreeModuleId++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	applyChunkIds() { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const usedIds = new Set(); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		// Get used ids from usedChunkIds property (i. e. from records)
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.usedChunkIds) { | 
					
						
							|  |  |  | 			for (const id of this.usedChunkIds) { | 
					
						
							|  |  |  | 				if (typeof id !== "number") { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				usedIds.add(id); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Get used ids from existing chunks
 | 
					
						
							|  |  |  | 		const chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			const chunk = chunks[indexChunk]; | 
					
						
							|  |  |  | 			const usedIdValue = chunk.id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (typeof usedIdValue !== "number") { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			usedIds.add(usedIdValue); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Calculate maximum assigned chunk id
 | 
					
						
							|  |  |  | 		let nextFreeChunkId = -1; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const id of usedIds) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			nextFreeChunkId = Math.max(nextFreeChunkId, id); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		nextFreeChunkId++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Determine free chunk ids from 0 to maximum
 | 
					
						
							|  |  |  | 		const unusedIds = []; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (nextFreeChunkId > 0) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			let index = nextFreeChunkId; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			while (index--) { | 
					
						
							|  |  |  | 				if (!usedIds.has(index)) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 					unusedIds.push(index); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		// Assign ids to chunk which has no id
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const chunk = chunks[indexChunk]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (chunk.id === null) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (unusedIds.length > 0) { | 
					
						
							|  |  |  | 					chunk.id = unusedIds.pop(); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					chunk.id = nextFreeChunkId++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!chunk.ids) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				chunk.ids = [chunk.id]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	sortItemsWithModuleIds() { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:17:10 +08:00
										 |  |  | 		this.modules.sort(byIdOrIdentifier); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const modules = this.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-04-19 13:57:21 +08:00
										 |  |  | 			modules[indexModule].sortItems(false); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-09-22 23:23:49 +08:00
										 |  |  | 			chunks[indexChunk].sortItems(false); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sortItemsWithChunkIds() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this.chunkGroups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.sortItems(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.chunks.sort(byId); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for ( | 
					
						
							|  |  |  | 			let indexModule = 0; | 
					
						
							|  |  |  | 			indexModule < this.modules.length; | 
					
						
							|  |  |  | 			indexModule++ | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2017-12-28 18:39:29 +08:00
										 |  |  | 			this.modules[indexModule].sortItems(true); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-09-22 23:23:49 +08:00
										 |  |  | 			chunks[indexChunk].sortItems(true); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-11 20:35:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const byMessage = (a, b) => { | 
					
						
							|  |  |  | 			const ma = `${a.message}`; | 
					
						
							|  |  |  | 			const mb = `${b.message}`; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (ma < mb) return -1; | 
					
						
							|  |  |  | 			if (mb < ma) return 1; | 
					
						
							| 
									
										
										
										
											2017-08-11 20:35:08 +08:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-08-11 22:58:18 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-08-11 20:35:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.errors.sort(byMessage); | 
					
						
							|  |  |  | 		this.warnings.sort(byMessage); | 
					
						
							| 
									
										
										
										
											2018-04-03 23:23:41 +08:00
										 |  |  | 		this.children.sort(byNameOrHash); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	summarizeDependencies() { | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 		this.fileDependencies = new SortableSet(this.compilationDependencies); | 
					
						
							|  |  |  | 		this.contextDependencies = new SortableSet(); | 
					
						
							|  |  |  | 		this.missingDependencies = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for ( | 
					
						
							|  |  |  | 			let indexChildren = 0; | 
					
						
							|  |  |  | 			indexChildren < this.children.length; | 
					
						
							|  |  |  | 			indexChildren++ | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2017-12-28 21:38:03 +08:00
										 |  |  | 			const child = this.children[indexChildren]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 			addAllToSet(this.fileDependencies, child.fileDependencies); | 
					
						
							|  |  |  | 			addAllToSet(this.contextDependencies, child.contextDependencies); | 
					
						
							|  |  |  | 			addAllToSet(this.missingDependencies, child.missingDependencies); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for ( | 
					
						
							|  |  |  | 			let indexModule = 0; | 
					
						
							|  |  |  | 			indexModule < this.modules.length; | 
					
						
							|  |  |  | 			indexModule++ | 
					
						
							|  |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2017-12-28 18:39:29 +08:00
										 |  |  | 			const module = this.modules[indexModule]; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (module.buildInfo.fileDependencies) { | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 				addAllToSet(this.fileDependencies, module.buildInfo.fileDependencies); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (module.buildInfo.contextDependencies) { | 
					
						
							|  |  |  | 				addAllToSet( | 
					
						
							|  |  |  | 					this.contextDependencies, | 
					
						
							|  |  |  | 					module.buildInfo.contextDependencies | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const error of this.errors) { | 
					
						
							|  |  |  | 			if ( | 
					
						
							|  |  |  | 				typeof error.missing === "object" && | 
					
						
							|  |  |  | 				error.missing && | 
					
						
							|  |  |  | 				error.missing[Symbol.iterator] | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 				addAllToSet(this.missingDependencies, error.missing); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.fileDependencies.sort(); | 
					
						
							|  |  |  | 		this.contextDependencies.sort(); | 
					
						
							|  |  |  | 		this.missingDependencies.sort(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	createHash() { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 		const hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 		const hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 		const hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | 		const hash = createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (outputOptions.hashSalt) { | 
					
						
							|  |  |  | 			hash.update(outputOptions.hashSalt); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.mainTemplate.updateHash(hash); | 
					
						
							|  |  |  | 		this.chunkTemplate.updateHash(hash); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		for (const key of Object.keys(this.moduleTemplates).sort()) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			this.moduleTemplates[key].updateHash(hash); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		for (const child of this.children) { | 
					
						
							|  |  |  | 			hash.update(child.hash); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (const warning of this.warnings) { | 
					
						
							|  |  |  | 			hash.update(`${warning.message}`); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (const error of this.errors) { | 
					
						
							|  |  |  | 			hash.update(`${error.message}`); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 		const modules = this.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < modules.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 			const module = modules[i]; | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | 			const moduleHash = createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 			module.updateHash(moduleHash); | 
					
						
							|  |  |  | 			module.hash = moduleHash.digest(hashDigest); | 
					
						
							|  |  |  | 			module.renderedHash = module.hash.substr(0, hashDigestLength); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-10 20:20:54 +08:00
										 |  |  | 		// clone needed as sort below is inplace mutation
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const chunks = this.chunks.slice(); | 
					
						
							| 
									
										
										
										
											2017-01-10 20:20:54 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * sort here will bring all "falsy" values to the beginning | 
					
						
							|  |  |  | 		 * this is needed as the "hasRuntime()" chunks are dependent on the | 
					
						
							|  |  |  | 		 * hashes of the non-runtime chunks. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		chunks.sort((a, b) => { | 
					
						
							|  |  |  | 			const aEntry = a.hasRuntime(); | 
					
						
							|  |  |  | 			const bEntry = b.hasRuntime(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (aEntry && !bEntry) return 1; | 
					
						
							|  |  |  | 			if (!aEntry && bEntry) return -1; | 
					
						
							| 
									
										
										
										
											2018-04-03 23:23:41 +08:00
										 |  |  | 			return byId(a, b); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < chunks.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 			const chunk = chunks[i]; | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | 			const chunkHash = createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (outputOptions.hashSalt) { | 
					
						
							|  |  |  | 				chunkHash.update(outputOptions.hashSalt); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			chunk.updateHash(chunkHash); | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 			const template = chunk.hasRuntime() | 
					
						
							|  |  |  | 				? this.mainTemplate | 
					
						
							|  |  |  | 				: this.chunkTemplate; | 
					
						
							|  |  |  | 			template.updateHashForChunk(chunkHash, chunk); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 			this.hooks.chunkHash.call(chunk, chunkHash); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			chunk.hash = chunkHash.digest(hashDigest); | 
					
						
							|  |  |  | 			hash.update(chunk.hash); | 
					
						
							|  |  |  | 			chunk.renderedHash = chunk.hash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 			this.hooks.contentHash.call(chunk); | 
					
						
							| 
									
										
										
										
											2015-06-25 05:17:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 		this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2013-02-13 20:00:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	modifyHash(update) { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 		const hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 		const hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 		const hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2017-11-23 17:59:29 +08:00
										 |  |  | 		const hash = createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		hash.update(this.fullHash); | 
					
						
							|  |  |  | 		hash.update(update); | 
					
						
							|  |  |  | 		this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 		this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2016-10-29 17:11:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	createModuleAssets() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this.modules.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 			const module = this.modules[i]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (module.buildInfo.assets) { | 
					
						
							|  |  |  | 				for (const assetName of Object.keys(module.buildInfo.assets)) { | 
					
						
							| 
									
										
										
										
											2017-02-05 10:28:15 +08:00
										 |  |  | 					const fileName = this.getPath(assetName); | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 					this.assets[fileName] = module.buildInfo.assets[assetName]; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 					this.hooks.moduleAsset.call(module, fileName); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	createChunkAssets() { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:43:14 +08:00
										 |  |  | 		const cachedSourceMap = new Map(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let i = 0; i < this.chunks.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			const chunk = this.chunks[i]; | 
					
						
							|  |  |  | 			chunk.files = []; | 
					
						
							|  |  |  | 			let source; | 
					
						
							|  |  |  | 			let file; | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 			let filenameTemplate; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const template = chunk.hasRuntime() | 
					
						
							|  |  |  | 					? this.mainTemplate | 
					
						
							|  |  |  | 					: this.chunkTemplate; | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 				const manifest = template.getRenderManifest({ | 
					
						
							|  |  |  | 					chunk, | 
					
						
							|  |  |  | 					hash: this.hash, | 
					
						
							|  |  |  | 					fullHash: this.fullHash, | 
					
						
							|  |  |  | 					outputOptions, | 
					
						
							|  |  |  | 					moduleTemplates: this.moduleTemplates, | 
					
						
							|  |  |  | 					dependencyTemplates: this.dependencyTemplates | 
					
						
							|  |  |  | 				}); // [{ render(), filenameTemplate, pathOptions, identifier, hash }]
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const fileManifest of manifest) { | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 					const cacheName = fileManifest.identifier; | 
					
						
							|  |  |  | 					const usedHash = fileManifest.hash; | 
					
						
							|  |  |  | 					filenameTemplate = fileManifest.filenameTemplate; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if ( | 
					
						
							|  |  |  | 						this.cache && | 
					
						
							|  |  |  | 						this.cache[cacheName] && | 
					
						
							|  |  |  | 						this.cache[cacheName].hash === usedHash | 
					
						
							|  |  |  | 					) { | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 						source = this.cache[cacheName].source; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 						source = fileManifest.render(); | 
					
						
							| 
									
										
										
										
											2017-12-01 17:43:14 +08:00
										 |  |  | 						// Ensure that source is a cached source to avoid additional cost because of repeated access
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (!(source instanceof CachedSource)) { | 
					
						
							| 
									
										
										
										
											2017-12-01 17:43:14 +08:00
										 |  |  | 							const cacheEntry = cachedSourceMap.get(source); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							if (cacheEntry) { | 
					
						
							| 
									
										
										
										
											2017-12-01 17:43:14 +08:00
										 |  |  | 								source = cacheEntry; | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								const cachedSource = new CachedSource(source); | 
					
						
							|  |  |  | 								cachedSourceMap.set(source, cachedSource); | 
					
						
							|  |  |  | 								source = cachedSource; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (this.cache) { | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 							this.cache[cacheName] = { | 
					
						
							|  |  |  | 								hash: usedHash, | 
					
						
							| 
									
										
										
										
											2017-12-01 17:43:14 +08:00
										 |  |  | 								source | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 							}; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 					file = this.getPath(filenameTemplate, fileManifest.pathOptions); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					if (this.assets[file] && this.assets[file] !== source) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						throw new Error( | 
					
						
							|  |  |  | 							`Conflict: Multiple assets emit to the same filename ${file}` | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 					this.assets[file] = source; | 
					
						
							|  |  |  | 					chunk.files.push(file); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 					this.hooks.chunkAsset.call(chunk, file); | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} catch (err) { | 
					
						
							|  |  |  | 				this.errors.push( | 
					
						
							|  |  |  | 					new ChunkRenderError(chunk, file || filenameTemplate, err) | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	getPath(filename, data) { | 
					
						
							|  |  |  | 		data = data || {}; | 
					
						
							|  |  |  | 		data.hash = data.hash || this.hash; | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		return this.mainTemplate.getAssetPath(filename, data); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 19:43:51 +08:00
										 |  |  | 	createChildCompiler(name, outputOptions, plugins) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const idx = this.childrenCounters[name] || 0; | 
					
						
							| 
									
										
										
										
											2017-04-13 19:43:51 +08:00
										 |  |  | 		this.childrenCounters[name] = idx + 1; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return this.compiler.createChildCompiler( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			name, | 
					
						
							|  |  |  | 			idx, | 
					
						
							|  |  |  | 			outputOptions, | 
					
						
							|  |  |  | 			plugins | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	checkConstraints() { | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 		const usedIds = new Set(); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const modules = this.modules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const moduleId = modules[indexModule].id; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (moduleId === null) continue; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (usedIds.has(moduleId)) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				throw new Error(`checkConstraints: duplicate module id ${moduleId}`); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-05 14:41:09 +08:00
										 |  |  | 			usedIds.add(moduleId); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 		const chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-03-02 22:09:09 +08:00
										 |  |  | 			const chunk = chunks[indexChunk]; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			if (chunks.indexOf(chunk) !== indexChunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					`checkConstraints: duplicate chunk in compilation ${chunk.debugId}` | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this.chunkGroups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.checkConstraints(); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2018-01-22 22:23:52 +08:00
										 |  |  | Compilation.prototype.applyPlugins = util.deprecate(function(name, ...args) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	this.hooks[ | 
					
						
							|  |  |  | 		name.replace(/[- ]([a-z])/g, match => match[1].toUpperCase()) | 
					
						
							|  |  |  | 	].call(...args); | 
					
						
							| 
									
										
										
										
											2018-01-22 22:23:52 +08:00
										 |  |  | }, "Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 05:28:23 +08:00
										 |  |  | // TODO remove in webpack 5
 | 
					
						
							| 
									
										
										
										
											2017-11-10 18:02:45 +08:00
										 |  |  | Object.defineProperty(Compilation.prototype, "moduleTemplate", { | 
					
						
							|  |  |  | 	configurable: false, | 
					
						
							|  |  |  | 	get: util.deprecate(function() { | 
					
						
							|  |  |  | 		return this.moduleTemplates.javascript; | 
					
						
							|  |  |  | 	}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead"), | 
					
						
							|  |  |  | 	set: util.deprecate(function(value) { | 
					
						
							| 
									
										
										
										
											2017-11-11 18:27:02 +08:00
										 |  |  | 		this.moduleTemplates.javascript = value; | 
					
						
							| 
									
										
										
										
											2017-11-10 18:02:45 +08:00
										 |  |  | 	}, "Compilation.moduleTemplate: Use Compilation.moduleTemplates.javascript instead.") | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | module.exports = Compilation; |