| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2020-08-14 12:37:25 +08:00
										 |  |  | const StringXor = require("./util/StringXor"); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2019-10-16 22:38:04 +08:00
										 |  |  | 	compareModulesByIdentifier, | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | 	compareChunkGroupsByIndex, | 
					
						
							|  |  |  | 	compareModulesById | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2019-07-25 21:41:00 +08:00
										 |  |  | const { createArrayToSetDeprecationSet } = require("./util/deprecation"); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | const { mergeRuntime } = require("./util/runtime"); | 
					
						
							| 
									
										
										
										
											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").ChunkSizeOptions} ChunkSizeOptions */ | 
					
						
							|  |  |  | /** @typedef {import("./ChunkGraph").ModuleFilterPredicate} ModuleFilterPredicate */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup")} ChunkGroup */ | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */ | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | /** @typedef {number | string} ChunkId */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 21:41:00 +08:00
										 |  |  | const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-03 20:37:18 +08:00
										 |  |  |  * @typedef {Object} WithId an object who has an id property * | 
					
						
							|  |  |  |  * @property {string | number} id the id of the object | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @deprecated | 
					
						
							|  |  |  |  * @typedef {Object} ChunkMaps | 
					
						
							|  |  |  |  * @property {Record<string|number, string>} hash | 
					
						
							|  |  |  |  * @property {Record<string|number, Record<string, string>>} contentHash | 
					
						
							|  |  |  |  * @property {Record<string|number, string>} name | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @deprecated | 
					
						
							|  |  |  |  * @typedef {Object} ChunkModuleMaps | 
					
						
							|  |  |  |  * @property {Record<string|number, (string|number)[]>} id | 
					
						
							|  |  |  |  * @property {Record<string|number, string>} hash | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | let debugId = 1000; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 	 * @param {boolean} backCompat enable backward-compatibility | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 	constructor(name, backCompat = true) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 		/** @type {ChunkId | null} */ | 
					
						
							| 
									
										
										
										
											2017-01-05 00:17:49 +08:00
										 |  |  | 		this.id = null; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 		/** @type {ChunkId[] | 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++; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 		/** @type {string | undefined} */ | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 		/** @type {(string | function(PathData, AssetInfo=): string) | undefined} */ | 
					
						
							| 
									
										
										
										
											2018-07-04 15:59:22 +08:00
										 |  |  | 		this.filenameTemplate = undefined; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 		/** @type {(string | function(PathData, AssetInfo=): string) | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		this.cssFilenameTemplate = undefined; | 
					
						
							| 
									
										
										
										
											2018-06-20 06:32:15 +08:00
										 |  |  | 		/** @private @type {SortableSet<ChunkGroup>} */ | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 		this._groups = new SortableSet(undefined, compareChunkGroupsByIndex); | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		/** @type {RuntimeSpec} */ | 
					
						
							|  |  |  | 		this.runtime = undefined; | 
					
						
							| 
									
										
										
										
											2019-06-14 16:45:56 +08:00
										 |  |  | 		/** @type {Set<string>} */ | 
					
						
							| 
									
										
										
										
											2021-11-05 16:53:32 +08:00
										 |  |  | 		this.files = backCompat ? new ChunkFilesSet() : new Set(); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 				"Chunk.entryModule", | 
					
						
							|  |  |  | 				"DEP_WEBPACK_CHUNK_ENTRY_MODULE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 			).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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 				"Chunk.hasEntryModule", | 
					
						
							|  |  |  | 				"DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 			).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) { | 
					
						
							| 
									
										
										
										
											2019-11-08 20:21:21 +08:00
										 |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 			this, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.addModule", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_ADD_MODULE" | 
					
						
							| 
									
										
										
										
											2019-11-08 20:21:21 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		if (chunkGraph.isModuleInChunk(module, this)) return false; | 
					
						
							|  |  |  | 		chunkGraph.connectChunkAndModule(this, module); | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.removeModule", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_REMOVE_MODULE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		).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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.getNumberOfModules", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_GET_NUMBER_OF_MODULES" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		).getNumberOfChunkModules(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get modulesIterable() { | 
					
						
							|  |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.modulesIterable", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_MODULES_ITERABLE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 			this, | 
					
						
							| 
									
										
										
										
											2019-10-16 22:38:04 +08:00
										 |  |  | 			compareModulesByIdentifier | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.compareTo", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_COMPARE_TO" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.containsModule", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_CONTAINS_MODULE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		).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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.getModules", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_GET_MODULES" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		).getChunkModules(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 17:49:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	remove() { | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.remove", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_REMOVE" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.moveModule", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_MOVE_MODULE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.integrate", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_INTEGRATE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.canBeIntegrated", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_CAN_BE_INTEGRATED" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		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() { | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.isEmpty", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_IS_EMPTY" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.modulesSize", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_MODULES_SIZE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		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 = {}) { | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 		const chunkGraph = ChunkGraph.getChunkGraphForChunk( | 
					
						
							|  |  |  | 			this, | 
					
						
							|  |  |  | 			"Chunk.size", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_SIZE" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.integratedSize", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_INTEGRATED_SIZE" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.getChunkModuleMaps", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_GET_CHUNK_MODULE_MAPS" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | 		/** @type {Record<string|number, (string|number)[]>} */ | 
					
						
							|  |  |  | 		const chunkModuleIdMap = Object.create(null); | 
					
						
							|  |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							|  |  |  | 		const chunkModuleHashMap = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const asyncChunk of this.getAllAsyncChunks()) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 			/** @type {ChunkId[] | undefined} */ | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | 			let array; | 
					
						
							|  |  |  | 			for (const module of chunkGraph.getOrderedChunkModulesIterable( | 
					
						
							|  |  |  | 				asyncChunk, | 
					
						
							|  |  |  | 				compareModulesById(chunkGraph) | 
					
						
							|  |  |  | 			)) { | 
					
						
							|  |  |  | 				if (filterFn(module)) { | 
					
						
							|  |  |  | 					if (array === undefined) { | 
					
						
							|  |  |  | 						array = []; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 						chunkModuleIdMap[/** @type {ChunkId} */ (asyncChunk.id)] = array; | 
					
						
							| 
									
										
										
										
											2020-07-29 17:14:26 +08:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					const moduleId = chunkGraph.getModuleId(module); | 
					
						
							|  |  |  | 					array.push(moduleId); | 
					
						
							|  |  |  | 					chunkModuleHashMap[moduleId] = chunkGraph.getRenderedModuleHash( | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						undefined | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			id: chunkModuleIdMap, | 
					
						
							|  |  |  | 			hash: chunkModuleHashMap | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-15 17:07:41 +08:00
										 |  |  | 			"Chunk.hasModuleInGraph", | 
					
						
							|  |  |  | 			"DEP_WEBPACK_CHUNK_HAS_MODULE_IN_GRAPH" | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		return chunkGraph.hasModuleInGraph(this, filterFn, filterChunkFn); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @deprecated | 
					
						
							| 
									
										
										
										
											2020-01-21 23:06:36 +08:00
										 |  |  | 	 * @param {boolean} realHash whether the full hash or the rendered hash is to be used | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	 * @returns {ChunkMaps} the chunk map information | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getChunkMaps(realHash) { | 
					
						
							|  |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							|  |  |  | 		const chunkHashMap = Object.create(null); | 
					
						
							|  |  |  | 		/** @type {Record<string|number, Record<string, string>>} */ | 
					
						
							|  |  |  | 		const chunkContentHashMap = Object.create(null); | 
					
						
							|  |  |  | 		/** @type {Record<string|number, string>} */ | 
					
						
							|  |  |  | 		const chunkNameMap = Object.create(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunk of this.getAllAsyncChunks()) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 			const id = /** @type {ChunkId} */ (chunk.id); | 
					
						
							|  |  |  | 			chunkHashMap[id] = | 
					
						
							|  |  |  | 				/** @type {string} */ | 
					
						
							|  |  |  | 				(realHash ? chunk.hash : chunk.renderedHash); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			for (const key of Object.keys(chunk.contentHash)) { | 
					
						
							|  |  |  | 				if (!chunkContentHashMap[key]) { | 
					
						
							|  |  |  | 					chunkContentHashMap[key] = Object.create(null); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				chunkContentHashMap[key][id] = chunk.contentHash[key]; | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (chunk.name) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				chunkNameMap[id] = chunk.name; | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			hash: chunkHashMap, | 
					
						
							|  |  |  | 			contentHash: chunkContentHashMap, | 
					
						
							|  |  |  | 			name: chunkNameMap | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 22:15:48 +08:00
										 |  |  | 	// 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-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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {EntryOptions | undefined} the entry options for this chunk | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getEntryOptions() { | 
					
						
							|  |  |  | 		for (const chunkGroup of this._groups) { | 
					
						
							|  |  |  | 			if (chunkGroup instanceof Entrypoint) { | 
					
						
							|  |  |  | 				return chunkGroup.options; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return undefined; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added | 
					
						
							| 
									
										
										
										
											2020-02-04 00:57:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	addGroup(chunkGroup) { | 
					
						
							|  |  |  | 		this._groups.add(chunkGroup); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from | 
					
						
							| 
									
										
										
										
											2020-02-04 00:57:51 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	removeGroup(chunkGroup) { | 
					
						
							|  |  |  | 		this._groups.delete(chunkGroup); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-01-21 23:02:15 +08:00
										 |  |  | 	 * @returns {number} the amount of groups that the said chunk is in | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-05-16 13:01:58 +08:00
										 |  |  | 	 * @returns {SortableSet<ChunkGroup>} the chunkGroups that the said chunk is referenced in | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 	get groupsIterable() { | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 		this._groups.sort(); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		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
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-01-21 23:04:37 +08:00
										 |  |  | 	 * @param {Chunk} newChunk the new chunk that will be split out of | 
					
						
							| 
									
										
										
										
											2018-04-13 04:29:42 +08:00
										 |  |  | 	 * @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); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-07-28 00:09:48 +08:00
										 |  |  | 		newChunk.runtime = mergeRuntime(newChunk.runtime, this.runtime); | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2021-09-26 08:15:41 +08:00
										 |  |  | 		hash.update( | 
					
						
							| 
									
										
										
										
											2021-10-04 15:29:09 +08:00
										 |  |  | 			`${this.id} ${this.ids ? this.ids.join() : ""} ${this.name || ""} ` | 
					
						
							| 
									
										
										
										
											2021-09-26 08:15:41 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-08-14 12:37:25 +08:00
										 |  |  | 		const xor = new StringXor(); | 
					
						
							|  |  |  | 		for (const m of chunkGraph.getChunkModulesIterable(this)) { | 
					
						
							|  |  |  | 			xor.add(chunkGraph.getModuleHash(m, this.runtime)); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-08-14 12:37:25 +08:00
										 |  |  | 		xor.updateHash(hash); | 
					
						
							| 
									
										
										
										
											2021-05-11 15:31:46 +08:00
										 |  |  | 		const entryModules = | 
					
						
							|  |  |  | 			chunkGraph.getChunkEntryModulesWithChunkGroupIterable(this); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 		for (const [m, chunkGroup] of entryModules) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 			hash.update( | 
					
						
							|  |  |  | 				`entry${chunkGraph.getModuleId(m)}${ | 
					
						
							|  |  |  | 					/** @type {ChunkGroup} */ (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)) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-10 21:49:08 +08:00
										 |  |  | 		const initialQueue = new Set(this.groupsIterable); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of initialQueue) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							| 
									
										
										
										
											2021-05-10 21:49:08 +08:00
										 |  |  | 				if (child instanceof Entrypoint) { | 
					
						
							|  |  |  | 					initialQueue.add(child); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					queue.add(child); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 05:14:19 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<Chunk>} a set of all the initial chunks (including itself) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getAllInitialChunks() { | 
					
						
							| 
									
										
										
										
											2021-03-15 02:54:34 +08:00
										 |  |  | 		const chunks = new Set(); | 
					
						
							| 
									
										
										
										
											2021-06-09 03:34:50 +08:00
										 |  |  | 		const queue = new Set(this.groupsIterable); | 
					
						
							|  |  |  | 		for (const group of queue) { | 
					
						
							|  |  |  | 			if (group.isInitial()) { | 
					
						
							|  |  |  | 				for (const c of group.chunks) chunks.add(c); | 
					
						
							|  |  |  | 				for (const g of group.childrenIterable) queue.add(g); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-03-15 02:54:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return chunks; | 
					
						
							| 
									
										
										
										
											2020-05-26 05:14:19 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 00:02:14 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {Set<Entrypoint>} a set of all the referenced entrypoints | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getAllReferencedAsyncEntrypoints() { | 
					
						
							|  |  |  | 		const queue = new Set(this.groupsIterable); | 
					
						
							|  |  |  | 		const entrypoints = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 			for (const entrypoint of chunkGroup.asyncEntrypointsIterable) { | 
					
						
							|  |  |  | 				entrypoints.add(entrypoint); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (const child of chunkGroup.childrenIterable) { | 
					
						
							|  |  |  | 				queue.add(child); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return entrypoints; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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")) { | 
					
						
							| 
									
										
										
										
											2022-03-14 05:54:18 +08:00
										 |  |  | 							const name = key.slice(0, key.length - "Order".length); | 
					
						
							| 
									
										
										
										
											2018-06-27 17:40:24 +08:00
										 |  |  | 							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({ | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 								order: | 
					
						
							|  |  |  | 									/** @type {number} */ | 
					
						
							|  |  |  | 									( | 
					
						
							|  |  |  | 										childGroup.options[ | 
					
						
							|  |  |  | 											/** @type {keyof ChunkGroupOptions} */ (key) | 
					
						
							|  |  |  | 										] | 
					
						
							|  |  |  | 									), | 
					
						
							| 
									
										
										
										
											2018-06-27 17:40:24 +08:00
										 |  |  | 								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>} */ | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			const chunkIdSet = new Set(); | 
					
						
							|  |  |  | 			for (const item of list) { | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 				for (const chunk of item.group.chunks) { | 
					
						
							|  |  |  | 					if (filterFn && !filterFn(chunk, chunkGraph)) continue; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 					chunkIdSet.add(/** @type {ChunkId} */ (chunk.id)); | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 			if (chunkIdSet.size > 0) { | 
					
						
							|  |  |  | 				result[name] = Array.from(chunkIdSet); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @param {string} type option name | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 	 * @returns {{ onChunks: Chunk[], chunks: Set<Chunk> }[] | undefined} referenced chunks for a specific type | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getChildrenOfTypeInOrder(chunkGraph, type) { | 
					
						
							|  |  |  | 		const list = []; | 
					
						
							|  |  |  | 		for (const group of this.groupsIterable) { | 
					
						
							|  |  |  | 			for (const childGroup of group.childrenIterable) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				const order = | 
					
						
							|  |  |  | 					childGroup.options[/** @type {keyof ChunkGroupOptions} */ (type)]; | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 				if (order === undefined) continue; | 
					
						
							|  |  |  | 				list.push({ | 
					
						
							|  |  |  | 					order, | 
					
						
							|  |  |  | 					group, | 
					
						
							|  |  |  | 					childGroup | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (list.length === 0) return undefined; | 
					
						
							|  |  |  | 		list.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 			const cmp = | 
					
						
							|  |  |  | 				/** @type {number} */ (b.order) - /** @type {number} */ (a.order); | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 			if (cmp !== 0) return cmp; | 
					
						
							|  |  |  | 			return a.group.compareTo(chunkGraph, b.group); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		const result = []; | 
					
						
							|  |  |  | 		let lastEntry; | 
					
						
							|  |  |  | 		for (const { group, childGroup } of list) { | 
					
						
							|  |  |  | 			if (lastEntry && lastEntry.onChunks === group.chunks) { | 
					
						
							|  |  |  | 				for (const chunk of childGroup.chunks) { | 
					
						
							|  |  |  | 					lastEntry.chunks.add(chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				result.push( | 
					
						
							|  |  |  | 					(lastEntry = { | 
					
						
							|  |  |  | 						onChunks: group.chunks, | 
					
						
							|  |  |  | 						chunks: new Set(childGroup.chunks) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		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
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				chunkMap[/** @type {ChunkId} */ (chunk.id)] = data[key]; | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											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; |