| 
									
										
										
										
											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-01-05 01:24:55 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 07:46:29 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-20 19:35:01 +08:00
										 |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2021-02-05 20:19:32 +08:00
										 |  |  | /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */ | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | class Stats { | 
					
						
							| 
									
										
										
										
											2018-07-20 19:35:01 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation webpack compilation | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 	constructor(compilation) { | 
					
						
							|  |  |  | 		this.compilation = compilation; | 
					
						
							| 
									
										
										
										
											2020-09-04 04:09:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get hash() { | 
					
						
							|  |  |  | 		return this.compilation.hash; | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get startTime() { | 
					
						
							|  |  |  | 		return this.compilation.startTime; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	get endTime() { | 
					
						
							|  |  |  | 		return this.compilation.endTime; | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-06-04 14:04:07 +08:00
										 |  |  | 	 * @returns {boolean} true if the compilation had a warning | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 	hasWarnings() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return ( | 
					
						
							|  |  |  | 			this.compilation.warnings.length > 0 || | 
					
						
							|  |  |  | 			this.compilation.children.some(child => child.getStats().hasWarnings()) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2015-08-03 17:01:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-06-04 14:04:07 +08:00
										 |  |  | 	 * @returns {boolean} true if the compilation encountered an error | 
					
						
							| 
									
										
										
										
											2018-12-10 18:34:59 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 	hasErrors() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return ( | 
					
						
							|  |  |  | 			this.compilation.errors.length > 0 || | 
					
						
							|  |  |  | 			this.compilation.children.some(child => child.getStats().hasErrors()) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 07:46:29 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2024-02-16 20:47:38 +08:00
										 |  |  | 	 * @param {(string | boolean | StatsOptions)=} options stats options | 
					
						
							| 
									
										
										
										
											2021-02-05 20:19:32 +08:00
										 |  |  | 	 * @returns {StatsCompilation} json output | 
					
						
							| 
									
										
										
										
											2021-01-10 07:46:29 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 	toJson(options) { | 
					
						
							|  |  |  | 		options = this.compilation.createStatsOptions(options, { | 
					
						
							|  |  |  | 			forToString: false | 
					
						
							| 
									
										
										
										
											2015-04-17 16:17:10 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-29 08:38:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		const statsFactory = this.compilation.createStatsFactory(options); | 
					
						
							| 
									
										
										
										
											2018-04-21 19:20:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		return statsFactory.create("compilation", this.compilation, { | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 			compilation: this.compilation | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-11-05 02:43:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-27 00:17:45 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2024-02-16 20:47:38 +08:00
										 |  |  | 	 * @param {(string | boolean | StatsOptions)=} options stats options | 
					
						
							| 
									
										
										
										
											2024-01-27 00:17:45 +08:00
										 |  |  | 	 * @returns {string} string output | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 	toString(options) { | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		options = this.compilation.createStatsOptions(options, { | 
					
						
							|  |  |  | 			forToString: true | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		const statsFactory = this.compilation.createStatsFactory(options); | 
					
						
							|  |  |  | 		const statsPrinter = this.compilation.createStatsPrinter(options); | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		const data = statsFactory.create("compilation", this.compilation, { | 
					
						
							| 
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 |  |  | 			compilation: this.compilation | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		const result = statsPrinter.print("compilation", data); | 
					
						
							|  |  |  | 		return result === undefined ? "" : result; | 
					
						
							| 
									
										
										
										
											2015-08-03 17:01:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-05 01:24:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Stats; |