| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const WebpackError = require("../WebpackError"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | /** @typedef {import("../ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | /** @typedef {import("../RequestShortener")} RequestShortener */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {Module} module module to get chains from | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  |  * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  |  * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  |  * @param {RequestShortener} requestShortener to make readable identifiers | 
					
						
							|  |  |  |  * @returns {string[]} all chains to the module | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | const getInitialModuleChains = ( | 
					
						
							|  |  |  | 	module, | 
					
						
							|  |  |  | 	moduleGraph, | 
					
						
							|  |  |  | 	chunkGraph, | 
					
						
							|  |  |  | 	requestShortener | 
					
						
							|  |  |  | ) => { | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 	const queue = [ | 
					
						
							|  |  |  | 		{ head: module, message: module.readableIdentifier(requestShortener) } | 
					
						
							|  |  |  | 	]; | 
					
						
							|  |  |  | 	/** @type {Set<string>} */ | 
					
						
							|  |  |  | 	const results = new Set(); | 
					
						
							|  |  |  | 	/** @type {Set<string>} */ | 
					
						
							|  |  |  | 	const incompleteResults = new Set(); | 
					
						
							|  |  |  | 	/** @type {Set<Module>} */ | 
					
						
							|  |  |  | 	const visitedModules = new Set(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (const chain of queue) { | 
					
						
							|  |  |  | 		const { head, message } = chain; | 
					
						
							|  |  |  | 		let final = true; | 
					
						
							|  |  |  | 		/** @type {Set<Module>} */ | 
					
						
							|  |  |  | 		const alreadyReferencedModules = new Set(); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 		for (const connection of moduleGraph.getIncomingConnections(head)) { | 
					
						
							|  |  |  | 			const newHead = connection.originModule; | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 			if (newHead) { | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 				if (!chunkGraph.getModuleChunks(newHead).some(c => c.canBeInitial())) | 
					
						
							|  |  |  | 					continue; | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 				final = false; | 
					
						
							|  |  |  | 				if (alreadyReferencedModules.has(newHead)) continue; | 
					
						
							|  |  |  | 				alreadyReferencedModules.add(newHead); | 
					
						
							|  |  |  | 				const moduleName = newHead.readableIdentifier(requestShortener); | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 				const detail = connection.explanation | 
					
						
							|  |  |  | 					? ` (${connection.explanation})` | 
					
						
							|  |  |  | 					: ""; | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 				const newMessage = `${moduleName}${detail} --> ${message}`; | 
					
						
							|  |  |  | 				if (visitedModules.has(newHead)) { | 
					
						
							|  |  |  | 					incompleteResults.add(`... --> ${newMessage}`); | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				visitedModules.add(newHead); | 
					
						
							|  |  |  | 				queue.push({ | 
					
						
							|  |  |  | 					head: newHead, | 
					
						
							|  |  |  | 					message: newMessage | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				final = false; | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 				const newMessage = connection.explanation | 
					
						
							|  |  |  | 					? `(${connection.explanation}) --> ${message}` | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 					: message; | 
					
						
							|  |  |  | 				results.add(newMessage); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (final) { | 
					
						
							|  |  |  | 			results.add(message); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for (const result of incompleteResults) { | 
					
						
							|  |  |  | 		results.add(result); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return Array.from(results); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = class WebAssemblyInInitialChunkError extends WebpackError { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Module} module WASM module | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	 * @param {ModuleGraph} moduleGraph the module graph | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 	 * @param {RequestShortener} requestShortener request shortener | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 	constructor(module, moduleGraph, chunkGraph, requestShortener) { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		const moduleChains = getInitialModuleChains( | 
					
						
							|  |  |  | 			module, | 
					
						
							|  |  |  | 			moduleGraph, | 
					
						
							| 
									
										
										
										
											2018-08-14 17:18:22 +08:00
										 |  |  | 			chunkGraph, | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			requestShortener | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 		const message = `WebAssembly module is included in initial chunk.
 | 
					
						
							|  |  |  | This is not allowed, because WebAssembly download and compilation must happen asynchronous. | 
					
						
							|  |  |  | Add an async splitpoint (i. e. import()) somewhere between your entrypoint and the WebAssembly module: | 
					
						
							|  |  |  | ${moduleChains.map(s => `* ${s}`).join("\n")}`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super(message); | 
					
						
							|  |  |  | 		this.name = "WebAssemblyInInitialChunkError"; | 
					
						
							|  |  |  | 		this.hideStack = true; | 
					
						
							|  |  |  | 		this.module = module; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Error.captureStackTrace(this, this.constructor); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; |