| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | /** @typedef {import("../ChunkGroup")} ChunkGroup */ | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | /** @typedef {(string|number)[]} EntryItem */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {ChunkGroup} chunkGroup a chunk group | 
					
						
							|  |  |  |  * @returns {Set<Chunk>} chunks | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getAllChunks = chunkGroup => { | 
					
						
							|  |  |  | 	const queue = new Set([chunkGroup]); | 
					
						
							|  |  |  | 	const chunks = new Set(); | 
					
						
							|  |  |  | 	for (const chunkGroup of queue) { | 
					
						
							|  |  |  | 		for (const chunk of chunkGroup.chunks) { | 
					
						
							|  |  |  | 			chunks.add(chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (const parent of chunkGroup.parentsIterable) { | 
					
						
							|  |  |  | 			queue.add(parent); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chunks; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  |  * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2020-06-25 01:44:02 +08:00
										 |  |  |  * @param {function(Chunk): boolean} chunkFilter the chunk filter function | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  |  * @returns {EntryItem[]} serialized entry info: | 
					
						
							|  |  |  |  * inner arrays have this format [module id, ...chunk ids] | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-06-25 01:44:02 +08:00
										 |  |  | exports.getEntryInfo = (chunkGraph, chunk, chunkFilter) => { | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	return Array.from( | 
					
						
							|  |  |  | 		chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk) | 
					
						
							| 
									
										
										
										
											2020-06-25 01:44:02 +08:00
										 |  |  | 	).map(([module, chunkGroup]) => { | 
					
						
							|  |  |  | 		const arr = [chunkGraph.getModuleId(module)]; | 
					
						
							|  |  |  | 		for (const c of getAllChunks(chunkGroup)) { | 
					
						
							| 
									
										
										
										
											2020-08-05 19:41:58 +08:00
										 |  |  | 			if (!chunkFilter(c) && !c.hasRuntime()) continue; | 
					
						
							| 
									
										
										
										
											2020-06-25 01:44:02 +08:00
										 |  |  | 			const id = c.id; | 
					
						
							|  |  |  | 			if (id === chunk.id) continue; | 
					
						
							|  |  |  | 			arr.push(id); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return arr; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | exports.needEntryDeferringCode = (compilation, chunk) => { | 
					
						
							|  |  |  | 	for (const entrypoint of compilation.entrypoints.values()) { | 
					
						
							|  |  |  | 		if (entrypoint.getRuntimeChunk() === chunk) { | 
					
						
							|  |  |  | 			if (entrypoint.chunks.some(c => c !== chunk)) return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | }; |