| 
									
										
										
										
											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-12-09 19:54:17 +08:00
										 |  |  | const Compiler = require("./Compiler"); | 
					
						
							|  |  |  | const MultiCompiler = require("./MultiCompiler"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | const NormalModule = require("./NormalModule"); | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const createSchemaValidation = require("./util/create-schema-validation"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | const { contextify } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | /** @typedef {import("tapable").Tap} Tap */ | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | /** @typedef {import("./Dependency")} Dependency */ | 
					
						
							|  |  |  | /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */ | 
					
						
							|  |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							|  |  |  | /** @typedef {import("./logging/Logger").Logger} Logger */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} CountsData | 
					
						
							|  |  |  |  * @property {number} modulesCount modules count | 
					
						
							|  |  |  |  * @property {number} dependenciesCount dependencies count | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | const validate = createSchemaValidation( | 
					
						
							|  |  |  | 	require("../schemas/plugins/ProgressPlugin.check.js"), | 
					
						
							|  |  |  | 	() => require("../schemas/plugins/ProgressPlugin.json"), | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		name: "Progress Plugin", | 
					
						
							|  |  |  | 		baseDataPath: "options" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {number} a a | 
					
						
							|  |  |  |  * @param {number} b b | 
					
						
							|  |  |  |  * @param {number} c c | 
					
						
							|  |  |  |  * @returns {number} median | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {boolean | null | undefined} profile need profile | 
					
						
							|  |  |  |  * @param {Logger} logger logger | 
					
						
							|  |  |  |  * @returns {defaultHandler} default handler | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | const createDefaultHandler = (profile, logger) => { | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 	/** @type {{ value: string | undefined, time: number }[]} */ | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 	const lastStateInfo = []; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {number} percentage percentage | 
					
						
							|  |  |  | 	 * @param {string} msg message | 
					
						
							|  |  |  | 	 * @param {...string} args additional arguments | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	const defaultHandler = (percentage, msg, ...args) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (profile) { | 
					
						
							|  |  |  | 			if (percentage === 0) { | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				lastStateInfo.length = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			const fullState = [msg, ...args]; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			const state = fullState.map(s => s.replace(/\d+\/\d+ /g, "")); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 			const now = Date.now(); | 
					
						
							|  |  |  | 			const len = Math.max(state.length, lastStateInfo.length); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			for (let i = len; i >= 0; i--) { | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				const stateItem = i < state.length ? state[i] : undefined; | 
					
						
							|  |  |  | 				const lastStateItem = | 
					
						
							|  |  |  | 					i < lastStateInfo.length ? lastStateInfo[i] : undefined; | 
					
						
							|  |  |  | 				if (lastStateItem) { | 
					
						
							|  |  |  | 					if (stateItem !== lastStateItem.value) { | 
					
						
							|  |  |  | 						const diff = now - lastStateItem.time; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						if (lastStateItem.value) { | 
					
						
							|  |  |  | 							let reportState = lastStateItem.value; | 
					
						
							|  |  |  | 							if (i > 0) { | 
					
						
							|  |  |  | 								reportState = lastStateInfo[i - 1].value + " > " + reportState; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							const stateMsg = `${" | ".repeat(i)}${diff} ms ${reportState}`; | 
					
						
							|  |  |  | 							const d = diff; | 
					
						
							|  |  |  | 							// This depends on timing so we ignore it for coverage
 | 
					
						
							|  |  |  | 							/* istanbul ignore next */ | 
					
						
							|  |  |  | 							{ | 
					
						
							|  |  |  | 								if (d > 10000) { | 
					
						
							|  |  |  | 									logger.error(stateMsg); | 
					
						
							|  |  |  | 								} else if (d > 1000) { | 
					
						
							|  |  |  | 									logger.warn(stateMsg); | 
					
						
							|  |  |  | 								} else if (d > 10) { | 
					
						
							|  |  |  | 									logger.info(stateMsg); | 
					
						
							|  |  |  | 								} else if (d > 5) { | 
					
						
							|  |  |  | 									logger.log(stateMsg); | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									logger.debug(stateMsg); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-04-21 22:29:13 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						if (stateItem === undefined) { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							lastStateInfo.length = i; | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							lastStateItem.value = stateItem; | 
					
						
							|  |  |  | 							lastStateItem.time = now; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							lastStateInfo.length = i + 1; | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-07-26 16:42:18 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					lastStateInfo[i] = { | 
					
						
							|  |  |  | 						value: stateItem, | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						time: now | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					}; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 		logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		if (percentage === 1 || (!msg && args.length === 0)) logger.status(); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return defaultHandler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @callback ReportProgress | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  |  * @param {number} p percentage | 
					
						
							|  |  |  |  * @param {...string} args additional arguments | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | /** @type {WeakMap<Compiler, ReportProgress | undefined>} */ | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 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 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 	 * @returns {ReportProgress | undefined} a progress reporter, if any | 
					
						
							| 
									
										
										
										
											2018-11-27 07:06:02 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	static getReporter(compiler) { | 
					
						
							|  |  |  | 		return progressReporters.get(compiler); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ProgressPluginArgument} options options | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-01-28 20:27:10 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-16 21:35:18 +08:00
										 |  |  | 		validate(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; | 
					
						
							| 
									
										
										
										
											2020-01-30 17:20:48 +08:00
										 |  |  | 		this.percentBy = options.percentBy; | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2020-01-19 01:54:56 +08:00
										 |  |  | 		const states = compiler.compilers.map( | 
					
						
							|  |  |  | 			() => /** @type {[number, ...string[]]} */ ([0]) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		compiler.compilers.forEach((compiler, idx) => { | 
					
						
							|  |  |  | 			new ProgressPlugin((p, msg, ...args) => { | 
					
						
							|  |  |  | 				states[idx] = [p, msg, ...args]; | 
					
						
							| 
									
										
										
										
											2020-01-18 04:19:37 +08:00
										 |  |  | 				let sum = 0; | 
					
						
							|  |  |  | 				for (const [p] of states) sum += p; | 
					
						
							|  |  |  | 				handler(sum / states.length, `[${idx}] ${msg}`, ...args); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			}).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 = ""; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		let currentLoader = ""; | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		let lastModulesCount = 0; | 
					
						
							|  |  |  | 		let lastDependenciesCount = 0; | 
					
						
							| 
									
										
										
										
											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 = | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 				doneModules / | 
					
						
							| 
									
										
										
										
											2021-02-02 20:09:49 +08:00
										 |  |  | 				Math.max(lastModulesCount || this.modulesCount || 1, modulesCount); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			const percentByEntries = | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 				doneEntries / | 
					
						
							| 
									
										
										
										
											2021-02-02 20:09:49 +08:00
										 |  |  | 				Math.max(lastEntriesCount || this.dependenciesCount || 1, entriesCount); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 			const percentByDependencies = | 
					
						
							| 
									
										
										
										
											2021-02-02 20:09:49 +08:00
										 |  |  | 				doneDependencies / | 
					
						
							|  |  |  | 				Math.max(lastDependenciesCount || 1, dependenciesCount); | 
					
						
							| 
									
										
										
										
											2020-01-30 17:20:48 +08:00
										 |  |  | 			let percentageFactor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			switch (this.percentBy) { | 
					
						
							|  |  |  | 				case "entries": | 
					
						
							|  |  |  | 					percentageFactor = percentByEntries; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "dependencies": | 
					
						
							|  |  |  | 					percentageFactor = percentByDependencies; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "modules": | 
					
						
							|  |  |  | 					percentageFactor = percentByModules; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					percentageFactor = median3( | 
					
						
							|  |  |  | 						percentByModules, | 
					
						
							|  |  |  | 						percentByEntries, | 
					
						
							|  |  |  | 						percentByDependencies | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 			const percentage = 0.1 + percentageFactor * 0.55; | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			if (currentLoader) { | 
					
						
							|  |  |  | 				items.push( | 
					
						
							|  |  |  | 					`import loader ${contextify( | 
					
						
							|  |  |  | 						compiler.context, | 
					
						
							|  |  |  | 						currentLoader, | 
					
						
							|  |  |  | 						compiler.root | 
					
						
							|  |  |  | 					)}`
 | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const statItems = []; | 
					
						
							|  |  |  | 				if (showEntries) { | 
					
						
							|  |  |  | 					statItems.push(`${doneEntries}/${entriesCount} entries`); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showDependencies) { | 
					
						
							|  |  |  | 					statItems.push( | 
					
						
							|  |  |  | 						`${doneDependencies}/${dependenciesCount} dependencies` | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showModules) { | 
					
						
							|  |  |  | 					statItems.push(`${doneModules}/${modulesCount} modules`); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showActiveModules) { | 
					
						
							|  |  |  | 					statItems.push(`${activeModules.size} active`); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (statItems.length > 0) { | 
					
						
							|  |  |  | 					items.push(statItems.join(" ")); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (showActiveModules) { | 
					
						
							|  |  |  | 					items.push(lastActiveModule); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			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++; | 
					
						
							| 
									
										
										
										
											2021-02-02 08:23:04 +08:00
										 |  |  | 			if (dependenciesCount < 50 || dependenciesCount % 100 === 0) | 
					
						
							|  |  |  | 				updateThrottled(); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const factorizeDone = () => { | 
					
						
							|  |  |  | 			doneDependencies++; | 
					
						
							| 
									
										
										
										
											2021-02-02 08:23:04 +08:00
										 |  |  | 			if (doneDependencies < 50 || doneDependencies % 100 === 0) | 
					
						
							|  |  |  | 				updateThrottled(); | 
					
						
							| 
									
										
										
										
											2019-11-12 18:33:15 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const moduleAdd = () => { | 
					
						
							|  |  |  | 			modulesCount++; | 
					
						
							| 
									
										
										
										
											2021-02-02 08:23:04 +08:00
										 |  |  | 			if (modulesCount < 50 || modulesCount % 100 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-28 20:43:39 +08:00
										 |  |  | 		// only used when showActiveModules is set
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Module} module the module | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		const moduleBuild = module => { | 
					
						
							| 
									
										
										
										
											2020-10-28 20:43:39 +08:00
										 |  |  | 			const ident = module.identifier(); | 
					
						
							|  |  |  | 			if (ident) { | 
					
						
							|  |  |  | 				activeModules.add(ident); | 
					
						
							|  |  |  | 				lastActiveModule = ident; | 
					
						
							|  |  |  | 				update(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Dependency} entry entry dependency | 
					
						
							|  |  |  | 		 * @param {EntryOptions} options options object | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 		const entryAdd = (entry, options) => { | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			entriesCount++; | 
					
						
							| 
									
										
										
										
											2021-02-02 08:23:04 +08:00
										 |  |  | 			if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2015-11-22 05:59:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Module} module the module | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-02-02 08:23:04 +08:00
										 |  |  | 			if (doneModules < 50 || doneModules % 100 === 0) updateThrottled(); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-11-04 17:27:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {Dependency} entry entry dependency | 
					
						
							|  |  |  | 		 * @param {EntryOptions} options options object | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2020-02-05 04:21:42 +08:00
										 |  |  | 		const entryDone = (entry, options) => { | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			doneEntries++; | 
					
						
							|  |  |  | 			update(); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-10-29 20:49:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 		const cache = compiler | 
					
						
							|  |  |  | 			.getCache("ProgressPlugin") | 
					
						
							|  |  |  | 			.getItemCache("counts", null); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** @type {Promise<CountsData> | undefined} */ | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		let cacheGetPromise; | 
					
						
							| 
									
										
										
										
											2020-02-17 19:39:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		compiler.hooks.beforeCompile.tap("ProgressPlugin", () => { | 
					
						
							|  |  |  | 			if (!cacheGetPromise) { | 
					
						
							|  |  |  | 				cacheGetPromise = cache.getPromise().then( | 
					
						
							|  |  |  | 					data => { | 
					
						
							|  |  |  | 						if (data) { | 
					
						
							|  |  |  | 							lastModulesCount = lastModulesCount || data.modulesCount; | 
					
						
							|  |  |  | 							lastDependenciesCount = | 
					
						
							|  |  |  | 								lastDependenciesCount || data.dependenciesCount; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2020-08-24 18:55:48 +08:00
										 |  |  | 						return data; | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 					err => { | 
					
						
							|  |  |  | 						// Ignore error
 | 
					
						
							| 
									
										
										
										
											2020-02-17 19:39:07 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2020-02-17 19:39:07 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-02-17 19:39:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => { | 
					
						
							| 
									
										
										
										
											2020-10-28 20:43:39 +08:00
										 |  |  | 			if (compilation.compiler.isChild()) return Promise.resolve(); | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 			return /** @type {Promise<CountsData>} */ (cacheGetPromise).then( | 
					
						
							|  |  |  | 				async oldData => { | 
					
						
							|  |  |  | 					if ( | 
					
						
							|  |  |  | 						!oldData || | 
					
						
							|  |  |  | 						oldData.modulesCount !== modulesCount || | 
					
						
							|  |  |  | 						oldData.dependenciesCount !== dependenciesCount | 
					
						
							|  |  |  | 					) { | 
					
						
							|  |  |  | 						await cache.storePromise({ modulesCount, dependenciesCount }); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-08-24 18:55:48 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2020-08-14 13:27:30 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-02-17 19:39:07 +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-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 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-28 20:43:39 +08:00
										 |  |  | 			if (showActiveModules) { | 
					
						
							|  |  |  | 				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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			// avoid dynamic require if bundled with webpack
 | 
					
						
							|  |  |  | 			// @ts-expect-error
 | 
					
						
							|  |  |  | 			if (typeof __webpack_require__ !== "function") { | 
					
						
							|  |  |  | 				const requiredLoaders = new Set(); | 
					
						
							|  |  |  | 				NormalModule.getCompilationHooks(compilation).beforeLoaders.tap( | 
					
						
							|  |  |  | 					"ProgressPlugin", | 
					
						
							|  |  |  | 					loaders => { | 
					
						
							|  |  |  | 						for (const loader of loaders) { | 
					
						
							|  |  |  | 							if ( | 
					
						
							|  |  |  | 								loader.type !== "module" && | 
					
						
							|  |  |  | 								!requiredLoaders.has(loader.loader) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								requiredLoaders.add(loader.loader); | 
					
						
							|  |  |  | 								currentLoader = loader.loader; | 
					
						
							|  |  |  | 								update(); | 
					
						
							|  |  |  | 								require(loader.loader); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if (currentLoader) { | 
					
						
							|  |  |  | 							currentLoader = ""; | 
					
						
							|  |  |  | 							update(); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			const hooks = { | 
					
						
							|  |  |  | 				finishModules: "finish module graph", | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 				seal: "plugins", | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				optimizeDependencies: "dependencies optimization", | 
					
						
							|  |  |  | 				afterOptimizeDependencies: "after dependencies optimization", | 
					
						
							| 
									
										
										
										
											2020-04-29 02:57:33 +08:00
										 |  |  | 				beforeChunks: "chunk graph", | 
					
						
							|  |  |  | 				afterChunks: "after chunk graph", | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				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", | 
					
						
							| 
									
										
										
										
											2020-05-12 18:16:51 +08:00
										 |  |  | 				processAssets: "asset processing", | 
					
						
							|  |  |  | 				afterProcessAssets: "after asset optimization", | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				record: "recording", | 
					
						
							|  |  |  | 				afterSeal: "after seal" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			const numberOfHooks = Object.keys(hooks).length; | 
					
						
							|  |  |  | 			Object.keys(hooks).forEach((name, idx) => { | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 				const title = hooks[/** @type {keyof typeof hooks} */ (name)]; | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 				const percentage = (idx / numberOfHooks) * 0.25 + 0.7; | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 				compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 					name: "ProgressPlugin", | 
					
						
							|  |  |  | 					call() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(percentage, "sealing", title); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					done() { | 
					
						
							| 
									
										
										
										
											2020-08-24 23:45:33 +08:00
										 |  |  | 						progressReporters.set(compiler, undefined); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(percentage, "sealing", title); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 					result() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(percentage, "sealing", title); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 					error() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(percentage, "sealing", title); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +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) => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 							handler(percentage, "sealing", title, tap.name, ...args); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(percentage, "sealing", title, tap.name); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:20:36 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 		compiler.hooks.make.intercept({ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			call() { | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				handler(0.1, "building"); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 			done() { | 
					
						
							| 
									
										
										
										
											2020-06-10 22:28:59 +08:00
										 |  |  | 				handler(0.65, "building"); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * @param {TODO} hook hook | 
					
						
							|  |  |  | 		 * @param {number} progress progress from 0 to 1 | 
					
						
							|  |  |  | 		 * @param {string} category category | 
					
						
							|  |  |  | 		 * @param {string} name name | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		const interceptHook = (hook, progress, category, name) => { | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 			hook.intercept({ | 
					
						
							|  |  |  | 				name: "ProgressPlugin", | 
					
						
							|  |  |  | 				call() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					handler(progress, category, name); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				done() { | 
					
						
							| 
									
										
										
										
											2020-08-24 23:45:33 +08:00
										 |  |  | 					progressReporters.set(compiler, undefined); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					handler(progress, category, name); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				result() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					handler(progress, category, name); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				error() { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					handler(progress, category, name); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Tap} tap tap | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				tap(tap) { | 
					
						
							|  |  |  | 					progressReporters.set(compiler, (p, ...args) => { | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 						handler(progress, category, name, tap.name, ...args); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 					handler(progress, category, name, tap.name); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		compiler.cache.hooks.endIdle.intercept({ | 
					
						
							|  |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			call() { | 
					
						
							|  |  |  | 				handler(0, ""); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle"); | 
					
						
							| 
									
										
										
										
											2022-02-24 23:17:42 +08:00
										 |  |  | 		compiler.hooks.beforeRun.intercept({ | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			call() { | 
					
						
							|  |  |  | 				handler(0, ""); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2022-02-23 21:01:47 +08:00
										 |  |  | 		interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.run, 0.02, "setup", "run"); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run"); | 
					
						
							| 
									
										
										
										
											2020-04-19 01:03:02 +08:00
										 |  |  | 		interceptHook( | 
					
						
							|  |  |  | 			compiler.hooks.normalModuleFactory, | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			0.04, | 
					
						
							|  |  |  | 			"setup", | 
					
						
							| 
									
										
										
										
											2020-04-19 01:03:02 +08:00
										 |  |  | 			"normal module factory" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		interceptHook( | 
					
						
							|  |  |  | 			compiler.hooks.contextModuleFactory, | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			0.05, | 
					
						
							|  |  |  | 			"setup", | 
					
						
							| 
									
										
										
										
											2020-04-19 01:03:02 +08:00
										 |  |  | 			"context module factory" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 		interceptHook( | 
					
						
							|  |  |  | 			compiler.hooks.beforeCompile, | 
					
						
							|  |  |  | 			0.06, | 
					
						
							|  |  |  | 			"setup", | 
					
						
							|  |  |  | 			"before compile" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.compile, 0.07, "setup", "compile"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.thisCompilation, 0.08, "setup", "compilation"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.compilation, 0.09, "setup", "compilation"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.finishMake, 0.69, "building", "finish"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.emit, 0.95, "emitting", "emit"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.afterEmit, 0.98, "emitting", "after emit"); | 
					
						
							|  |  |  | 		interceptHook(compiler.hooks.done, 0.99, "done", "plugins"); | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 		compiler.hooks.done.intercept({ | 
					
						
							| 
									
										
										
										
											2020-07-31 23:38:33 +08:00
										 |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			done() { | 
					
						
							|  |  |  | 				handler(0.99, ""); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		interceptHook( | 
					
						
							|  |  |  | 			compiler.cache.hooks.storeBuildDependencies, | 
					
						
							|  |  |  | 			0.99, | 
					
						
							|  |  |  | 			"cache", | 
					
						
							|  |  |  | 			"store build dependencies" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		interceptHook(compiler.cache.hooks.shutdown, 0.99, "cache", "shutdown"); | 
					
						
							|  |  |  | 		interceptHook(compiler.cache.hooks.beginIdle, 0.99, "cache", "begin idle"); | 
					
						
							|  |  |  | 		interceptHook( | 
					
						
							|  |  |  | 			compiler.hooks.watchClose, | 
					
						
							|  |  |  | 			0.99, | 
					
						
							|  |  |  | 			"end", | 
					
						
							|  |  |  | 			"closing watch compilation" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		compiler.cache.hooks.beginIdle.intercept({ | 
					
						
							|  |  |  | 			name: "ProgressPlugin", | 
					
						
							|  |  |  | 			done() { | 
					
						
							|  |  |  | 				handler(1, ""); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		compiler.cache.hooks.shutdown.intercept({ | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +08:00
										 |  |  | 			name: "ProgressPlugin", | 
					
						
							| 
									
										
										
										
											2019-12-20 23:34:51 +08:00
										 |  |  | 			done() { | 
					
						
							|  |  |  | 				handler(1, ""); | 
					
						
							| 
									
										
										
										
											2018-12-09 19:54:17 +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, | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-05 08:06:45 +08:00
										 |  |  | ProgressPlugin.createDefaultHandler = createDefaultHandler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 15:57:56 +08:00
										 |  |  | module.exports = ProgressPlugin; |