| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | const ChunkGraph = require("./ChunkGraph"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const Entrypoint = require("./Entrypoint"); | 
					
						
							|  |  |  | const { intersect } = require("./util/SetHelpers"); | 
					
						
							|  |  |  | const SortableSet = require("./util/SortableSet"); | 
					
						
							| 
									
										
										
										
											2018-11-30 20:19:55 +08:00
										 |  |  | const { compareModulesByIdOrIdentifier } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2019-07-25 21:41:00 +08:00
										 |  |  | const { createArrayToSetDeprecationSet } = require("./util/deprecation"); | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph").ChunkFilterPredicate} ChunkFilterPredicate */ | 
					
						
							|  |  |  | /** @typedef {import("./ChunkGraph").ChunkModuleMaps} ChunkModuleMaps */ | 
					
						
							|  |  |  | /** @typedef {import("./ChunkGraph").ChunkSizeOptions} ChunkSizeOptions */ | 
					
						
							|  |  |  | /** @typedef {import("./ChunkGraph").ModuleFilterPredicate} ModuleFilterPredicate */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup")} ChunkGroup */ | 
					
						
							| 
									
										
										
										
											2018-08-16 22:11:20 +08:00
										 |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2019-09-13 17:12:26 +08:00
										 |  |  | /** @typedef {import("./Compilation").AssetInfo} AssetInfo */ | 
					
						
							| 
									
										
										
										
											2019-06-19 04:09:10 +08:00
										 |  |  | /** @typedef {import("./Compilation").PathData} PathData */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-08-16 22:11:20 +08:00
										 |  |  | /** @typedef {import("./ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2019-07-17 22:02:33 +08:00
										 |  |  | /** @typedef {import("./util/Hash")} Hash */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 21:41:00 +08:00
										 |  |  | const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  |  *  @typedef {Object} WithId an object who has an id property * | 
					
						
							| 
									
										
										
										
											2018-06-06 12:11:24 +08:00
										 |  |  |  *  @property {string | number} id the id of the object | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  |  * Compare two Modules based on their ids for sorting | 
					
						
							|  |  |  |  * @param {Module} a module | 
					
						
							|  |  |  |  * @param {Module} b module | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  * @returns {-1|0|1} sort value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | let debugId = 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Compare two ChunkGroups based on their ids for sorting | 
					
						
							|  |  |  |  * @param {ChunkGroup} a chunk group | 
					
						
							|  |  |  |  * @param {ChunkGroup} b chunk group | 
					
						
							|  |  |  |  * @returns {-1|0|1} sort value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const sortChunkGroupById = (a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if (b.id < a.id) return 1; | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * A Chunk is a unit of encapsulation for Modules. | 
					
						
							|  |  |  |  * Chunks are "rendered" into bundles that get emitted when the build completes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-06-19 20:13:44 +08:00
										 |  |  | class Chunk { | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string=} name of chunk being created, is optional (for subclasses) | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	constructor(name) { | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 		/** @type {number | string | null} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.id = null; | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 		/** @type {(number|string)[] | null} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.ids = null; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {number} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.debugId = debugId++; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.name = name; | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 		/** @type {SortableSet<string>} */ | 
					
						
							|  |  |  | 		this.idNameHints = new SortableSet(); | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2018-04-26 01:45:53 +08:00
										 |  |  | 		this.preventIntegration = false; | 
					
						
							| 
									
										
										
										
											2019-09-13 17:12:26 +08:00
										 |  |  | 		/** @type {(string | function(PathData, AssetInfo=): string)?} */ | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | 		this.filenameTemplate = undefined; | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  | 		/** @private @type {SortableSet<ChunkGroup>} */ | 
					
						
							| 
									
										
										
										
											2018-06-20 18:04:47 +08:00
										 |  |  | 		this._groups = new SortableSet(undefined, sortChunkGroupById); | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 		/** @type {Set<string>} */ | 
					
						
							| 
									
										
										
										
											2019-07-25 21:41:00 +08:00
										 |  |  | 		this.files = new ChunkFilesSet(); | 
					
						
							| 
									
										
										
										
											2019-07-17 23:30:25 +08:00
										 |  |  | 		/** @type {Set<string>} */ | 
					
						
							|  |  |  | 		this.auxiliaryFiles = new Set(); | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.rendered = false; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.hash = undefined; | 
					
						
							| 
									
										
										
										
											2018-08-23 01:23:48 +08:00
										 |  |  | 		/** @type {Record<string, string>} */ | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 		this.contentHash = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.renderedHash = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {string=} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.chunkReason = undefined; | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 		/** @type {boolean} */ | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 		this.extraAsync = false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 	// BACKWARD-COMPAT START
 | 
					
						
							|  |  |  | 	get entryModule() { | 
					
						
							|  |  |  | 		const entryModules = Array.from( | 
					
						
							|  |  |  | 			ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 				this, | 
					
						
							|  |  |  | 				"Chunk.entryModule" | 
					
						
							|  |  |  | 			).getChunkEntryModulesIterable(this) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		if (entryModules.length === 0) { | 
					
						
							|  |  |  | 			return undefined; | 
					
						
							|  |  |  | 		} else if (entryModules.length === 1) { | 
					
						
							|  |  |  | 			return entryModules[0]; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			throw new Error( | 
					
						
							|  |  |  | 				"Module.entryModule: Multiple entry modules are not supported by the deprecated API (Use the new ChunkGroup API)" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk contains an entry module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	hasEntryModule() { | 
					
						
							|  |  |  | 		return ( | 
					
						
							|  |  |  | 			ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 				this, | 
					
						
							|  |  |  | 				"Chunk.hasEntryModule" | 
					
						
							|  |  |  | 			).getNumberOfEntryModules(this) > 0 | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk could be added | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	addModule(module) { | 
					
						
							|  |  |  | 		return ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.addModule" | 
					
						
							|  |  |  | 		).connectChunkAndModule(this, module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	removeModule(module) { | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 		ChunkGraph.getChunkGraphForChunk( | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.removeModule" | 
					
						
							|  |  |  | 		).disconnectChunkAndModule(this, module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the number of module which are contained in this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	getNumberOfModules() { | 
					
						
							|  |  |  | 		return ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.getNumberOfModules" | 
					
						
							|  |  |  | 		).getNumberOfChunkModules(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get modulesIterable() { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.modulesIterable" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 			this, | 
					
						
							| 
									
										
										
										
											2018-11-30 20:19:55 +08:00
										 |  |  | 			compareModulesByIdOrIdentifier(chunkGraph) | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the chunk to compare with | 
					
						
							|  |  |  | 	 * @returns {-1|0|1} the comparison result | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	compareTo(otherChunk) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.compareTo" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-22 17:49:27 +08:00
										 |  |  | 		return chunkGraph.compareChunks(this, otherChunk); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk contains the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	containsModule(module) { | 
					
						
							|  |  |  | 		return ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.containsModule" | 
					
						
							|  |  |  | 		).isModuleInChunk(module, this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Module[]} the modules for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	getModules() { | 
					
						
							|  |  |  | 		return ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.getModules" | 
					
						
							|  |  |  | 		).getChunkModules(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	remove() { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.remove"); | 
					
						
							|  |  |  | 		chunkGraph.disconnectChunk(this); | 
					
						
							|  |  |  | 		this.disconnectFromGroups(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module the module | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the target chunk | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	moveModule(module, otherChunk) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.moveModule" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		chunkGraph.disconnectChunkAndModule(this, module); | 
					
						
							|  |  |  | 		chunkGraph.connectChunkAndModule(otherChunk, module); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the other chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the specified chunk has been integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	integrate(otherChunk) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.integrate" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 		if (chunkGraph.canChunksBeIntegrated(this, otherChunk)) { | 
					
						
							|  |  |  | 			chunkGraph.integrateChunks(this, otherChunk); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the other chunk | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if chunks could be integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	canBeIntegrated(otherChunk) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.canBeIntegrated" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.canChunksBeIntegrated(this, otherChunk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if this chunk contains no module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	isEmpty() { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.isEmpty"); | 
					
						
							|  |  |  | 		return chunkGraph.getNumberOfChunkModules(this) === 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} total size of all modules in this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	modulesSize() { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.modulesSize" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.getChunkModulesSize(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkSizeOptions} options options object | 
					
						
							|  |  |  | 	 * @returns {number} total size of this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-10 03:34:28 +08:00
										 |  |  | 	size(options = {}) { | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.size"); | 
					
						
							|  |  |  | 		return chunkGraph.getChunkSize(this, options); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} otherChunk the other chunk | 
					
						
							|  |  |  | 	 * @param {ChunkSizeOptions} options options object | 
					
						
							|  |  |  | 	 * @returns {number} total size of the chunk or false if the chunk can't be integrated | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	integratedSize(otherChunk, options) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.integratedSize" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.getIntegratedChunksSize(this, otherChunk, options); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ModuleFilterPredicate} filterFn function used to filter modules | 
					
						
							|  |  |  | 	 * @returns {ChunkModuleMaps} module map information | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	getChunkModuleMaps(filterFn) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.getChunkModuleMaps" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-22 17:49:27 +08:00
										 |  |  | 		return chunkGraph.getChunkModuleMaps(this, filterFn); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 	 * @returns {boolean} return true if module exists in graph | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	hasModuleInGraph(filterFn, filterChunkFn) { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.hasModuleInGraph" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.hasModuleInGraph(this, filterFn, filterChunkFn); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// BACKWARD-COMPAT END
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether or not the Chunk will have a runtime | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	hasRuntime() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 			if ( | 
					
						
							| 
									
										
										
										
											2018-07-05 13:07:46 +08:00
										 |  |  | 				chunkGroup.isInitial() && | 
					
						
							| 
									
										
										
										
											2018-07-13 09:00:44 +08:00
										 |  |  | 				chunkGroup instanceof Entrypoint && | 
					
						
							|  |  |  | 				chunkGroup.getRuntimeChunk() === this | 
					
						
							| 
									
										
										
										
											2018-10-17 23:14:50 +08:00
										 |  |  | 			) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether or not this chunk can be an initial chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	canBeInitial() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							|  |  |  | 			if (chunkGroup.isInitial()) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} whether this chunk can only be an initial chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	isOnlyInitial() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._groups.size <= 0) return false; | 
					
						
							|  |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							|  |  |  | 			if (!chunkGroup.isInitial()) return false; | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	addGroup(chunkGroup) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this._groups.has(chunkGroup)) return false; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._groups.add(chunkGroup); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk does exist in chunkGroup and is removed | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	removeGroup(chunkGroup) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!this._groups.has(chunkGroup)) return false; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		this._groups.delete(chunkGroup); | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup to check | 
					
						
							|  |  |  | 	 * @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	isInGroup(chunkGroup) { | 
					
						
							|  |  |  | 		return this._groups.has(chunkGroup); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {number} the amount of groups said chunk is in | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	getNumberOfGroups() { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:47:08 +08:00
										 |  |  | 		return this._groups.size; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	 * @returns {Iterable<ChunkGroup>} the chunkGroups that said chunk is referenced in | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get groupsIterable() { | 
					
						
							|  |  |  | 		return this._groups; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-05-11 19:16:27 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	disconnectFromGroups() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.removeChunk(this); | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} newChunk the new chunk that will be split out of, and then chunk raphi twil= | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 	split(newChunk) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			chunkGroup.insertChunk(newChunk, this); | 
					
						
							|  |  |  | 			newChunk.addGroup(chunkGroup); | 
					
						
							| 
									
										
										
										
											2017-09-22 22:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-12-07 19:26:35 +08:00
										 |  |  | 		for (const idHint of this.idNameHints) { | 
					
						
							|  |  |  | 			newChunk.idNameHints.add(idHint); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-25 00:53:32 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Hash} hash hash (will be modified) | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 	updateHash(hash, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		hash.update(`${this.id} `); | 
					
						
							|  |  |  | 		hash.update(this.ids ? this.ids.join(",") : ""); | 
					
						
							|  |  |  | 		hash.update(`${this.name || ""} `); | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		for (const m of chunkGraph.getOrderedChunkModulesIterable( | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 			this, | 
					
						
							| 
									
										
										
										
											2018-11-30 20:19:55 +08:00
										 |  |  | 			compareModulesByIdOrIdentifier(chunkGraph) | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 		)) { | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 			hash.update(chunkGraph.getModuleHash(m)); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 		const entryModules = chunkGraph.getChunkEntryModulesWithChunkGroupIterable( | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			this | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		for (const [m, chunkGroup] of entryModules) { | 
					
						
							|  |  |  | 			hash.update("entry"); | 
					
						
							| 
									
										
										
										
											2018-08-23 23:07:23 +08:00
										 |  |  | 			hash.update(chunkGraph.getModuleHash(m)); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			hash.update(chunkGroup.id); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<Chunk>} a set of all the async chunks | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 	getAllAsyncChunks() { | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:15 +08:00
										 |  |  | 		const queue = new Set(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const chunks = new Set(); | 
					
						
							| 
									
										
										
										
											2017-12-01 16:46:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 16:37:15 +08:00
										 |  |  | 		const initialChunks = intersect( | 
					
						
							|  |  |  | 			Array.from(this.groupsIterable, g => new Set(g.chunks)) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of this.groupsIterable) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (!initialChunks.has(chunk)) { | 
					
						
							|  |  |  | 					chunks.add(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 19:15:58 +08:00
										 |  |  | 		return chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 17:03:07 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<Chunk>} a set of all the referenced chunks (including itself) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getAllReferencedChunks() { | 
					
						
							|  |  |  | 		const queue = new Set(this.groupsIterable); | 
					
						
							|  |  |  | 		const chunks = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				chunks.add(chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return chunks; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 18:32:10 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the chunk references async chunks | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	hasAsyncChunks() { | 
					
						
							|  |  |  | 		const queue = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const initialChunks = intersect( | 
					
						
							|  |  |  | 			Array.from(this.groupsIterable, g => new Set(g.chunks)) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of this.groupsIterable) { | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 				if (!initialChunks.has(chunk)) { | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	 * @param {ChunkFilterPredicate=} filterFn function used to filter chunks | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	 * @returns {Record<string, (string | number)[]>} a record object of names to lists of child ids(?) | 
					
						
							| 
									
										
										
										
											2018-05-04 00:57:02 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	getChildIdsByOrders(chunkGraph, filterFn) { | 
					
						
							| 
									
										
										
										
											2018-12-18 04:35:39 +08:00
										 |  |  | 		/** @type {Map<string, {order: number, group: ChunkGroup}[]>} */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const lists = new Map(); | 
					
						
							|  |  |  | 		for (const group of this.groupsIterable) { | 
					
						
							|  |  |  | 			if (group.chunks[group.chunks.length - 1] === this) { | 
					
						
							|  |  |  | 				for (const childGroup of group.childrenIterable) { | 
					
						
							| 
									
										
										
										
											2018-06-27 17:40:24 +08:00
										 |  |  | 					for (const key of Object.keys(childGroup.options)) { | 
					
						
							|  |  |  | 						if (key.endsWith("Order")) { | 
					
						
							|  |  |  | 							const name = key.substr(0, key.length - "Order".length); | 
					
						
							|  |  |  | 							let list = lists.get(name); | 
					
						
							| 
									
										
										
										
											2018-12-18 04:35:39 +08:00
										 |  |  | 							if (list === undefined) { | 
					
						
							|  |  |  | 								list = []; | 
					
						
							|  |  |  | 								lists.set(name, list); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-06-27 17:40:24 +08:00
										 |  |  | 							list.push({ | 
					
						
							|  |  |  | 								order: childGroup.options[key], | 
					
						
							|  |  |  | 								group: childGroup | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		/** @type {Record<string, (string | number)[]>} */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const result = Object.create(null); | 
					
						
							|  |  |  | 		for (const [name, list] of lists) { | 
					
						
							|  |  |  | 			list.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 				const cmp = b.order - a.order; | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				if (cmp !== 0) return cmp; | 
					
						
							| 
									
										
										
										
											2018-08-22 17:49:27 +08:00
										 |  |  | 				return a.group.compareTo(chunkGraph, b.group); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			/** @type {Set<string | number>} */ | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			const chunkIdSet = list.reduce((set, item) => { | 
					
						
							|  |  |  | 				for (const chunk of item.group.chunks) { | 
					
						
							|  |  |  | 					if (filterFn && !filterFn(chunk, chunkGraph)) continue; | 
					
						
							|  |  |  | 					set.add(chunk.id); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return set; | 
					
						
							|  |  |  | 			}, new Set()); | 
					
						
							|  |  |  | 			if (chunkIdSet.size > 0) { | 
					
						
							|  |  |  | 				result[name] = Array.from(chunkIdSet); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 22:11:20 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @param {boolean=} includeDirectChildren include direct children (by default only children of async children are included) | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	 * @param {ChunkFilterPredicate=} filterFn function used to filter chunks | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	 * @returns {Record<string|number, Record<string, (string | number)[]>>} a record object of names to lists of child ids(?) by chunk id | 
					
						
							| 
									
										
										
										
											2018-08-16 22:11:20 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 	getChildIdsByOrdersMap(chunkGraph, includeDirectChildren, filterFn) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		/** @type {Record<string|number, Record<string, (string | number)[]>>} */ | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const chunkMaps = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Chunk} chunk a chunk | 
					
						
							|  |  |  | 		 * @returns {void} | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 		const addChildIdsByOrdersToMap = chunk => { | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			const data = chunk.getChildIdsByOrders(chunkGraph, filterFn); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			for (const key of Object.keys(data)) { | 
					
						
							|  |  |  | 				let chunkMap = chunkMaps[key]; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				if (chunkMap === undefined) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					chunkMaps[key] = chunkMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				chunkMap[chunk.id] = data[key]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (includeDirectChildren) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			/** @type {Set<Chunk>} */ | 
					
						
							| 
									
										
										
										
											2019-05-11 05:04:29 +08:00
										 |  |  | 			const chunks = new Set(); | 
					
						
							|  |  |  | 			for (const chunkGroup of this.groupsIterable) { | 
					
						
							|  |  |  | 				for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 					chunks.add(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const chunk of chunks) { | 
					
						
							|  |  |  | 				addChildIdsByOrdersToMap(chunk); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunk of this.getAllAsyncChunks()) { | 
					
						
							|  |  |  | 			addChildIdsByOrdersToMap(chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		return chunkMaps; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | module.exports = Chunk; |