88 * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
99 */
1010
11- // @ts -nocheck
11+ import type { EXPECTED_ANY } from '../types' ;
1212
13- 'use strict' ;
13+ export const LogType = Object . freeze ( {
14+ error : 'error' , // message, c style arguments
15+ warn : 'warn' , // message, c style arguments
16+ info : 'info' , // message, c style arguments
17+ log : 'log' , // message, c style arguments
18+ debug : 'debug' , // message, c style arguments
1419
15- const LogType = Object . freeze ( {
16- error : /** @type {"error" } */ ( 'error' ) , // message, c style arguments
17- warn : /** @type {"warn" } */ ( 'warn' ) , // message, c style arguments
18- info : /** @type {"info" } */ ( 'info' ) , // message, c style arguments
19- log : /** @type {"log" } */ ( 'log' ) , // message, c style arguments
20- debug : /** @type {"debug" } */ ( 'debug' ) , // message, c style arguments
20+ trace : 'trace' , // no arguments
2121
22- trace : /** @type {"trace" } */ ( 'trace' ) , // no arguments
22+ group : 'group' , // [label]
23+ groupCollapsed : 'groupCollapsed' , // [label]
24+ groupEnd : 'groupEnd' , // [label]
2325
24- group : /** @type {"group" } */ ( 'group' ) , // [label]
25- groupCollapsed : /** @type {"groupCollapsed" } */ ( 'groupCollapsed' ) , // [label]
26- groupEnd : /** @type {"groupEnd" } */ ( 'groupEnd' ) , // [label]
26+ profile : 'profile' , // [profileName]
27+ profileEnd : 'profileEnd' , // [profileName]
2728
28- profile : /** @type {"profile" } */ ( 'profile' ) , // [profileName]
29- profileEnd : /** @type {"profileEnd" } */ ( 'profileEnd' ) , // [profileName]
29+ time : 'time' , // name, time as [seconds, nanoseconds]
3030
31- time : /** @type {"time" } */ ( 'time' ) , // name, time as [seconds, nanoseconds]
32-
33- clear : /** @type {"clear" } */ ( 'clear' ) , // no arguments
34- status : /** @type {"status" } */ ( 'status' ) , // message, arguments
31+ clear : 'clear' , // no arguments
32+ status : 'status' , // message, arguments
3533} ) ;
3634
37- module . exports . LogType = LogType ;
38-
39- /** @typedef {typeof LogType[keyof typeof LogType] } LogTypeEnum */
40- /** @typedef {Map<string | undefined, [number, number]> } TimersMap */
35+ export type LogTypeEnum = ( typeof LogType ) [ keyof typeof LogType ] ;
36+ export type TimersMap = Map < string | undefined , [ number , number ] > ;
4137
4238const LOG_SYMBOL = Symbol ( 'webpack logger raw log method' ) ;
4339const TIMERS_SYMBOL = Symbol ( 'webpack logger times' ) ;
4440const TIMERS_AGGREGATES_SYMBOL = Symbol ( 'webpack logger aggregated times' ) ;
4541
46- /** @typedef { EXPECTED_ANY[] } Args */
42+ export type Args = EXPECTED_ANY [ ] ;
4743
4844class WebpackLogger {
49- /**
50- * @param {(type: LogTypeEnum, args?: Args) => void } log log function
51- * @param {(name: string | (() => string)) => WebpackLogger } getChildLogger function to create child logger
52- */
53- constructor ( log , getChildLogger ) {
45+ private [ LOG_SYMBOL ] : ( type : LogTypeEnum , args ?: Args ) => void ;
46+ private [ TIMERS_SYMBOL ] : TimersMap = new Map ( ) ;
47+ private [ TIMERS_AGGREGATES_SYMBOL ] : TimersMap = new Map ( ) ;
48+ // @ts -ignore
49+ private getChildLogger : ( name : string | ( ( ) => string ) ) => WebpackLogger ;
50+
51+ constructor (
52+ log : ( type : LogTypeEnum , args ?: Args ) => void ,
53+ getChildLogger : ( name : string | ( ( ) => string ) ) => WebpackLogger ,
54+ ) {
5455 this [ LOG_SYMBOL ] = log ;
5556 this . getChildLogger = getChildLogger ;
5657 }
5758
58- /**
59- * @param {Args } args args
60- */
61- error ( ...args ) {
59+ error ( ...args : Args ) {
6260 this [ LOG_SYMBOL ] ( LogType . error , args ) ;
6361 }
6462
65- /**
66- * @param {Args } args args
67- */
68- warn ( ...args ) {
63+ warn ( ...args : Args ) {
6964 this [ LOG_SYMBOL ] ( LogType . warn , args ) ;
7065 }
7166
72- /**
73- * @param {Args } args args
74- */
75- info ( ...args ) {
67+ info ( ...args : Args ) {
7668 this [ LOG_SYMBOL ] ( LogType . info , args ) ;
7769 }
7870
79- /**
80- * @param {Args } args args
81- */
82- log ( ...args ) {
71+ log ( ...args : Args ) {
8372 this [ LOG_SYMBOL ] ( LogType . log , args ) ;
8473 }
8574
86- /**
87- * @param {Args } args args
88- */
89- debug ( ...args ) {
75+ debug ( ...args : Args ) {
9076 this [ LOG_SYMBOL ] ( LogType . debug , args ) ;
9177 }
9278
93- /**
94- * @param {EXPECTED_ANY } assertion assertion
95- * @param {Args } args args
96- */
97- assert ( assertion , ...args ) {
79+ assert ( assertion : EXPECTED_ANY , ...args : Args ) {
9880 if ( ! assertion ) {
9981 this [ LOG_SYMBOL ] ( LogType . error , args ) ;
10082 }
@@ -108,58 +90,36 @@ class WebpackLogger {
10890 this [ LOG_SYMBOL ] ( LogType . clear ) ;
10991 }
11092
111- /**
112- * @param {Args } args args
113- */
114- status ( ...args ) {
93+ status ( ...args : Args ) {
11594 this [ LOG_SYMBOL ] ( LogType . status , args ) ;
11695 }
11796
118- /**
119- * @param {Args } args args
120- */
121- group ( ...args ) {
97+ group ( ...args : Args ) {
12298 this [ LOG_SYMBOL ] ( LogType . group , args ) ;
12399 }
124100
125- /**
126- * @param {Args } args args
127- */
128- groupCollapsed ( ...args ) {
101+ groupCollapsed ( ...args : Args ) {
129102 this [ LOG_SYMBOL ] ( LogType . groupCollapsed , args ) ;
130103 }
131104
132105 groupEnd ( ) {
133106 this [ LOG_SYMBOL ] ( LogType . groupEnd ) ;
134107 }
135108
136- /**
137- * @param {string= } label label
138- */
139- profile ( label ) {
109+ profile ( label ?: string ) {
140110 this [ LOG_SYMBOL ] ( LogType . profile , [ label ] ) ;
141111 }
142112
143- /**
144- * @param {string= } label label
145- */
146- profileEnd ( label ) {
113+ profileEnd ( label ?: string ) {
147114 this [ LOG_SYMBOL ] ( LogType . profileEnd , [ label ] ) ;
148115 }
149116
150- /**
151- * @param {string } label label
152- */
153- time ( label ) {
154- /** @type {TimersMap } */
117+ time ( label : string ) {
155118 this [ TIMERS_SYMBOL ] = this [ TIMERS_SYMBOL ] || new Map ( ) ;
156119 this [ TIMERS_SYMBOL ] . set ( label , process . hrtime ( ) ) ;
157120 }
158121
159- /**
160- * @param {string= } label label
161- */
162- timeLog ( label ) {
122+ timeLog ( label ?: string ) {
163123 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
164124 if ( ! prev ) {
165125 throw new Error ( `No such label '${ label } ' for WebpackLogger.timeLog()` ) ;
@@ -168,34 +128,26 @@ class WebpackLogger {
168128 this [ LOG_SYMBOL ] ( LogType . time , [ label , ...time ] ) ;
169129 }
170130
171- /**
172- * @param {string= } label label
173- */
174- timeEnd ( label ) {
131+ timeEnd ( label ?: string ) {
175132 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
176133 if ( ! prev ) {
177134 throw new Error ( `No such label '${ label } ' for WebpackLogger.timeEnd()` ) ;
178135 }
179136 const time = process . hrtime ( prev ) ;
180137 /** @type {TimersMap } */
181- ( this [ TIMERS_SYMBOL ] ) . delete ( label ) ;
138+ this [ TIMERS_SYMBOL ] . delete ( label ) ;
182139 this [ LOG_SYMBOL ] ( LogType . time , [ label , ...time ] ) ;
183140 }
184141
185- /**
186- * @param {string= } label label
187- */
188- timeAggregate ( label ) {
142+ timeAggregate ( label ?: string ) {
189143 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
190144 if ( ! prev ) {
191145 throw new Error (
192146 `No such label '${ label } ' for WebpackLogger.timeAggregate()` ,
193147 ) ;
194148 }
195149 const time = process . hrtime ( prev ) ;
196- /** @type {TimersMap } */
197- ( this [ TIMERS_SYMBOL ] ) . delete ( label ) ;
198- /** @type {TimersMap } */
150+ this [ TIMERS_SYMBOL ] . delete ( label ) ;
199151 this [ TIMERS_AGGREGATES_SYMBOL ] =
200152 this [ TIMERS_AGGREGATES_SYMBOL ] || new Map ( ) ;
201153 const current = this [ TIMERS_AGGREGATES_SYMBOL ] . get ( label ) ;
@@ -211,10 +163,7 @@ class WebpackLogger {
211163 this [ TIMERS_AGGREGATES_SYMBOL ] . set ( label , time ) ;
212164 }
213165
214- /**
215- * @param {string= } label label
216- */
217- timeAggregateEnd ( label ) {
166+ timeAggregateEnd ( label ?: string ) {
218167 if ( this [ TIMERS_AGGREGATES_SYMBOL ] === undefined ) return ;
219168 const time = this [ TIMERS_AGGREGATES_SYMBOL ] . get ( label ) ;
220169 if ( time === undefined ) return ;
@@ -223,4 +172,4 @@ class WebpackLogger {
223172 }
224173}
225174
226- module . exports . Logger = WebpackLogger ;
175+ export { WebpackLogger as Logger } ;
0 commit comments