| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const util = require("util"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | /** @type {undefined | Map<string, { code: string, message: string, stack: string }>} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 06:15:03 +08:00
										 |  |  | let interception; | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const originalDeprecate = util.deprecate; | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @template {EXPECTED_FUNCTION} T | 
					
						
							|  |  |  |  * @param {T} fn fn | 
					
						
							|  |  |  |  * @param {string} message message | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  |  * @param {string=} _code code | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  |  * @returns {T} result | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | util.deprecate = (fn, message, _code) => { | 
					
						
							|  |  |  | 	const original = originalDeprecate(fn, message, _code); | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 	// @ts-expect-error expected
 | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 	return function deprecate(...args) { | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 		if (interception) { | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 			interception.set(`${_code}: ${message}`, { | 
					
						
							|  |  |  | 				code: /** @type {string} */ (_code), | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 				message, | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | 				stack: /** @type {string} */ (new Error(message).stack) | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 			// @ts-expect-error expected
 | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 			return fn.apply(this, args); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | 		// @ts-expect-error expected
 | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 		return original.apply(this, args); | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-01 22:36:51 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @returns {() => EXPECTED_ANY} result | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | module.exports.start = () => { | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 	interception = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return () => { | 
					
						
							|  |  |  | 		const map = interception; | 
					
						
							|  |  |  | 		interception = undefined; | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 		return [...(map || [])] | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 			.sort(([a], [b]) => { | 
					
						
							|  |  |  | 				if (a < b) return -1; | 
					
						
							|  |  |  | 				if (a > b) return 1; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 			.map(([_key, data]) => data); | 
					
						
							| 
									
										
										
										
											2019-12-18 00:18:52 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | }; |