88 * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
99 */
1010
11- // @ts -nocheck
12-
13- 'use strict' ;
14-
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
21-
22- trace : /** @type {"trace" } */ ( 'trace' ) , // no arguments
23-
24- group : /** @type {"group" } */ ( 'group' ) , // [label]
25- groupCollapsed : /** @type {"groupCollapsed" } */ ( 'groupCollapsed' ) , // [label]
26- groupEnd : /** @type {"groupEnd" } */ ( 'groupEnd' ) , // [label]
27-
28- profile : /** @type {"profile" } */ ( 'profile' ) , // [profileName]
29- profileEnd : /** @type {"profileEnd" } */ ( 'profileEnd' ) , // [profileName]
30-
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
35- } ) ;
36-
37- module . exports . LogType = LogType ;
38-
39- /** @typedef {typeof LogType[keyof typeof LogType] } LogTypeEnum */
40- /** @typedef {Map<string | undefined, [number, number]> } TimersMap */
11+ import {
12+ LogType ,
13+ type Args ,
14+ type EXPECTED_ANY ,
15+ type LogTypeEnum ,
16+ type TimersMap ,
17+ } from '../types' ;
4118
4219const LOG_SYMBOL = Symbol ( 'webpack logger raw log method' ) ;
4320const TIMERS_SYMBOL = Symbol ( 'webpack logger times' ) ;
4421const TIMERS_AGGREGATES_SYMBOL = Symbol ( 'webpack logger aggregated times' ) ;
4522
46- /** @typedef {EXPECTED_ANY[] } Args */
47-
4823class 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 ) {
24+ private [ LOG_SYMBOL ] : ( type : LogTypeEnum , args ?: Args ) => void ;
25+ private [ TIMERS_SYMBOL ] : TimersMap = new Map ( ) ;
26+ private [ TIMERS_AGGREGATES_SYMBOL ] : TimersMap = new Map ( ) ;
27+ // @ts -ignore
28+ private getChildLogger : ( name : string | ( ( ) => string ) ) => WebpackLogger ;
29+
30+ constructor (
31+ log : ( type : LogTypeEnum , args ?: Args ) => void ,
32+ getChildLogger : ( name : string | ( ( ) => string ) ) => WebpackLogger ,
33+ ) {
5434 this [ LOG_SYMBOL ] = log ;
5535 this . getChildLogger = getChildLogger ;
5636 }
5737
58- /**
59- * @param {Args } args args
60- */
61- error ( ...args ) {
38+ error ( ...args : Args ) {
6239 this [ LOG_SYMBOL ] ( LogType . error , args ) ;
6340 }
6441
65- /**
66- * @param {Args } args args
67- */
68- warn ( ...args ) {
42+ warn ( ...args : Args ) {
6943 this [ LOG_SYMBOL ] ( LogType . warn , args ) ;
7044 }
7145
72- /**
73- * @param {Args } args args
74- */
75- info ( ...args ) {
46+ info ( ...args : Args ) {
7647 this [ LOG_SYMBOL ] ( LogType . info , args ) ;
7748 }
7849
79- /**
80- * @param {Args } args args
81- */
82- log ( ...args ) {
50+ log ( ...args : Args ) {
8351 this [ LOG_SYMBOL ] ( LogType . log , args ) ;
8452 }
8553
86- /**
87- * @param {Args } args args
88- */
89- debug ( ...args ) {
54+ debug ( ...args : Args ) {
9055 this [ LOG_SYMBOL ] ( LogType . debug , args ) ;
9156 }
9257
93- /**
94- * @param {EXPECTED_ANY } assertion assertion
95- * @param {Args } args args
96- */
97- assert ( assertion , ...args ) {
58+ assert ( assertion : EXPECTED_ANY , ...args : Args ) {
9859 if ( ! assertion ) {
9960 this [ LOG_SYMBOL ] ( LogType . error , args ) ;
10061 }
@@ -108,58 +69,36 @@ class WebpackLogger {
10869 this [ LOG_SYMBOL ] ( LogType . clear ) ;
10970 }
11071
111- /**
112- * @param {Args } args args
113- */
114- status ( ...args ) {
72+ status ( ...args : Args ) {
11573 this [ LOG_SYMBOL ] ( LogType . status , args ) ;
11674 }
11775
118- /**
119- * @param {Args } args args
120- */
121- group ( ...args ) {
76+ group ( ...args : Args ) {
12277 this [ LOG_SYMBOL ] ( LogType . group , args ) ;
12378 }
12479
125- /**
126- * @param {Args } args args
127- */
128- groupCollapsed ( ...args ) {
80+ groupCollapsed ( ...args : Args ) {
12981 this [ LOG_SYMBOL ] ( LogType . groupCollapsed , args ) ;
13082 }
13183
13284 groupEnd ( ) {
13385 this [ LOG_SYMBOL ] ( LogType . groupEnd ) ;
13486 }
13587
136- /**
137- * @param {string= } label label
138- */
139- profile ( label ) {
88+ profile ( label ?: string ) {
14089 this [ LOG_SYMBOL ] ( LogType . profile , [ label ] ) ;
14190 }
14291
143- /**
144- * @param {string= } label label
145- */
146- profileEnd ( label ) {
92+ profileEnd ( label ?: string ) {
14793 this [ LOG_SYMBOL ] ( LogType . profileEnd , [ label ] ) ;
14894 }
14995
150- /**
151- * @param {string } label label
152- */
153- time ( label ) {
154- /** @type {TimersMap } */
96+ time ( label : string ) {
15597 this [ TIMERS_SYMBOL ] = this [ TIMERS_SYMBOL ] || new Map ( ) ;
15698 this [ TIMERS_SYMBOL ] . set ( label , process . hrtime ( ) ) ;
15799 }
158100
159- /**
160- * @param {string= } label label
161- */
162- timeLog ( label ) {
101+ timeLog ( label ?: string ) {
163102 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
164103 if ( ! prev ) {
165104 throw new Error ( `No such label '${ label } ' for WebpackLogger.timeLog()` ) ;
@@ -168,34 +107,26 @@ class WebpackLogger {
168107 this [ LOG_SYMBOL ] ( LogType . time , [ label , ...time ] ) ;
169108 }
170109
171- /**
172- * @param {string= } label label
173- */
174- timeEnd ( label ) {
110+ timeEnd ( label ?: string ) {
175111 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
176112 if ( ! prev ) {
177113 throw new Error ( `No such label '${ label } ' for WebpackLogger.timeEnd()` ) ;
178114 }
179115 const time = process . hrtime ( prev ) ;
180116 /** @type {TimersMap } */
181- ( this [ TIMERS_SYMBOL ] ) . delete ( label ) ;
117+ this [ TIMERS_SYMBOL ] . delete ( label ) ;
182118 this [ LOG_SYMBOL ] ( LogType . time , [ label , ...time ] ) ;
183119 }
184120
185- /**
186- * @param {string= } label label
187- */
188- timeAggregate ( label ) {
121+ timeAggregate ( label ?: string ) {
189122 const prev = this [ TIMERS_SYMBOL ] && this [ TIMERS_SYMBOL ] . get ( label ) ;
190123 if ( ! prev ) {
191124 throw new Error (
192125 `No such label '${ label } ' for WebpackLogger.timeAggregate()` ,
193126 ) ;
194127 }
195128 const time = process . hrtime ( prev ) ;
196- /** @type {TimersMap } */
197- ( this [ TIMERS_SYMBOL ] ) . delete ( label ) ;
198- /** @type {TimersMap } */
129+ this [ TIMERS_SYMBOL ] . delete ( label ) ;
199130 this [ TIMERS_AGGREGATES_SYMBOL ] =
200131 this [ TIMERS_AGGREGATES_SYMBOL ] || new Map ( ) ;
201132 const current = this [ TIMERS_AGGREGATES_SYMBOL ] . get ( label ) ;
@@ -211,10 +142,7 @@ class WebpackLogger {
211142 this [ TIMERS_AGGREGATES_SYMBOL ] . set ( label , time ) ;
212143 }
213144
214- /**
215- * @param {string= } label label
216- */
217- timeAggregateEnd ( label ) {
145+ timeAggregateEnd ( label ?: string ) {
218146 if ( this [ TIMERS_AGGREGATES_SYMBOL ] === undefined ) return ;
219147 const time = this [ TIMERS_AGGREGATES_SYMBOL ] . get ( label ) ;
220148 if ( time === undefined ) return ;
@@ -223,4 +151,4 @@ class WebpackLogger {
223151 }
224152}
225153
226- module . exports . Logger = WebpackLogger ;
154+ export { WebpackLogger as Logger } ;
0 commit comments