| 
									
										
										
										
											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"); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | const Compiler = require("./Compiler"); | 
					
						
							|  |  |  | const MultiCompiler = require("./MultiCompiler"); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | /** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */ | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */ | 
					
						
							|  |  |  | /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | const median3 = (a, b, c) => { | 
					
						
							|  |  |  | 	return a + b + c - Math.max(a, b, c) - Math.min(a, b, c); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | const createDefaultHandler = (profile, logger) => { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	let lastState; | 
					
						
							|  |  |  | 	let lastStateTime; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const defaultHandler = (percentage, msg, ...args) => { | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 		logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (profile) { | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 			let state = msg; | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2019-07-26 16:42:18 +08:00
										 |  |  | 					const diff = now - lastStateTime; | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 					const stateMsg = `${diff}ms ${lastState}`; | 
					
						
							|  |  |  | 					if (diff > 1000) { | 
					
						
							|  |  |  | 						logger.warn(stateMsg); | 
					
						
							|  |  |  | 					} else if (diff > 10) { | 
					
						
							|  |  |  | 						logger.info(stateMsg); | 
					
						
							|  |  |  | 					} else if (diff > 0) { | 
					
						
							|  |  |  | 						logger.log(stateMsg); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						logger.debug(stateMsg); | 
					
						
							| 
									
										
										
										
											2019-07-26 16:42:18 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				lastState = state; | 
					
						
							|  |  |  | 				lastStateTime = now; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 		if (percentage === 1) logger.status(); | 
					
						
							| 
									
										
										
										
											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 || {}; | 
					
						
							| 
									
										
										
										
											2019-08-07 21:55:03 +08:00
										 |  |  | 		validateOptions(schema, options || {}, { | 
					
						
							|  |  |  | 			name: "Progress Plugin", | 
					
						
							|  |  |  | 			baseDataPath: "options" | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 		options = { ...ProgressPlugin.defaultOptions, ...options }; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		this.dependenciesCount = options.dependenciesCount; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		this.showEntries = options.entries; | 
					
						
							|  |  |  | 		this.showModules = options.modules; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		this.showDependencies = options.dependencies; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		this.showActiveModules = options.activeModules; | 
					
						
							| 
									
										
										
										
											2016-01-10 06:48:37 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler | MultiCompiler} compiler webpack compiler | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 	apply(compiler) { | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 		const handler = | 
					
						
							|  |  |  | 			this.handler || | 
					
						
							|  |  |  | 			createDefaultHandler( | 
					
						
							|  |  |  | 				this.profile, | 
					
						
							|  |  |  | 				compiler.getInfrastructureLogger("webpack.Progress") | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		if (compiler instanceof MultiCompiler) { | 
					
						
							|  |  |  | 			this._applyOnMultiCompiler(compiler, handler); | 
					
						
							|  |  |  | 		} else if (compiler instanceof Compiler) { | 
					
						
							|  |  |  | 			this._applyOnCompiler(compiler, handler); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {MultiCompiler} compiler webpack multi-compiler | 
					
						
							|  |  |  | 	 * @param {HandlerFunction} handler function that executes for every progress step | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_applyOnMultiCompiler(compiler, handler) { | 
					
						
							|  |  |  | 		const states = compiler.compilers.map(() => null); | 
					
						
							|  |  |  | 		compiler.compilers.forEach((compiler, idx) => { | 
					
						
							|  |  |  | 			new ProgressPlugin((p, msg, ...args) => { | 
					
						
							|  |  |  | 				states[idx] = [p, msg, ...args]; | 
					
						
							|  |  |  | 				handler( | 
					
						
							|  |  |  | 					states | 
					
						
							|  |  |  | 						.map(state => (state && state[0]) || 0) | 
					
						
							|  |  |  | 						.reduce((a, b) => a + b) / states.length, | 
					
						
							|  |  |  | 					`[${idx}] ${msg}`, | 
					
						
							|  |  |  | 					...args | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			}).apply(compiler); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler webpack compiler | 
					
						
							|  |  |  | 	 * @param {HandlerFunction} handler function that executes for every progress step | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	_applyOnCompiler(compiler, handler) { | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		const showEntries = this.showEntries; | 
					
						
							|  |  |  | 		const showModules = this.showModules; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		const showDependencies = this.showDependencies; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 		const showActiveModules = this.showActiveModules; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		let lastActiveModule = ""; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		let lastModulesCount = this.modulesCount; | 
					
						
							|  |  |  | 		let lastDependenciesCount = this.dependenciesCount; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		let lastEntriesCount = 0; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		let modulesCount = 0; | 
					
						
							|  |  |  | 		let dependenciesCount = 0; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		let entriesCount = 1; | 
					
						
							|  |  |  | 		let doneModules = 0; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		let doneDependencies = 0; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		let doneEntries = 0; | 
					
						
							|  |  |  | 		const activeModules = new Set(); | 
					
						
							| 
									
										
										
										
											2019-07-26 19:36:16 +08:00
										 |  |  | 		let lastUpdate = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const updateThrottled = () => { | 
					
						
							|  |  |  | 			if (lastUpdate + 500 < Date.now()) update(); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const update = () => { | 
					
						
							|  |  |  | 			/** @type {string[]} */ | 
					
						
							|  |  |  | 			const items = []; | 
					
						
							|  |  |  | 			const percentByModules = | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 				doneModules / Math.max(lastModulesCount, modulesCount); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			const percentByEntries = | 
					
						
							|  |  |  | 				doneEntries / Math.max(lastEntriesCount, entriesCount); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			const percentByDependencies = | 
					
						
							|  |  |  | 				doneDependencies / Math.max(lastDependenciesCount, dependenciesCount); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			const percentage = | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 				0.1 + | 
					
						
							|  |  |  | 				median3(percentByModules, percentByEntries, percentByDependencies) * | 
					
						
							|  |  |  | 					0.6; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			if (showEntries) { | 
					
						
							|  |  |  | 				items.push(`${doneEntries}/${entriesCount} entries`); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			if (showDependencies) { | 
					
						
							|  |  |  | 				items.push(`${doneDependencies}/${dependenciesCount} dependencies`); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			if (showModules) { | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 				items.push(`${doneModules}/${modulesCount} modules`); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (showActiveModules) { | 
					
						
							|  |  |  | 				items.push(`${activeModules.size} active`); | 
					
						
							|  |  |  | 				items.push(lastActiveModule); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			handler(percentage, "building", ...items); | 
					
						
							| 
									
										
										
										
											2019-07-26 19:36:16 +08:00
										 |  |  | 			lastUpdate = Date.now(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		const factorizeAdd = () => { | 
					
						
							|  |  |  | 			dependenciesCount++; | 
					
						
							|  |  |  | 			if (dependenciesCount % 100 === 0) updateThrottled(); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const factorizeDone = () => { | 
					
						
							|  |  |  | 			doneDependencies++; | 
					
						
							|  |  |  | 			if (doneDependencies % 100 === 0) updateThrottled(); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const moduleAdd = () => { | 
					
						
							|  |  |  | 			modulesCount++; | 
					
						
							|  |  |  | 			if (modulesCount % 100 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const moduleBuild = module => { | 
					
						
							|  |  |  | 			if (showActiveModules) { | 
					
						
							|  |  |  | 				const ident = module.identifier(); | 
					
						
							|  |  |  | 				if (ident) { | 
					
						
							|  |  |  | 					activeModules.add(ident); | 
					
						
							|  |  |  | 					lastActiveModule = ident; | 
					
						
							| 
									
										
										
										
											2019-11-12 17:55:54 +08:00
										 |  |  | 					update(); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const entryAdd = (entry, name) => { | 
					
						
							|  |  |  | 			entriesCount++; | 
					
						
							| 
									
										
										
										
											2019-07-26 19:36:16 +08:00
										 |  |  | 			if (entriesCount % 10 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const moduleDone = module => { | 
					
						
							|  |  |  | 			doneModules++; | 
					
						
							|  |  |  | 			if (showActiveModules) { | 
					
						
							|  |  |  | 				const ident = module.identifier(); | 
					
						
							|  |  |  | 				if (ident) { | 
					
						
							|  |  |  | 					activeModules.delete(ident); | 
					
						
							|  |  |  | 					if (lastActiveModule === ident) { | 
					
						
							|  |  |  | 						lastActiveModule = ""; | 
					
						
							|  |  |  | 						for (const m of activeModules) { | 
					
						
							|  |  |  | 							lastActiveModule = m; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-07-26 19:36:16 +08:00
										 |  |  | 						update(); | 
					
						
							|  |  |  | 						return; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-07-26 19:36:16 +08:00
										 |  |  | 			if (doneModules % 100 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const entryDone = (entry, name) => { | 
					
						
							|  |  |  | 			doneEntries++; | 
					
						
							|  |  |  | 			update(); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		compiler.hooks.compilation.tap("ProgressPlugin", compilation => { | 
					
						
							|  |  |  | 			if (compilation.compiler.isChild()) return; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			lastModulesCount = modulesCount; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			lastEntriesCount = entriesCount; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			lastDependenciesCount = dependenciesCount; | 
					
						
							|  |  |  | 			modulesCount = dependenciesCount = entriesCount = 0; | 
					
						
							|  |  |  | 			doneModules = doneDependencies = doneEntries = 0; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			handler(0, "compiling"); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			compilation.factorizeQueue.hooks.added.tap( | 
					
						
							|  |  |  | 				"ProgressPlugin", | 
					
						
							|  |  |  | 				factorizeAdd | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			compilation.factorizeQueue.hooks.result.tap( | 
					
						
							|  |  |  | 				"ProgressPlugin", | 
					
						
							|  |  |  | 				factorizeDone | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-25 21:47:31 +08:00
										 |  |  | 			compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", moduleAdd); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			compilation.processDependenciesQueue.hooks.result.tap( | 
					
						
							|  |  |  | 				"ProgressPlugin", | 
					
						
							|  |  |  | 				moduleDone | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild); | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd); | 
					
						
							|  |  |  | 			compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone); | 
					
						
							|  |  |  | 			compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			const hooks = { | 
					
						
							|  |  |  | 				finishModules: "finish module graph", | 
					
						
							|  |  |  | 				seal: "sealing", | 
					
						
							|  |  |  | 				beforeChunks: "chunk graph", | 
					
						
							|  |  |  | 				afterChunks: "after chunk graph", | 
					
						
							|  |  |  | 				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", | 
					
						
							|  |  |  | 				chunkIds: "chunk ids", | 
					
						
							|  |  |  | 				optimizeChunkIds: "chunk id optimization", | 
					
						
							|  |  |  | 				afterOptimizeChunkIds: "after chunk id optimization", | 
					
						
							|  |  |  | 				recordModules: "record modules", | 
					
						
							|  |  |  | 				recordChunks: "record chunks", | 
					
						
							|  |  |  | 				beforeModuleHash: "module hashing", | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 				beforeCodeGeneration: "code generation", | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				beforeRuntimeRequirements: "runtime requirements", | 
					
						
							|  |  |  | 				beforeHash: "hashing", | 
					
						
							|  |  |  | 				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", | 
					
						
							| 
									
										
										
										
											2019-11-12 21:34:19 +08:00
										 |  |  | 				finishAssets: "finish assets", | 
					
						
							|  |  |  | 				afterFinishAssets: "after finish assets", | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				afterSeal: "after seal" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			const numberOfHooks = Object.keys(hooks).length; | 
					
						
							|  |  |  | 			Object.keys(hooks).forEach((name, idx) => { | 
					
						
							|  |  |  | 				const title = hooks[name]; | 
					
						
							|  |  |  | 				const percentage = (idx / numberOfHooks) * 0.25 + 0.7; | 
					
						
							|  |  |  | 				compilation.hooks[name].intercept({ | 
					
						
							|  |  |  | 					name: "ProgressPlugin", | 
					
						
							|  |  |  | 					call() { | 
					
						
							|  |  |  | 						handler(percentage, title); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					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); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						handler(percentage, title, tap.name); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:20:36 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		compiler.hooks.emit.intercept({ | 
					
						
							|  |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			call() { | 
					
						
							|  |  |  | 				handler(0.95, "emitting"); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			tap(tap) { | 
					
						
							|  |  |  | 				progressReporters.set(compiler, (p, ...args) => { | 
					
						
							|  |  |  | 					handler(0.95, "emitting", tap.name, ...args); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				handler(0.95, "emitting", tap.name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		compiler.hooks.afterEmit.intercept({ | 
					
						
							|  |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			call() { | 
					
						
							|  |  |  | 				handler(0.98, "after emitting"); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			tap(tap) { | 
					
						
							|  |  |  | 				progressReporters.set(compiler, (p, ...args) => { | 
					
						
							|  |  |  | 					handler(0.98, "after emitting", tap.name, ...args); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				handler(0.98, "after emitting", tap.name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		compiler.hooks.done.tap("ProgressPlugin", () => { | 
					
						
							|  |  |  | 			handler(1, ""); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 	modulesCount: 5000, | 
					
						
							|  |  |  | 	dependenciesCount: 10000, | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 	modules: true, | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 	dependencies: true, | 
					
						
							| 
									
										
										
										
											2019-10-10 20:00:28 +08:00
										 |  |  | 	activeModules: false, | 
					
						
							| 
									
										
										
										
											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; |