@@ -93,10 +93,19 @@ const ERRONEOUS_WARNINGS_FILTER = (warning: string) => ![
93
93
/ S y s t e m .i m p o r t \( \) i s d e p r e c a t e d a n d w i l l b e r e m o v e d s o o n / i,
94
94
] . some ( msg => msg . test ( warning ) ) ;
95
95
96
+ interface WebpackDiagnostic {
97
+ message : string ;
98
+ file ?: string ;
99
+ moduleName ?: string ;
100
+ loc ?: string ;
101
+ }
102
+
96
103
export function statsWarningsToString ( json : any , statsConfig : any ) : string {
97
104
const colors = statsConfig . colors ;
98
- const rs = ( x : string ) => colors ? ansiColors . reset ( x ) : x ;
99
- const y = ( x : string ) => colors ? ansiColors . bold . yellow ( x ) : x ;
105
+ const c = ( x : string ) => colors ? ansiColors . reset . cyan ( x ) : x ;
106
+ const y = ( x : string ) => colors ? ansiColors . reset . yellow ( x ) : x ;
107
+ const yb = ( x : string ) => colors ? ansiColors . reset . yellowBright ( x ) : x ;
108
+
100
109
const warnings = [ ...json . warnings ] ;
101
110
if ( json . children ) {
102
111
warnings . push ( ...json . children
@@ -105,17 +114,45 @@ export function statsWarningsToString(json: any, statsConfig: any): string {
105
114
) ;
106
115
}
107
116
108
- return rs ( '\n' + warnings
109
- . map ( ( warning : any ) => `${ warning } ` )
110
- . filter ( ERRONEOUS_WARNINGS_FILTER )
111
- . map ( ( warning : string ) => y ( `WARNING in ${ warning } ` ) )
112
- . join ( '\n\n' ) ) ;
117
+ let output = '' ;
118
+ for ( const warning of warnings as ( string | WebpackDiagnostic ) [ ] ) {
119
+ if ( typeof warning === 'string' ) {
120
+ if ( ! ERRONEOUS_WARNINGS_FILTER ( warning ) ) {
121
+ continue ;
122
+ }
123
+ output += yb ( `WARNING in ${ warning } \n\n` ) ;
124
+ } else {
125
+ if ( ! ERRONEOUS_WARNINGS_FILTER ( warning . message ) ) {
126
+ continue ;
127
+ }
128
+ const file = warning . file || warning . moduleName ;
129
+ if ( file ) {
130
+ output += c ( file ) ;
131
+ if ( warning . loc ) {
132
+ output += ':' + yb ( warning . loc ) ;
133
+ }
134
+ output += ' - ' ;
135
+ }
136
+ if ( ! / ^ w a r n i n g / i. test ( warning . message ) ) {
137
+ output += y ( 'Warning: ' ) ;
138
+ }
139
+ output += `${ warning . message } \n\n` ;
140
+ }
141
+ }
142
+
143
+ if ( output ) {
144
+ return '\n' + output ;
145
+ }
146
+
147
+ return '' ;
113
148
}
114
149
115
150
export function statsErrorsToString ( json : any , statsConfig : any ) : string {
116
151
const colors = statsConfig . colors ;
117
- const rs = ( x : string ) => colors ? ansiColors . reset ( x ) : x ;
118
- const r = ( x : string ) => colors ? ansiColors . bold . red ( x ) : x ;
152
+ const c = ( x : string ) => colors ? ansiColors . reset . cyan ( x ) : x ;
153
+ const yb = ( x : string ) => colors ? ansiColors . reset . yellowBright ( x ) : x ;
154
+ const r = ( x : string ) => colors ? ansiColors . reset . redBright ( x ) : x ;
155
+
119
156
const errors = [ ...json . errors ] ;
120
157
if ( json . children ) {
121
158
errors . push ( ...json . children
@@ -124,10 +161,31 @@ export function statsErrorsToString(json: any, statsConfig: any): string {
124
161
) ;
125
162
}
126
163
127
- return rs ( '\n' + errors
128
- . map ( ( error : any ) => r ( `ERROR in ${ error } ` ) )
129
- . join ( '\n\n' )
130
- ) ;
164
+ let output = '' ;
165
+ for ( const error of errors as ( string | WebpackDiagnostic ) [ ] ) {
166
+ if ( typeof error === 'string' ) {
167
+ output += r ( `ERROR in ${ error } \n\n` ) ;
168
+ } else {
169
+ const file = error . file || error . moduleName ;
170
+ if ( file ) {
171
+ output += c ( file ) ;
172
+ if ( error . loc ) {
173
+ output += ':' + yb ( error . loc ) ;
174
+ }
175
+ output += ' - ' ;
176
+ }
177
+ if ( ! / ^ e r r o r / i. test ( error . message ) ) {
178
+ output += r ( 'Error: ' ) ;
179
+ }
180
+ output += `${ error . message } \n\n` ;
181
+ }
182
+ }
183
+
184
+ if ( output ) {
185
+ return '\n' + output ;
186
+ }
187
+
188
+ return '' ;
131
189
}
132
190
133
191
export function statsHasErrors ( json : any ) : boolean {
0 commit comments