| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2021-01-12 00:20:51 +08:00
										 |  |  | const ModuleGraphConnection = require("./ModuleGraphConnection"); | 
					
						
							| 
									
										
										
										
											2021-02-04 21:21:27 +08:00
										 |  |  | const { first } = require("./util/SetHelpers"); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | const StringXor = require("./util/StringXor"); | 
					
						
							| 
									
										
										
										
											2018-08-28 21:07:28 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	compareModulesById, | 
					
						
							|  |  |  | 	compareIterables, | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 	compareModulesByIdentifier, | 
					
						
							|  |  |  | 	concatComparators, | 
					
						
							|  |  |  | 	compareSelect, | 
					
						
							|  |  |  | 	compareIds | 
					
						
							| 
									
										
										
										
											2018-08-28 21:07:28 +08:00
										 |  |  | } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | const createHash = require("./util/createHash"); | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | const findGraphRoots = require("./util/findGraphRoots"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	RuntimeSpecMap, | 
					
						
							|  |  |  | 	RuntimeSpecSet, | 
					
						
							|  |  |  | 	runtimeToString, | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 	mergeRuntime, | 
					
						
							|  |  |  | 	forEachRuntime | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | } = require("./util/runtime"); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("./ChunkGroup")} ChunkGroup */ | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | /** @typedef {import("./Entrypoint")} Entrypoint */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-08-16 22:11:20 +08:00
										 |  |  | /** @typedef {import("./ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | /** @typedef {import("./RuntimeModule")} RuntimeModule */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | /** @type {ReadonlySet<string>} */ | 
					
						
							|  |  |  | const EMPTY_SET = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 21:07:28 +08:00
										 |  |  | const compareModuleIterables = compareIterables(compareModulesByIdentifier); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | /** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ChunkSizeOptions | 
					
						
							|  |  |  |  * @property {number=} chunkOverhead constant overhead for a chunk | 
					
						
							|  |  |  |  * @property {number=} entryChunkMultiplicator multiplicator for initial chunks | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | class ModuleHashInfo { | 
					
						
							|  |  |  | 	constructor(hash, renderedHash) { | 
					
						
							|  |  |  | 		this.hash = hash; | 
					
						
							|  |  |  | 		this.renderedHash = renderedHash; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @template T @typedef {(set: SortableSet<T>) => T[]} SetToArrayFunction<T> */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @param {SortableSet<T>} set the set | 
					
						
							|  |  |  |  * @returns {T[]} set as array | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getArray = set => { | 
					
						
							|  |  |  | 	return Array.from(set); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 07:25:38 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {SortableSet<Chunk>} chunks the chunks | 
					
						
							|  |  |  |  * @returns {RuntimeSpecSet} runtimes | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getModuleRuntimes = chunks => { | 
					
						
							|  |  |  | 	const runtimes = new RuntimeSpecSet(); | 
					
						
							|  |  |  | 	for (const chunk of chunks) { | 
					
						
							|  |  |  | 		runtimes.add(chunk.runtime); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return runtimes; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:20:34 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {SortableSet<Module>} set the set | 
					
						
							|  |  |  |  * @returns {Map<string, SortableSet<Module>>} modules by source type | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const modulesBySourceType = set => { | 
					
						
							|  |  |  | 	/** @type {Map<string, SortableSet<Module>>} */ | 
					
						
							|  |  |  | 	const map = new Map(); | 
					
						
							|  |  |  | 	for (const module of set) { | 
					
						
							|  |  |  | 		for (const sourceType of module.getSourceTypes()) { | 
					
						
							|  |  |  | 			let innerSet = map.get(sourceType); | 
					
						
							|  |  |  | 			if (innerSet === undefined) { | 
					
						
							|  |  |  | 				innerSet = new SortableSet(); | 
					
						
							|  |  |  | 				map.set(sourceType, innerSet); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			innerSet.add(module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-20 22:27:38 +08:00
										 |  |  | 	for (const [key, innerSet] of map) { | 
					
						
							|  |  |  | 		// When all modules have the source type, we reuse the original SortableSet
 | 
					
						
							|  |  |  | 		// to benefit from the shared cache (especially for sorting)
 | 
					
						
							|  |  |  | 		if (innerSet.size === set.size) { | 
					
						
							|  |  |  | 			map.set(key, set); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-20 18:20:34 +08:00
										 |  |  | 	return map; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /** @type {WeakMap<Function, any>} */ | 
					
						
							|  |  |  | const createOrderedArrayFunctionMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template T | 
					
						
							|  |  |  |  * @param {function(T, T): -1|0|1} comparator comparator function | 
					
						
							|  |  |  |  * @returns {SetToArrayFunction<T>} set as ordered array | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const createOrderedArrayFunction = comparator => { | 
					
						
							|  |  |  | 	/** @type {SetToArrayFunction<T>} */ | 
					
						
							|  |  |  | 	let fn = createOrderedArrayFunctionMap.get(comparator); | 
					
						
							|  |  |  | 	if (fn !== undefined) return fn; | 
					
						
							|  |  |  | 	fn = set => { | 
					
						
							|  |  |  | 		set.sortWith(comparator); | 
					
						
							|  |  |  | 		return Array.from(set); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	createOrderedArrayFunctionMap.set(comparator, fn); | 
					
						
							|  |  |  | 	return fn; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  |  * @param {Iterable<Module>} modules the modules to get the count/size of | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  |  * @returns {number} the size of the modules | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  | const getModulesSize = modules => { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	let size = 0; | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  | 	for (const module of modules) { | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  | 		for (const type of module.getSourceTypes()) { | 
					
						
							|  |  |  | 			size += module.size(type); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return size; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  |  * @param {Iterable<Module>} modules the sortable Set to get the size of | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  |  * @returns {Record<string, number>} the sizes of the modules | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  | const getModulesSizes = modules => { | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  | 	let sizes = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  | 	for (const module of modules) { | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  | 		for (const type of module.getSourceTypes()) { | 
					
						
							|  |  |  | 			sizes[type] = (sizes[type] || 0) + module.size(type); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return sizes; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 06:07:25 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Chunk} a chunk | 
					
						
							|  |  |  |  * @param {Chunk} b chunk | 
					
						
							|  |  |  |  * @returns {boolean} true, if a is always a parent of b | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const isAvailableChunk = (a, b) => { | 
					
						
							|  |  |  | 	const queue = new Set(b.groupsIterable); | 
					
						
							|  |  |  | 	for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 		if (a.isInGroup(chunkGroup)) continue; | 
					
						
							|  |  |  | 		if (chunkGroup.isInitial()) return false; | 
					
						
							|  |  |  | 		for (const parent of chunkGroup.parentsIterable) { | 
					
						
							|  |  |  | 			queue.add(parent); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | class ChunkGraphModule { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							|  |  |  | 		/** @type {SortableSet<Chunk>} */ | 
					
						
							|  |  |  | 		this.chunks = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		/** @type {Set<Chunk> | undefined} */ | 
					
						
							|  |  |  | 		this.entryInChunks = undefined; | 
					
						
							| 
									
										
										
										
											2019-11-08 19:28:54 +08:00
										 |  |  | 		/** @type {Set<Chunk> | undefined} */ | 
					
						
							|  |  |  | 		this.runtimeInChunks = undefined; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		/** @type {RuntimeSpecMap<ModuleHashInfo>} */ | 
					
						
							|  |  |  | 		this.hashes = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 		/** @type {string | number} */ | 
					
						
							|  |  |  | 		this.id = null; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		/** @type {RuntimeSpecMap<Set<string>> | undefined} */ | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		this.runtimeRequirements = undefined; | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 		/** @type {RuntimeSpecMap<string>} */ | 
					
						
							|  |  |  | 		this.graphHashes = undefined; | 
					
						
							|  |  |  | 		/** @type {RuntimeSpecMap<string>} */ | 
					
						
							|  |  |  | 		this.graphHashesWithConnections = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ChunkGraphChunk { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							|  |  |  | 		/** @type {SortableSet<Module>} */ | 
					
						
							|  |  |  | 		this.modules = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 		/** @type {Map<Module, Entrypoint>} */ | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		this.entryModules = new Map(); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		/** @type {SortableSet<RuntimeModule>} */ | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		this.runtimeModules = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 		/** @type {Set<RuntimeModule> | undefined} */ | 
					
						
							|  |  |  | 		this.fullHashModules = undefined; | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		/** @type {Set<string> | undefined} */ | 
					
						
							|  |  |  | 		this.runtimeRequirements = undefined; | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		/** @type {Set<string>} */ | 
					
						
							|  |  |  | 		this.runtimeRequirementsInTree = new Set(); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ChunkGraph { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(moduleGraph) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		/** @private @type {WeakMap<Module, ChunkGraphModule>} */ | 
					
						
							|  |  |  | 		this._modules = new WeakMap(); | 
					
						
							|  |  |  | 		/** @private @type {WeakMap<Chunk, ChunkGraphChunk>} */ | 
					
						
							|  |  |  | 		this._chunks = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 		/** @private @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>} */ | 
					
						
							|  |  |  | 		this._blockChunkGroups = new WeakMap(); | 
					
						
							| 
									
										
										
										
											2020-10-23 20:52:23 +08:00
										 |  |  | 		/** @private @type {Map<string, string | number>} */ | 
					
						
							|  |  |  | 		this._runtimeIds = new Map(); | 
					
						
							| 
									
										
										
										
											2020-02-28 16:50:30 +08:00
										 |  |  | 		/** @type {ModuleGraph} */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		this.moduleGraph = moduleGraph; | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this._getGraphRoots = this._getGraphRoots.bind(this); | 
					
						
							| 
									
										
										
										
											2019-10-28 21:41:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Caching
 | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleKey1 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleValue1 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleKey2 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleValue2 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkKey1 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkValue1 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkKey2 = undefined; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkValue2 = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @private | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {ChunkGraphModule} internal module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getChunkGraphModule(module) { | 
					
						
							| 
									
										
										
										
											2019-10-28 21:41:03 +08:00
										 |  |  | 		if (this._cacheChunkGraphModuleKey1 === module) | 
					
						
							|  |  |  | 			return this._cacheChunkGraphModuleValue1; | 
					
						
							|  |  |  | 		if (this._cacheChunkGraphModuleKey2 === module) | 
					
						
							|  |  |  | 			return this._cacheChunkGraphModuleValue2; | 
					
						
							|  |  |  | 		let cgm = this._modules.get(module); | 
					
						
							|  |  |  | 		if (cgm === undefined) { | 
					
						
							|  |  |  | 			cgm = new ChunkGraphModule(); | 
					
						
							|  |  |  | 			this._modules.set(module, cgm); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-28 21:41:03 +08:00
										 |  |  | 		this._cacheChunkGraphModuleKey2 = this._cacheChunkGraphModuleKey1; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleValue2 = this._cacheChunkGraphModuleValue1; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleKey1 = module; | 
					
						
							|  |  |  | 		this._cacheChunkGraphModuleValue1 = cgm; | 
					
						
							|  |  |  | 		return cgm; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @private | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {ChunkGraphChunk} internal chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getChunkGraphChunk(chunk) { | 
					
						
							| 
									
										
										
										
											2019-10-28 21:41:03 +08:00
										 |  |  | 		if (this._cacheChunkGraphChunkKey1 === chunk) | 
					
						
							|  |  |  | 			return this._cacheChunkGraphChunkValue1; | 
					
						
							|  |  |  | 		if (this._cacheChunkGraphChunkKey2 === chunk) | 
					
						
							|  |  |  | 			return this._cacheChunkGraphChunkValue2; | 
					
						
							|  |  |  | 		let cgc = this._chunks.get(chunk); | 
					
						
							|  |  |  | 		if (cgc === undefined) { | 
					
						
							|  |  |  | 			cgc = new ChunkGraphChunk(); | 
					
						
							|  |  |  | 			this._chunks.set(chunk, cgc); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-28 21:41:03 +08:00
										 |  |  | 		this._cacheChunkGraphChunkKey2 = this._cacheChunkGraphChunkKey1; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkValue2 = this._cacheChunkGraphChunkValue1; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkKey1 = chunk; | 
					
						
							|  |  |  | 		this._cacheChunkGraphChunkValue1 = cgc; | 
					
						
							|  |  |  | 		return cgc; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {SortableSet<Module>} set the sortable Set to get the roots of | 
					
						
							|  |  |  | 	 * @returns {Module[]} the graph roots | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getGraphRoots(set) { | 
					
						
							|  |  |  | 		const { moduleGraph } = this; | 
					
						
							|  |  |  | 		return Array.from( | 
					
						
							|  |  |  | 			findGraphRoots(set, module => { | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 				/** @type {Set<Module>} */ | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 				const set = new Set(); | 
					
						
							| 
									
										
										
										
											2021-01-12 00:20:51 +08:00
										 |  |  | 				const addDependencies = module => { | 
					
						
							|  |  |  | 					for (const connection of moduleGraph.getOutgoingConnections(module)) { | 
					
						
							|  |  |  | 						if (!connection.module) continue; | 
					
						
							|  |  |  | 						const activeState = connection.getActiveState(undefined); | 
					
						
							|  |  |  | 						if (activeState === false) continue; | 
					
						
							|  |  |  | 						if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) { | 
					
						
							|  |  |  | 							addDependencies(connection.module); | 
					
						
							|  |  |  | 							continue; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						set.add(connection.module); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				addDependencies(module); | 
					
						
							| 
									
										
										
										
											2019-10-30 04:37:59 +08:00
										 |  |  | 				return set; | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 			}) | 
					
						
							|  |  |  | 		).sort(compareModulesByIdentifier); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2019-11-08 20:21:21 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	connectChunkAndModule(chunk, module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		cgm.chunks.add(chunk); | 
					
						
							|  |  |  | 		cgc.modules.add(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectChunkAndModule(chunk, module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		cgc.modules.delete(module); | 
					
						
							|  |  |  | 		cgm.chunks.delete(chunk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk which will be disconnected | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectChunk(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		for (const module of cgc.modules) { | 
					
						
							|  |  |  | 			const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 			cgm.chunks.delete(chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		cgc.modules.clear(); | 
					
						
							|  |  |  | 		chunk.disconnectFromGroups(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<Module>} modules the modules | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	attachModules(chunk, modules) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		for (const module of modules) { | 
					
						
							|  |  |  | 			cgc.modules.add(module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<RuntimeModule>} modules the runtime modules | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	attachRuntimeModules(chunk, modules) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		for (const module of modules) { | 
					
						
							|  |  |  | 			cgc.runtimeModules.add(module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<RuntimeModule>} modules the modules that require a full hash | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	attachFullHashModules(chunk, modules) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		if (cgc.fullHashModules === undefined) cgc.fullHashModules = new Set(); | 
					
						
							|  |  |  | 		for (const module of modules) { | 
					
						
							|  |  |  | 			cgc.fullHashModules.add(module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} oldModule the replaced module | 
					
						
							|  |  |  | 	 * @param {Module} newModule the replacing module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	replaceModule(oldModule, newModule) { | 
					
						
							|  |  |  | 		const oldCgm = this._getChunkGraphModule(oldModule); | 
					
						
							|  |  |  | 		const newCgm = this._getChunkGraphModule(newModule); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunk of oldCgm.chunks) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 			const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 			cgc.modules.delete(oldModule); | 
					
						
							|  |  |  | 			cgc.modules.add(newModule); | 
					
						
							|  |  |  | 			newCgm.chunks.add(chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		oldCgm.chunks.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		if (oldCgm.entryInChunks !== undefined) { | 
					
						
							|  |  |  | 			if (newCgm.entryInChunks === undefined) { | 
					
						
							|  |  |  | 				newCgm.entryInChunks = new Set(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const chunk of oldCgm.entryInChunks) { | 
					
						
							|  |  |  | 				const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 				const old = cgc.entryModules.get(oldModule); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 				/** @type {Map<Module, Entrypoint>} */ | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 				const newEntryModules = new Map(); | 
					
						
							|  |  |  | 				for (const [m, cg] of cgc.entryModules) { | 
					
						
							|  |  |  | 					if (m === oldModule) { | 
					
						
							|  |  |  | 						newEntryModules.set(newModule, old); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						newEntryModules.set(m, cg); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 				cgc.entryModules = newEntryModules; | 
					
						
							|  |  |  | 				newCgm.entryInChunks.add(chunk); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 			oldCgm.entryInChunks = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-08 19:28:54 +08:00
										 |  |  | 		if (oldCgm.runtimeInChunks !== undefined) { | 
					
						
							|  |  |  | 			if (newCgm.runtimeInChunks === undefined) { | 
					
						
							|  |  |  | 				newCgm.runtimeInChunks = new Set(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const chunk of oldCgm.runtimeInChunks) { | 
					
						
							|  |  |  | 				const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 				cgc.runtimeModules.delete(/** @type {RuntimeModule} */ (oldModule)); | 
					
						
							|  |  |  | 				cgc.runtimeModules.add(/** @type {RuntimeModule} */ (newModule)); | 
					
						
							|  |  |  | 				newCgm.runtimeInChunks.add(chunk); | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 				if ( | 
					
						
							|  |  |  | 					cgc.fullHashModules !== undefined && | 
					
						
							|  |  |  | 					cgc.fullHashModules.has(/** @type {RuntimeModule} */ (oldModule)) | 
					
						
							|  |  |  | 				) { | 
					
						
							|  |  |  | 					cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule)); | 
					
						
							|  |  |  | 					cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-11-08 19:28:54 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			oldCgm.runtimeInChunks = undefined; | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the checked module | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the checked chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk contains the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isModuleInChunk(module, chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.has(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the checked module | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the checked chunk group | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk contains the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isModuleInChunkGroup(module, chunkGroup) { | 
					
						
							|  |  |  | 		for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 			if (this.isModuleInChunk(module, chunk)) return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the checked module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the module is entry of any chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isEntryModule(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		return cgm.entryInChunks !== undefined; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {Iterable<Chunk>} iterable of chunks (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleChunksIterable(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		return cgm.chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {function(Chunk, Chunk): -1|0|1} sortFn sort function | 
					
						
							|  |  |  | 	 * @returns {Iterable<Chunk>} iterable of chunks (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrderedModuleChunksIterable(module, sortFn) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		cgm.chunks.sortWith(sortFn); | 
					
						
							|  |  |  | 		return cgm.chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {Chunk[]} array of chunks (cached, do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleChunks(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		return cgm.chunks.getFromCache(getArray); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {number} the number of chunk which contain the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getNumberOfModuleChunks(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		return cgm.chunks.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {RuntimeSpecSet} runtimes | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleRuntimes(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2021-02-23 07:25:38 +08:00
										 |  |  | 		return cgm.chunks.getFromUnorderedCache(getModuleRuntimes); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {number} the number of module which are contained in this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getNumberOfChunkModules(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Iterable<Module>} return the modules for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModulesIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:20:34 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {string} sourceType source type | 
					
						
							|  |  |  | 	 * @returns {Iterable<Module> | undefined} return the modules for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModulesIterableBySourceType(chunk, sourceType) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const modulesWithSourceType = cgc.modules | 
					
						
							|  |  |  | 			.getFromUnorderedCache(modulesBySourceType) | 
					
						
							|  |  |  | 			.get(sourceType); | 
					
						
							|  |  |  | 		return modulesWithSourceType; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {function(Module, Module): -1|0|1} comparator comparator function | 
					
						
							|  |  |  | 	 * @returns {Iterable<Module>} return the modules for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrderedChunkModulesIterable(chunk, comparator) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		cgc.modules.sortWith(comparator); | 
					
						
							|  |  |  | 		return cgc.modules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:20:34 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {string} sourceType source type | 
					
						
							|  |  |  | 	 * @param {function(Module, Module): -1|0|1} comparator comparator function | 
					
						
							|  |  |  | 	 * @returns {Iterable<Module> | undefined} return the modules for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const modulesWithSourceType = cgc.modules | 
					
						
							|  |  |  | 			.getFromUnorderedCache(modulesBySourceType) | 
					
						
							|  |  |  | 			.get(sourceType); | 
					
						
							|  |  |  | 		if (modulesWithSourceType === undefined) return undefined; | 
					
						
							|  |  |  | 		modulesWithSourceType.sortWith(comparator); | 
					
						
							|  |  |  | 		return modulesWithSourceType; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Module[]} return the modules for this chunk (cached, do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModules(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.getFromUnorderedCache(getArray); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {function(Module, Module): -1|0|1} comparator comparator function | 
					
						
							|  |  |  | 	 * @returns {Module[]} return the modules for this chunk (cached, do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getOrderedChunkModules(chunk, comparator) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const arrayFunction = createOrderedArrayFunction(comparator); | 
					
						
							|  |  |  | 		return cgc.modules.getFromUnorderedCache(arrayFunction); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 23:08:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {ModuleFilterPredicate} filterFn function used to filter modules | 
					
						
							|  |  |  | 	 * @param {boolean} includeAllChunks all chunks or only async chunks | 
					
						
							|  |  |  | 	 * @returns {Record<string|number, (string|number)[]>} chunk to module ids object | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModuleIdMap(chunk, filterFn, includeAllChunks = false) { | 
					
						
							|  |  |  | 		/** @type {Record<string|number, (string|number)[]>} */ | 
					
						
							|  |  |  | 		const chunkModuleIdMap = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const asyncChunk of includeAllChunks | 
					
						
							|  |  |  | 			? chunk.getAllReferencedChunks() | 
					
						
							|  |  |  | 			: chunk.getAllAsyncChunks()) { | 
					
						
							|  |  |  | 			/** @type {(string|number)[]} */ | 
					
						
							|  |  |  | 			let array; | 
					
						
							|  |  |  | 			for (const module of this.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 				asyncChunk, | 
					
						
							|  |  |  | 				compareModulesById(this) | 
					
						
							|  |  |  | 			)) { | 
					
						
							|  |  |  | 				if (filterFn(module)) { | 
					
						
							|  |  |  | 					if (array === undefined) { | 
					
						
							|  |  |  | 						array = []; | 
					
						
							|  |  |  | 						chunkModuleIdMap[asyncChunk.id] = array; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					const moduleId = this.getModuleId(module); | 
					
						
							|  |  |  | 					array.push(moduleId); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return chunkModuleIdMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {ModuleFilterPredicate} filterFn function used to filter modules | 
					
						
							|  |  |  | 	 * @param {number} hashLength length of the hash | 
					
						
							|  |  |  | 	 * @param {boolean} includeAllChunks all chunks or only async chunks | 
					
						
							|  |  |  | 	 * @returns {Record<string|number, Record<string|number, string>>} chunk to module id to module hash object | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModuleRenderedHashMap( | 
					
						
							|  |  |  | 		chunk, | 
					
						
							|  |  |  | 		filterFn, | 
					
						
							|  |  |  | 		hashLength = 0, | 
					
						
							|  |  |  | 		includeAllChunks = false | 
					
						
							|  |  |  | 	) { | 
					
						
							|  |  |  | 		/** @type {Record<string|number, Record<string|number, string>>} */ | 
					
						
							|  |  |  | 		const chunkModuleHashMap = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const asyncChunk of includeAllChunks | 
					
						
							|  |  |  | 			? chunk.getAllReferencedChunks() | 
					
						
							|  |  |  | 			: chunk.getAllAsyncChunks()) { | 
					
						
							|  |  |  | 			/** @type {Record<string|number, string>} */ | 
					
						
							|  |  |  | 			let idToHashMap; | 
					
						
							|  |  |  | 			for (const module of this.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 				asyncChunk, | 
					
						
							|  |  |  | 				compareModulesById(this) | 
					
						
							|  |  |  | 			)) { | 
					
						
							|  |  |  | 				if (filterFn(module)) { | 
					
						
							|  |  |  | 					if (idToHashMap === undefined) { | 
					
						
							|  |  |  | 						idToHashMap = Object.create(null); | 
					
						
							|  |  |  | 						chunkModuleHashMap[asyncChunk.id] = idToHashMap; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					const moduleId = this.getModuleId(module); | 
					
						
							|  |  |  | 					const hash = this.getRenderedModuleHash(module, asyncChunk.runtime); | 
					
						
							|  |  |  | 					idToHashMap[moduleId] = hashLength ? hash.slice(0, hashLength) : hash; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return chunkModuleHashMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {ChunkFilterPredicate} filterFn function used to filter chunks | 
					
						
							|  |  |  | 	 * @returns {Record<string|number, boolean>} chunk map | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkConditionMap(chunk, filterFn) { | 
					
						
							|  |  |  | 		const map = Object.create(null); | 
					
						
							|  |  |  | 		for (const asyncChunk of chunk.getAllAsyncChunks()) { | 
					
						
							|  |  |  | 			map[asyncChunk.id] = filterFn(asyncChunk, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (const depChunk of this.getChunkEntryDependentChunksIterable(chunk)) { | 
					
						
							|  |  |  | 			map[depChunk.id] = filterFn(depChunk, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return map; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	 * @param {ModuleFilterPredicate} filterFn predicate function used to filter modules | 
					
						
							|  |  |  | 	 * @param {ChunkFilterPredicate=} filterChunkFn predicate function used to filter chunks | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 * @returns {boolean} return true if module exists in graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	hasModuleInGraph(chunk, filterFn, filterChunkFn) { | 
					
						
							|  |  |  | 		const queue = new Set(chunk.groupsIterable); | 
					
						
							|  |  |  | 		const chunksProcessed = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const innerChunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				if (!chunksProcessed.has(innerChunk)) { | 
					
						
							|  |  |  | 					chunksProcessed.add(innerChunk); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 					if (!filterChunkFn || filterChunkFn(innerChunk, this)) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 						for (const module of this.getChunkModulesIterable(innerChunk)) { | 
					
						
							|  |  |  | 							if (filterFn(module)) { | 
					
						
							|  |  |  | 								return true; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkA first chunk | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkB second chunk | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	 * @returns {-1|0|1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-22 17:49:27 +08:00
										 |  |  | 	compareChunks(chunkA, chunkB) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		const cgcA = this._getChunkGraphChunk(chunkA); | 
					
						
							|  |  |  | 		const cgcB = this._getChunkGraphChunk(chunkB); | 
					
						
							|  |  |  | 		if (cgcA.modules.size > cgcB.modules.size) return -1; | 
					
						
							|  |  |  | 		if (cgcA.modules.size < cgcB.modules.size) return 1; | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 		cgcA.modules.sortWith(compareModulesByIdentifier); | 
					
						
							|  |  |  | 		cgcB.modules.sortWith(compareModulesByIdentifier); | 
					
						
							| 
									
										
										
										
											2018-08-28 21:07:28 +08:00
										 |  |  | 		return compareModuleIterables(cgcA.modules, cgcB.modules); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {number} total size of all modules in the chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModulesSize(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.getFromUnorderedCache(getModulesSize); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-05 20:18:38 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Record<string, number>} total sizes of all modules in the chunk by source type | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkModulesSizes(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.getFromUnorderedCache(getModulesSizes); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2019-04-13 00:29:41 +08:00
										 |  |  | 	 * @returns {Module[]} root modules of the chunks (ordered by identifier) | 
					
						
							| 
									
										
										
										
											2018-12-06 19:30:22 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkRootModules(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.modules.getFromUnorderedCache(this._getGraphRoots); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {ChunkSizeOptions} options options object | 
					
						
							|  |  |  | 	 * @returns {number} total size of the chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-10 03:34:28 +08:00
										 |  |  | 	getChunkSize(chunk, options = {}) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const modulesSize = cgc.modules.getFromUnorderedCache(getModulesSize); | 
					
						
							|  |  |  | 		const chunkOverhead = | 
					
						
							|  |  |  | 			typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000; | 
					
						
							|  |  |  | 		const entryChunkMultiplicator = | 
					
						
							|  |  |  | 			typeof options.entryChunkMultiplicator === "number" | 
					
						
							|  |  |  | 				? options.entryChunkMultiplicator | 
					
						
							|  |  |  | 				: 10; | 
					
						
							|  |  |  | 		return ( | 
					
						
							|  |  |  | 			chunkOverhead + | 
					
						
							|  |  |  | 			modulesSize * (chunk.canBeInitial() ? entryChunkMultiplicator : 1) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkA chunk | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkB chunk | 
					
						
							|  |  |  | 	 * @param {ChunkSizeOptions} options options object | 
					
						
							|  |  |  | 	 * @returns {number} total size of the chunk or false if chunks can't be integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-10 03:34:28 +08:00
										 |  |  | 	getIntegratedChunksSize(chunkA, chunkB, options = {}) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		const cgcA = this._getChunkGraphChunk(chunkA); | 
					
						
							|  |  |  | 		const cgcB = this._getChunkGraphChunk(chunkB); | 
					
						
							|  |  |  | 		const allModules = new Set(cgcA.modules); | 
					
						
							|  |  |  | 		for (const m of cgcB.modules) allModules.add(m); | 
					
						
							| 
									
										
										
										
											2018-12-05 20:47:08 +08:00
										 |  |  | 		let modulesSize = getModulesSize(allModules); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		const chunkOverhead = | 
					
						
							|  |  |  | 			typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000; | 
					
						
							|  |  |  | 		const entryChunkMultiplicator = | 
					
						
							|  |  |  | 			typeof options.entryChunkMultiplicator === "number" | 
					
						
							|  |  |  | 				? options.entryChunkMultiplicator | 
					
						
							|  |  |  | 				: 10; | 
					
						
							|  |  |  | 		return ( | 
					
						
							|  |  |  | 			chunkOverhead + | 
					
						
							|  |  |  | 			modulesSize * | 
					
						
							|  |  |  | 				(chunkA.canBeInitial() || chunkB.canBeInitial() | 
					
						
							|  |  |  | 					? entryChunkMultiplicator | 
					
						
							|  |  |  | 					: 1) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkA chunk | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkB chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if chunks could be integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	canChunksBeIntegrated(chunkA, chunkB) { | 
					
						
							| 
									
										
										
										
											2018-12-04 18:02:26 +08:00
										 |  |  | 		if (chunkA.preventIntegration || chunkB.preventIntegration) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const hasRuntimeA = chunkA.hasRuntime(); | 
					
						
							|  |  |  | 		const hasRuntimeB = chunkB.hasRuntime(); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-04 18:02:26 +08:00
										 |  |  | 		if (hasRuntimeA !== hasRuntimeB) { | 
					
						
							|  |  |  | 			if (hasRuntimeA) { | 
					
						
							| 
									
										
										
										
											2019-04-12 06:07:25 +08:00
										 |  |  | 				return isAvailableChunk(chunkA, chunkB); | 
					
						
							| 
									
										
										
										
											2018-12-04 18:02:26 +08:00
										 |  |  | 			} else if (hasRuntimeB) { | 
					
						
							| 
									
										
										
										
											2019-04-12 06:07:25 +08:00
										 |  |  | 				return isAvailableChunk(chunkB, chunkA); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( | 
					
						
							|  |  |  | 			this.getNumberOfEntryModules(chunkA) > 0 || | 
					
						
							|  |  |  | 			this.getNumberOfEntryModules(chunkB) > 0 | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkA the target chunk | 
					
						
							|  |  |  | 	 * @param {Chunk} chunkB the chunk to integrate | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	integrateChunks(chunkA, chunkB) { | 
					
						
							| 
									
										
										
										
											2018-10-25 02:10:30 +08:00
										 |  |  | 		// Decide for one name (deterministic)
 | 
					
						
							|  |  |  | 		if (chunkA.name && chunkB.name) { | 
					
						
							| 
									
										
										
										
											2018-10-25 02:30:39 +08:00
										 |  |  | 			if ( | 
					
						
							|  |  |  | 				this.getNumberOfEntryModules(chunkA) > 0 === | 
					
						
							|  |  |  | 				this.getNumberOfEntryModules(chunkB) > 0 | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2018-10-25 02:10:30 +08:00
										 |  |  | 				// When both chunks have entry modules or none have one, use
 | 
					
						
							|  |  |  | 				// shortest name
 | 
					
						
							|  |  |  | 				if (chunkA.name.length !== chunkB.name.length) { | 
					
						
							|  |  |  | 					chunkA.name = | 
					
						
							|  |  |  | 						chunkA.name.length < chunkB.name.length ? chunkA.name : chunkB.name; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					chunkA.name = chunkA.name < chunkB.name ? chunkA.name : chunkB.name; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-10-25 02:30:39 +08:00
										 |  |  | 			} else if (this.getNumberOfEntryModules(chunkB) > 0) { | 
					
						
							| 
									
										
										
										
											2018-10-25 02:10:30 +08:00
										 |  |  | 				// Pick the name of the chunk with the entry module
 | 
					
						
							|  |  |  | 				chunkA.name = chunkB.name; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (chunkB.name) { | 
					
						
							|  |  |  | 			chunkA.name = chunkB.name; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 		// Merge id name hints
 | 
					
						
							|  |  |  | 		for (const hint of chunkB.idNameHints) { | 
					
						
							|  |  |  | 			chunkA.idNameHints.add(hint); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		// Merge runtime
 | 
					
						
							|  |  |  | 		chunkA.runtime = mergeRuntime(chunkA.runtime, chunkB.runtime); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		// getChunkModules is used here to create a clone, because disconnectChunkAndModule modifies
 | 
					
						
							|  |  |  | 		for (const module of this.getChunkModules(chunkB)) { | 
					
						
							|  |  |  | 			this.disconnectChunkAndModule(chunkB, module); | 
					
						
							|  |  |  | 			this.connectChunkAndModule(chunkA, module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 		for (const [module, chunkGroup] of Array.from( | 
					
						
							|  |  |  | 			this.getChunkEntryModulesWithChunkGroupIterable(chunkB) | 
					
						
							|  |  |  | 		)) { | 
					
						
							|  |  |  | 			this.disconnectChunkAndEntryModule(chunkB, module); | 
					
						
							|  |  |  | 			this.connectChunkAndEntryModule(chunkA, module, chunkGroup); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		for (const chunkGroup of chunkB.groupsIterable) { | 
					
						
							|  |  |  | 			chunkGroup.replaceChunk(chunkB, chunkA); | 
					
						
							|  |  |  | 			chunkA.addGroup(chunkGroup); | 
					
						
							|  |  |  | 			chunkB.removeGroup(chunkGroup); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the checked module | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the checked chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk contains the module as entry | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isEntryModuleInChunk(module, chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.entryModules.has(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							|  |  |  | 	 * @param {Module} module the entry module | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 	 * @param {Entrypoint=} entrypoint the chunk group which must be loaded before the module is executed | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 	connectChunkAndEntryModule(chunk, module, entrypoint) { | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		if (cgm.entryInChunks === undefined) { | 
					
						
							|  |  |  | 			cgm.entryInChunks = new Set(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		cgm.entryInChunks.add(chunk); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 		cgc.entryModules.set(module, entrypoint); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	 * @param {RuntimeModule} module the runtime module | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	connectChunkAndRuntimeModule(chunk, module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:28:54 +08:00
										 |  |  | 		if (cgm.runtimeInChunks === undefined) { | 
					
						
							|  |  |  | 			cgm.runtimeInChunks = new Set(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		cgm.runtimeInChunks.add(chunk); | 
					
						
							|  |  |  | 		cgc.runtimeModules.add(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							|  |  |  | 	 * @param {RuntimeModule} module the module that require a full hash | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	addFullHashModuleToChunk(chunk, module) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		if (cgc.fullHashModules === undefined) cgc.fullHashModules = new Set(); | 
					
						
							|  |  |  | 		cgc.fullHashModules.add(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							|  |  |  | 	 * @param {Module} module the entry module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectChunkAndEntryModule(chunk, module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		cgm.entryInChunks.delete(chunk); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		if (cgm.entryInChunks.size === 0) { | 
					
						
							|  |  |  | 			cgm.entryInChunks = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 		cgc.entryModules.delete(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the new chunk | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	 * @param {RuntimeModule} module the runtime module | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectChunkAndRuntimeModule(chunk, module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		cgm.runtimeInChunks.delete(chunk); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:28:54 +08:00
										 |  |  | 		if (cgm.runtimeInChunks.size === 0) { | 
					
						
							|  |  |  | 			cgm.runtimeInChunks = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		cgc.runtimeModules.delete(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the entry module, it will no longer be entry | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectEntryModule(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		for (const chunk of cgm.entryInChunks) { | 
					
						
							|  |  |  | 			const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 			cgc.entryModules.delete(module); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 		cgm.entryInChunks = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk, for which all entries will be removed | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectEntries(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		for (const module of cgc.entryModules.keys()) { | 
					
						
							|  |  |  | 			const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 			cgm.entryInChunks.delete(chunk); | 
					
						
							| 
									
										
										
										
											2019-11-08 19:27:17 +08:00
										 |  |  | 			if (cgm.entryInChunks.size === 0) { | 
					
						
							|  |  |  | 				cgm.entryInChunks = undefined; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		cgc.entryModules.clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {number} the amount of entry modules in chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getNumberOfEntryModules(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.entryModules.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {number} the amount of entry modules in chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getNumberOfRuntimeModules(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.runtimeModules.size; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Iterable<Module>} iterable of modules (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkEntryModulesIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.entryModules.keys(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Iterable<Chunk>} iterable of chunks | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkEntryDependentChunksIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 		/** @type {Set<Chunk>} */ | 
					
						
							| 
									
										
										
										
											2018-12-29 19:48:59 +08:00
										 |  |  | 		const set = new Set(); | 
					
						
							|  |  |  | 		for (const chunkGroup of cgc.entryModules.values()) { | 
					
						
							|  |  |  | 			for (const c of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				if (c !== chunk) { | 
					
						
							|  |  |  | 					set.add(c); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return set; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, when it has dependent chunks | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	hasChunkEntryDependentChunks(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		for (const chunkGroup of cgc.entryModules.values()) { | 
					
						
							|  |  |  | 			for (const c of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				if (c !== chunk) { | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	 * @returns {Iterable<RuntimeModule>} iterable of modules (do not modify) | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkRuntimeModulesIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.runtimeModules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {RuntimeModule[]} array of modules in order of execution | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkRuntimeModulesInOrder(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const array = Array.from(cgc.runtimeModules); | 
					
						
							|  |  |  | 		array.sort( | 
					
						
							|  |  |  | 			concatComparators( | 
					
						
							| 
									
										
										
										
											2019-11-14 23:47:08 +08:00
										 |  |  | 				compareSelect( | 
					
						
							|  |  |  | 					/** | 
					
						
							|  |  |  | 					 * @param {RuntimeModule} r runtime module | 
					
						
							|  |  |  | 					 * @returns {number=} stage | 
					
						
							|  |  |  | 					 */ | 
					
						
							|  |  |  | 					r => r.stage, | 
					
						
							|  |  |  | 					compareIds | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				compareModulesByIdentifier | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return array; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-30 23:52:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkFullHashModulesIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.fullHashModules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {ReadonlySet<RuntimeModule> | undefined} set of modules (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkFullHashModulesSet(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.fullHashModules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 	/** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */ | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @returns {Iterable<EntryModuleWithChunkGroup>} iterable of modules (do not modify) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkEntryModulesWithChunkGroupIterable(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.entryModules; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {AsyncDependenciesBlock} depBlock the async block | 
					
						
							|  |  |  | 	 * @returns {ChunkGroup} the chunk group | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getBlockChunkGroup(depBlock) { | 
					
						
							|  |  |  | 		return this._blockChunkGroups.get(depBlock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {AsyncDependenciesBlock} depBlock the async block | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunk group | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	connectBlockAndChunkGroup(depBlock, chunkGroup) { | 
					
						
							|  |  |  | 		this._blockChunkGroups.set(depBlock, chunkGroup); | 
					
						
							|  |  |  | 		chunkGroup.addBlock(depBlock); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunk group | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	disconnectChunkGroup(chunkGroup) { | 
					
						
							|  |  |  | 		for (const block of chunkGroup.blocksIterable) { | 
					
						
							|  |  |  | 			this._blockChunkGroups.delete(block); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// TODO refactor by moving blocks list into ChunkGraph
 | 
					
						
							|  |  |  | 		chunkGroup._blocks.clear(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {string | number} the id of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleId(module) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		return cgm.id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {string | number} id the id of the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setModuleId(module, id) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		cgm.id = id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 20:52:23 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} runtime runtime | 
					
						
							|  |  |  | 	 * @returns {string | number} the id of the runtime | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getRuntimeId(runtime) { | 
					
						
							|  |  |  | 		return this._runtimeIds.get(runtime); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} runtime runtime | 
					
						
							|  |  |  | 	 * @param {string | number} id the id of the runtime | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	setRuntimeId(runtime, id) { | 
					
						
							|  |  |  | 		this._runtimeIds.set(runtime, id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 	 * @template T | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 	 * @param {RuntimeSpecMap<T>} hashes hashes data | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 	 * @returns {T} hash | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_getModuleHashInfo(module, hashes, runtime) { | 
					
						
							|  |  |  | 		if (!hashes) { | 
					
						
							|  |  |  | 			throw new Error( | 
					
						
							|  |  |  | 				`Module ${module.identifier()} has no hash info for runtime ${runtimeToString( | 
					
						
							|  |  |  | 					runtime | 
					
						
							|  |  |  | 				)} (hashes not set at all)`
 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} else if (runtime === undefined) { | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 			const hashInfoItems = new Set(hashes.values()); | 
					
						
							|  |  |  | 			if (hashInfoItems.size !== 1) { | 
					
						
							|  |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					`No unique hash info entry for unspecified runtime for ${module.identifier()} (existing runtimes: ${Array.from( | 
					
						
							|  |  |  | 						hashes.keys(), | 
					
						
							|  |  |  | 						r => runtimeToString(r) | 
					
						
							|  |  |  | 					).join(", ")}). | 
					
						
							|  |  |  | Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
 | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-02-04 21:21:27 +08:00
										 |  |  | 			return first(hashInfoItems); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 			const hashInfo = hashes.get(runtime); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 			if (!hashInfo) { | 
					
						
							|  |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					`Module ${module.identifier()} has no hash info for runtime ${runtimeToString( | 
					
						
							|  |  |  | 						runtime | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 					)} (available runtimes ${Array.from( | 
					
						
							|  |  |  | 						hashes.keys(), | 
					
						
							|  |  |  | 						runtimeToString | 
					
						
							|  |  |  | 					).join(", ")})`
 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return hashInfo; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the module has hashes for this runtime | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	hasModuleHashes(module, runtime) { | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		const hashes = cgm.hashes; | 
					
						
							|  |  |  | 		return hashes && hashes.has(runtime); | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							|  |  |  | 	 * @returns {string} hash | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getModuleHash(module, runtime) { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const hashes = cgm.hashes; | 
					
						
							|  |  |  | 		return this._getModuleHashInfo(module, hashes, runtime).hash; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							|  |  |  | 	 * @returns {string} hash | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getRenderedModuleHash(module, runtime) { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		const hashes = cgm.hashes; | 
					
						
							|  |  |  | 		return this._getModuleHashInfo(module, hashes, runtime).renderedHash; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	 * @param {string} hash the full hash | 
					
						
							|  |  |  | 	 * @param {string} renderedHash the shortened hash for rendering | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	setModuleHashes(module, runtime, hash, renderedHash) { | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		if (cgm.hashes === undefined) { | 
					
						
							|  |  |  | 			cgm.hashes = new RuntimeSpecMap(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 		cgm.hashes.set(runtime, new ModuleHashInfo(hash, renderedHash)); | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 	 * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph) | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	addModuleRuntimeRequirements(module, runtime, items) { | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		const runtimeRequirementsMap = cgm.runtimeRequirements; | 
					
						
							|  |  |  | 		if (runtimeRequirementsMap === undefined) { | 
					
						
							|  |  |  | 			const map = new RuntimeSpecMap(); | 
					
						
							|  |  |  | 			map.set(runtime, items); | 
					
						
							|  |  |  | 			cgm.runtimeRequirements = map; | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		runtimeRequirementsMap.update(runtime, runtimeRequirements => { | 
					
						
							|  |  |  | 			if (runtimeRequirements === undefined) { | 
					
						
							|  |  |  | 				return items; | 
					
						
							|  |  |  | 			} else if (runtimeRequirements.size >= items.size) { | 
					
						
							|  |  |  | 				for (const item of items) runtimeRequirements.add(item); | 
					
						
							|  |  |  | 				return runtimeRequirements; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				for (const item of runtimeRequirements) items.add(item); | 
					
						
							|  |  |  | 				return items; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 	 * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph) | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	addChunkRuntimeRequirements(chunk, items) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const runtimeRequirements = cgc.runtimeRequirements; | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		if (runtimeRequirements === undefined) { | 
					
						
							|  |  |  | 			cgc.runtimeRequirements = items; | 
					
						
							|  |  |  | 		} else if (runtimeRequirements.size >= items.size) { | 
					
						
							|  |  |  | 			for (const item of items) runtimeRequirements.add(item); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			for (const item of runtimeRequirements) items.add(item); | 
					
						
							|  |  |  | 			cgc.runtimeRequirements = items; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<string>} items runtime requirements to be added | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	addTreeRuntimeRequirements(chunk, items) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		const runtimeRequirements = cgc.runtimeRequirementsInTree; | 
					
						
							|  |  |  | 		for (const item of items) runtimeRequirements.add(item); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	 * @param {RuntimeSpec} runtime the runtime | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 	 * @returns {ReadonlySet<string>} runtime requirements | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 	getModuleRuntimeRequirements(module, runtime) { | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		const runtimeRequirements = | 
					
						
							|  |  |  | 			cgm.runtimeRequirements && cgm.runtimeRequirements.get(runtime); | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		return runtimeRequirements === undefined ? EMPTY_SET : runtimeRequirements; | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 	 * @returns {ReadonlySet<string>} runtime requirements | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkRuntimeRequirements(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		const runtimeRequirements = cgc.runtimeRequirements; | 
					
						
							|  |  |  | 		return runtimeRequirements === undefined ? EMPTY_SET : runtimeRequirements; | 
					
						
							| 
									
										
										
										
											2018-11-17 01:11:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 	getModuleGraphHash(module, runtime, withConnections = true) { | 
					
						
							|  |  |  | 		const cgm = this._getChunkGraphModule(module); | 
					
						
							|  |  |  | 		if (cgm.graphHashes === undefined) { | 
					
						
							|  |  |  | 			cgm.graphHashes = new RuntimeSpecMap(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const graphHash = cgm.graphHashes.provide(runtime, () => { | 
					
						
							|  |  |  | 			const hash = createHash("md4"); | 
					
						
							|  |  |  | 			hash.update(`${cgm.id}`); | 
					
						
							|  |  |  | 			hash.update(`${this.moduleGraph.isAsync(module)}`); | 
					
						
							|  |  |  | 			this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime); | 
					
						
							|  |  |  | 			return /** @type {string} */ (hash.digest("hex")); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		if (!withConnections) return graphHash; | 
					
						
							|  |  |  | 		if (cgm.graphHashesWithConnections === undefined) { | 
					
						
							|  |  |  | 			cgm.graphHashesWithConnections = new RuntimeSpecMap(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const activeStateToString = state => { | 
					
						
							|  |  |  | 			if (state === false) return "false"; | 
					
						
							|  |  |  | 			if (state === true) return "true"; | 
					
						
							|  |  |  | 			if (state === ModuleGraphConnection.TRANSITIVE_ONLY) return "transitive"; | 
					
						
							|  |  |  | 			throw new Error("Not implemented active state"); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		const strict = module.buildMeta && module.buildMeta.strictHarmonyModule; | 
					
						
							|  |  |  | 		return cgm.graphHashesWithConnections.provide(runtime, () => { | 
					
						
							|  |  |  | 			const connections = this.moduleGraph.getOutgoingConnections(module); | 
					
						
							|  |  |  | 			/** @type {Map<string, Module | Set<Module>>} */ | 
					
						
							|  |  |  | 			const connectedModules = new Map(); | 
					
						
							|  |  |  | 			for (const connection of connections) { | 
					
						
							|  |  |  | 				let stateInfo; | 
					
						
							|  |  |  | 				if (typeof runtime === "string") { | 
					
						
							|  |  |  | 					const state = connection.getActiveState(runtime); | 
					
						
							|  |  |  | 					if (state === false) continue; | 
					
						
							|  |  |  | 					stateInfo = activeStateToString(state); | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 					const states = new Set(); | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 					stateInfo = ""; | 
					
						
							|  |  |  | 					forEachRuntime( | 
					
						
							|  |  |  | 						runtime, | 
					
						
							|  |  |  | 						runtime => { | 
					
						
							|  |  |  | 							const state = connection.getActiveState(runtime); | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 							states.add(state); | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 							stateInfo += runtime + activeStateToString(state); | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						true | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 					if (states.size === 1) { | 
					
						
							| 
									
										
										
										
											2021-02-04 21:21:27 +08:00
										 |  |  | 						const state = first(states); | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 						if (state === false) continue; | 
					
						
							|  |  |  | 						stateInfo = activeStateToString(state); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				const module = connection.module; | 
					
						
							|  |  |  | 				stateInfo += module.getExportsType(this.moduleGraph, strict); | 
					
						
							|  |  |  | 				const oldModule = connectedModules.get(stateInfo); | 
					
						
							|  |  |  | 				if (oldModule === undefined) { | 
					
						
							|  |  |  | 					connectedModules.set(stateInfo, module); | 
					
						
							|  |  |  | 				} else if (oldModule instanceof Set) { | 
					
						
							|  |  |  | 					oldModule.add(module); | 
					
						
							|  |  |  | 				} else if (oldModule !== module) { | 
					
						
							|  |  |  | 					connectedModules.set(stateInfo, new Set([oldModule, module])); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 			if (connectedModules.size === 0) return graphHash; | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 			const connectedModulesInOrder = | 
					
						
							|  |  |  | 				connectedModules.size > 1 | 
					
						
							|  |  |  | 					? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1)) | 
					
						
							|  |  |  | 					: connectedModules; | 
					
						
							|  |  |  | 			const hash = createHash("md4"); | 
					
						
							|  |  |  | 			for (const [stateInfo, modules] of connectedModulesInOrder) { | 
					
						
							|  |  |  | 				hash.update(stateInfo); | 
					
						
							|  |  |  | 				if (modules instanceof Set) { | 
					
						
							|  |  |  | 					const xor = new StringXor(); | 
					
						
							|  |  |  | 					for (const m of modules) { | 
					
						
							|  |  |  | 						xor.add(this.getModuleGraphHash(m, runtime, false)); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					xor.updateHash(hash); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					hash.update(this.getModuleGraphHash(modules, runtime, false)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-26 07:48:37 +08:00
										 |  |  | 			hash.update(graphHash); | 
					
						
							| 
									
										
										
										
											2021-01-25 00:14:13 +08:00
										 |  |  | 			return /** @type {string} */ (hash.digest("hex")); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 	 * @returns {ReadonlySet<string>} runtime requirements | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getTreeRuntimeRequirements(chunk) { | 
					
						
							|  |  |  | 		const cgc = this._getChunkGraphChunk(chunk); | 
					
						
							|  |  |  | 		return cgc.runtimeRequirementsInTree; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {string} deprecateMessage message for the deprecation message | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	 * @param {string} deprecationCode code for the deprecation | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	 * @returns {ChunkGraph} the chunk graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	static getChunkGraphForModule(module, deprecateMessage, deprecationCode) { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		const fn = deprecateGetChunkGraphForModuleMap.get(deprecateMessage); | 
					
						
							|  |  |  | 		if (fn) return fn(module); | 
					
						
							|  |  |  | 		const newFn = util.deprecate( | 
					
						
							|  |  |  | 			/** | 
					
						
							|  |  |  | 			 * @param {Module} module the module | 
					
						
							|  |  |  | 			 * @returns {ChunkGraph} the chunk graph | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			module => { | 
					
						
							|  |  |  | 				const chunkGraph = chunkGraphForModuleMap.get(module); | 
					
						
							|  |  |  | 				if (!chunkGraph) | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						deprecateMessage + | 
					
						
							|  |  |  | 							": There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				return chunkGraph; | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-14 22:01:25 +08:00
										 |  |  | 			deprecateMessage + ": Use new ChunkGraph API", | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			deprecationCode | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		deprecateGetChunkGraphForModuleMap.set(deprecateMessage, newFn); | 
					
						
							|  |  |  | 		return newFn(module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static setChunkGraphForModule(module, chunkGraph) { | 
					
						
							|  |  |  | 		chunkGraphForModuleMap.set(module, chunkGraph); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {string} deprecateMessage message for the deprecation message | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	 * @param {string} deprecationCode code for the deprecation | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	 * @returns {ChunkGraph} the chunk graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 	static getChunkGraphForChunk(chunk, deprecateMessage, deprecationCode) { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		const fn = deprecateGetChunkGraphForChunkMap.get(deprecateMessage); | 
					
						
							|  |  |  | 		if (fn) return fn(chunk); | 
					
						
							|  |  |  | 		const newFn = util.deprecate( | 
					
						
							|  |  |  | 			/** | 
					
						
							|  |  |  | 			 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 			 * @returns {ChunkGraph} the chunk graph | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			chunk => { | 
					
						
							|  |  |  | 				const chunkGraph = chunkGraphForChunkMap.get(chunk); | 
					
						
							|  |  |  | 				if (!chunkGraph) | 
					
						
							|  |  |  | 					throw new Error( | 
					
						
							|  |  |  | 						deprecateMessage + | 
					
						
							|  |  |  | 							"There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				return chunkGraph; | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-14 22:01:25 +08:00
										 |  |  | 			deprecateMessage + ": Use new ChunkGraph API", | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			deprecationCode | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		deprecateGetChunkGraphForChunkMap.set(deprecateMessage, newFn); | 
					
						
							|  |  |  | 		return newFn(chunk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static setChunkGraphForChunk(chunk, chunkGraph) { | 
					
						
							|  |  |  | 		chunkGraphForChunkMap.set(chunk, chunkGraph); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {WeakMap<Module, ChunkGraph>} */ | 
					
						
							|  |  |  | const chunkGraphForModuleMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {WeakMap<Chunk, ChunkGraph>} */ | 
					
						
							|  |  |  | const chunkGraphForChunkMap = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {Map<string, (module: Module) => ChunkGraph>} */ | 
					
						
							|  |  |  | const deprecateGetChunkGraphForModuleMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO remove in webpack 6
 | 
					
						
							|  |  |  | /** @type {Map<string, (chunk: Chunk) => ChunkGraph>} */ | 
					
						
							|  |  |  | const deprecateGetChunkGraphForChunkMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | module.exports = ChunkGraph; |