| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | const validateOptions = require("schema-utils"); | 
					
						
							|  |  |  | const schema = require("../schemas/plugins/ProgressPlugin.json"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */ | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | /** @typedef {import("./Compiler")} Compiler */ | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | const createDefaultHandler = profile => { | 
					
						
							|  |  |  | 	let lineCaretPosition = 0; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:33:37 +08:00
										 |  |  | 	let lastMessage = ""; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	let lastState; | 
					
						
							|  |  |  | 	let lastStateTime; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const defaultHandler = (percentage, msg, ...args) => { | 
					
						
							|  |  |  | 		let state = msg; | 
					
						
							|  |  |  | 		const details = args; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (percentage < 1) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			percentage = Math.floor(percentage * 100); | 
					
						
							|  |  |  | 			msg = `${percentage}% ${msg}`; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (percentage < 100) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				msg = ` ${msg}`; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (percentage < 10) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				msg = ` ${msg}`; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (let detail of details) { | 
					
						
							|  |  |  | 				if (!detail) continue; | 
					
						
							|  |  |  | 				if (detail.length > 40) { | 
					
						
							| 
									
										
										
										
											2018-08-28 16:09:21 +08:00
										 |  |  | 					detail = `...${detail.substr(detail.length - 39)}`; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				msg += ` ${detail}`; | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (profile) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			state = state.replace(/^\d+\/\d+\s+/, ""); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (percentage === 0) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				lastState = null; | 
					
						
							|  |  |  | 				lastStateTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (state !== lastState || percentage === 1) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				const now = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (lastState) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 					const stateMsg = `${now - lastStateTime}ms ${lastState}`; | 
					
						
							|  |  |  | 					goToLineStart(stateMsg); | 
					
						
							|  |  |  | 					process.stderr.write(stateMsg + "\n"); | 
					
						
							|  |  |  | 					lineCaretPosition = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				lastState = state; | 
					
						
							|  |  |  | 				lastStateTime = now; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-04 17:33:37 +08:00
										 |  |  | 		if (lastMessage !== msg) { | 
					
						
							|  |  |  | 			goToLineStart(msg); | 
					
						
							|  |  |  | 			process.stderr.write(msg); | 
					
						
							|  |  |  | 			lastMessage = msg; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const goToLineStart = nextMessage => { | 
					
						
							|  |  |  | 		let str = ""; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (; lineCaretPosition > nextMessage.length; lineCaretPosition--) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			str += "\b \b"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		for (var i = 0; i < lineCaretPosition; i++) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			str += "\b"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		lineCaretPosition = nextMessage.length; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (str) process.stderr.write(str); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return defaultHandler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @callback ReportProgress | 
					
						
							|  |  |  |  * @param {number} p | 
					
						
							|  |  |  |  * @param {...string[]} [args] | 
					
						
							|  |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @type {WeakMap<Compiler,ReportProgress>} */ | 
					
						
							|  |  |  | const progressReporters = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | class ProgressPlugin { | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the current compiler | 
					
						
							|  |  |  | 	 * @returns {ReportProgress} a progress reporter, if any | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static getReporter(compiler) { | 
					
						
							|  |  |  | 		return progressReporters.get(compiler); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ProgressPluginArgument} options options | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 	constructor(options) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (typeof options === "function") { | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			options = { | 
					
						
							|  |  |  | 				handler: options | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 		options = options || {}; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 		validateOptions(schema, options, "Progress Plugin"); | 
					
						
							|  |  |  | 		options = Object.assign({}, ProgressPlugin.defaultOptions, options); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 		this.profile = options.profile; | 
					
						
							|  |  |  | 		this.handler = options.handler; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 		this.modulesCount = options.modulesCount; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		this.showEntries = options.entries; | 
					
						
							|  |  |  | 		this.showModules = options.modules; | 
					
						
							|  |  |  | 		this.showActiveModules = options.activeModules; | 
					
						
							| 
									
										
										
										
											2016-01-10 06:48:37 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 		const { modulesCount } = this; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const handler = this.handler || createDefaultHandler(this.profile); | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		const showEntries = this.showEntries; | 
					
						
							|  |  |  | 		const showModules = this.showModules; | 
					
						
							|  |  |  | 		const showActiveModules = this.showActiveModules; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (compiler.compilers) { | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			const states = new Array(compiler.compilers.length); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			compiler.compilers.forEach((compiler, idx) => { | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 				new ProgressPlugin((p, msg, ...args) => { | 
					
						
							| 
									
										
										
										
											2018-05-12 01:06:10 +08:00
										 |  |  | 					states[idx] = [p, msg, ...args]; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 					handler( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						states | 
					
						
							|  |  |  | 							.map(state => (state && state[0]) || 0) | 
					
						
							|  |  |  | 							.reduce((a, b) => a + b) / states.length, | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 						`[${idx}] ${msg}`, | 
					
						
							|  |  |  | 						...args | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-12-20 16:53:33 +08:00
										 |  |  | 				}).apply(compiler); | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			let lastModulesCount = 0; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 			let lastEntriesCount = 0; | 
					
						
							|  |  |  | 			let moduleCount = modulesCount; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 			let entriesCount = 1; | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			let doneModules = 0; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 			let doneEntries = 0; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 			const activeModules = new Set(); | 
					
						
							|  |  |  | 			let lastActiveModule = ""; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			const update = () => { | 
					
						
							|  |  |  | 				const percentByModules = | 
					
						
							|  |  |  | 					doneModules / Math.max(lastModulesCount, moduleCount); | 
					
						
							|  |  |  | 				const percentByEntries = | 
					
						
							|  |  |  | 					doneEntries / Math.max(lastEntriesCount, entriesCount); | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 				const items = [ | 
					
						
							|  |  |  | 					0.1 + Math.max(percentByModules, percentByEntries) * 0.6, | 
					
						
							|  |  |  | 					"building" | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				if (showEntries) { | 
					
						
							|  |  |  | 					items.push(`${doneEntries}/${entriesCount} entries`); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showModules) { | 
					
						
							|  |  |  | 					items.push(`${doneModules}/${moduleCount} modules`); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showActiveModules) { | 
					
						
							|  |  |  | 					items.push(`${activeModules.size} active`); | 
					
						
							|  |  |  | 					items.push(lastActiveModule); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				handler(...items); | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 			const moduleAdd = module => { | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				moduleCount++; | 
					
						
							| 
									
										
										
										
											2018-11-05 18:07:35 +08:00
										 |  |  | 				update(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const moduleBuild = module => { | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 				if (showActiveModules) { | 
					
						
							|  |  |  | 					const ident = module.identifier(); | 
					
						
							|  |  |  | 					if (ident) { | 
					
						
							|  |  |  | 						activeModules.add(ident); | 
					
						
							|  |  |  | 						lastActiveModule = ident; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				update(); | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			const entryAdd = (entry, name) => { | 
					
						
							|  |  |  | 				entriesCount++; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				update(); | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			const moduleDone = module => { | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				doneModules++; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 				if (showActiveModules) { | 
					
						
							|  |  |  | 					const ident = module.identifier(); | 
					
						
							|  |  |  | 					if (ident) { | 
					
						
							|  |  |  | 						activeModules.delete(ident); | 
					
						
							|  |  |  | 						if (lastActiveModule === ident) { | 
					
						
							|  |  |  | 							lastActiveModule = ""; | 
					
						
							|  |  |  | 							for (const m of activeModules) { | 
					
						
							|  |  |  | 								lastActiveModule = m; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 				update(); | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 			const entryDone = (entry, name) => { | 
					
						
							|  |  |  | 				doneEntries++; | 
					
						
							|  |  |  | 				update(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			compiler.hooks.compilation.tap("ProgressPlugin", compilation => { | 
					
						
							|  |  |  | 				if (compilation.compiler.isChild()) return; | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				lastModulesCount = moduleCount; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				lastEntriesCount = entriesCount; | 
					
						
							|  |  |  | 				moduleCount = entriesCount = 0; | 
					
						
							|  |  |  | 				doneModules = doneEntries = 0; | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				handler(0, "compiling"); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-05 18:07:35 +08:00
										 |  |  | 				compilation.buildQueue.hooks.added.tap("ProgressPlugin", moduleAdd); | 
					
						
							|  |  |  | 				compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild); | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 				compilation.hooks.failedModule.tap("ProgressPlugin", moduleDone); | 
					
						
							|  |  |  | 				compilation.hooks.succeedModule.tap("ProgressPlugin", moduleDone); | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd); | 
					
						
							|  |  |  | 				compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 				const hooks = { | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					finishModules: "finish module graph", | 
					
						
							|  |  |  | 					seal: "sealing", | 
					
						
							| 
									
										
										
										
											2018-11-04 17:36:47 +08:00
										 |  |  | 					beforeChunks: "chunk graph", | 
					
						
							|  |  |  | 					afterChunks: "after chunk graph", | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					optimizeDependencies: "dependencies optimization", | 
					
						
							|  |  |  | 					afterOptimizeDependencies: "after dependencies optimization", | 
					
						
							|  |  |  | 					optimize: "optimizing", | 
					
						
							|  |  |  | 					optimizeModules: "module optimization", | 
					
						
							|  |  |  | 					afterOptimizeModules: "after module optimization", | 
					
						
							|  |  |  | 					optimizeChunks: "chunk optimization", | 
					
						
							|  |  |  | 					afterOptimizeChunks: "after chunk optimization", | 
					
						
							|  |  |  | 					optimizeTree: "module and chunk tree optimization", | 
					
						
							|  |  |  | 					afterOptimizeTree: "after module and chunk tree optimization", | 
					
						
							|  |  |  | 					optimizeChunkModules: "chunk modules optimization", | 
					
						
							|  |  |  | 					afterOptimizeChunkModules: "after chunk modules optimization", | 
					
						
							|  |  |  | 					reviveModules: "module reviving", | 
					
						
							|  |  |  | 					beforeModuleIds: "before module ids", | 
					
						
							|  |  |  | 					moduleIds: "module ids", | 
					
						
							|  |  |  | 					optimizeModuleIds: "module id optimization", | 
					
						
							|  |  |  | 					afterOptimizeModuleIds: "module id optimization", | 
					
						
							|  |  |  | 					reviveChunks: "chunk reviving", | 
					
						
							|  |  |  | 					beforeChunkIds: "before chunk ids", | 
					
						
							| 
									
										
										
										
											2018-09-05 20:22:10 +08:00
										 |  |  | 					chunkIds: "chunk ids", | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					optimizeChunkIds: "chunk id optimization", | 
					
						
							|  |  |  | 					afterOptimizeChunkIds: "after chunk id optimization", | 
					
						
							|  |  |  | 					recordModules: "record modules", | 
					
						
							|  |  |  | 					recordChunks: "record chunks", | 
					
						
							| 
									
										
										
										
											2018-11-15 00:31:32 +08:00
										 |  |  | 					beforeModuleHash: "module hashing", | 
					
						
							|  |  |  | 					beforeRuntimeRequirements: "runtime requirements", | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					beforeHash: "hashing", | 
					
						
							| 
									
										
										
										
											2018-11-04 17:36:47 +08:00
										 |  |  | 					contentHash: "content hashing", | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					afterHash: "after hashing", | 
					
						
							|  |  |  | 					recordHash: "record hash", | 
					
						
							|  |  |  | 					beforeModuleAssets: "module assets processing", | 
					
						
							|  |  |  | 					beforeChunkAssets: "chunk assets processing", | 
					
						
							|  |  |  | 					additionalChunkAssets: "additional chunk assets processing", | 
					
						
							|  |  |  | 					record: "recording", | 
					
						
							|  |  |  | 					additionalAssets: "additional asset processing", | 
					
						
							|  |  |  | 					optimizeChunkAssets: "chunk asset optimization", | 
					
						
							|  |  |  | 					afterOptimizeChunkAssets: "after chunk asset optimization", | 
					
						
							|  |  |  | 					optimizeAssets: "asset optimization", | 
					
						
							|  |  |  | 					afterOptimizeAssets: "after asset optimization", | 
					
						
							|  |  |  | 					afterSeal: "after seal" | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 				const numberOfHooks = Object.keys(hooks).length; | 
					
						
							|  |  |  | 				Object.keys(hooks).forEach((name, idx) => { | 
					
						
							|  |  |  | 					const title = hooks[name]; | 
					
						
							| 
									
										
										
										
											2018-05-29 22:14:16 +08:00
										 |  |  | 					const percentage = (idx / numberOfHooks) * 0.25 + 0.7; | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					compilation.hooks[name].intercept({ | 
					
						
							|  |  |  | 						name: "ProgressPlugin", | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 						call() { | 
					
						
							| 
									
										
										
										
											2017-12-13 17:09:35 +08:00
										 |  |  | 							handler(percentage, title); | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 						tap(tap) { | 
					
						
							|  |  |  | 							// p is percentage from 0 to 1
 | 
					
						
							|  |  |  | 							// args is any number of messages in a hierarchical matter
 | 
					
						
							|  |  |  | 							progressReporters.set(compilation.compiler, (p, ...args) => { | 
					
						
							|  |  |  | 								handler(percentage, title, tap.name, ...args); | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2017-12-13 17:09:35 +08:00
										 |  |  | 							handler(percentage, title, tap.name); | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:20:36 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 			compiler.hooks.emit.intercept({ | 
					
						
							|  |  |  | 				name: "ProgressPlugin", | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 				call() { | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					handler(0.95, "emitting"); | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 				tap(tap) { | 
					
						
							|  |  |  | 					progressReporters.set(compiler, (p, ...args) => { | 
					
						
							|  |  |  | 						handler(0.95, "emitting", tap.name, ...args); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-12-12 21:44:26 +08:00
										 |  |  | 					handler(0.95, "emitting", tap.name); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-05-30 02:22:12 +08:00
										 |  |  | 			compiler.hooks.afterEmit.intercept({ | 
					
						
							|  |  |  | 				name: "ProgressPlugin", | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 				call() { | 
					
						
							| 
									
										
										
										
											2018-05-30 02:22:12 +08:00
										 |  |  | 					handler(0.98, "after emitting"); | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 				tap(tap) { | 
					
						
							|  |  |  | 					progressReporters.set(compiler, (p, ...args) => { | 
					
						
							|  |  |  | 						handler(0.98, "after emitting", tap.name, ...args); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-05-30 02:22:12 +08:00
										 |  |  | 					handler(0.98, "after emitting", tap.name); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-12-06 22:01:25 +08:00
										 |  |  | 			compiler.hooks.done.tap("ProgressPlugin", () => { | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				handler(1, ""); | 
					
						
							| 
									
										
										
										
											2014-06-19 05:02:33 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | ProgressPlugin.defaultOptions = { | 
					
						
							|  |  |  | 	profile: false, | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 	modulesCount: 500, | 
					
						
							|  |  |  | 	modules: true, | 
					
						
							|  |  |  | 	activeModules: true, | 
					
						
							| 
									
										
										
										
											2018-11-05 17:28:37 +08:00
										 |  |  | 	entries: true | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | module.exports = ProgressPlugin; |