@@ -2,17 +2,21 @@ import type { StatsError } from '@rspack/core';
22import { removeLoaderChainDelimiter } from './stats' ;
33import { color } from './vendors' ;
44
5- const formatFileName = ( fileName : string ) => {
5+ const formatFileName = ( fileName : string , stats : StatsError ) => {
66 // File name may be empty when the error is not related to a file.
77 // For example, when an invalid entry is provided.
88 if ( ! fileName ) {
99 return '' ;
1010 }
1111
12+ if ( / : \d + : \d + / . test ( fileName ) ) {
13+ return `File: ${ color . cyan ( fileName ) } \n` ;
14+ }
15+ if ( stats . loc ) {
16+ return `File: ${ color . cyan ( `${ fileName } :${ stats . loc } ` ) } \n` ;
17+ }
1218 // add default column add lines for linking
13- return / : \d + : \d + / . test ( fileName )
14- ? `File: ${ color . cyan ( fileName ) } \n`
15- : `File: ${ color . cyan ( `${ fileName } :1:1` ) } \n` ;
19+ return `File: ${ color . cyan ( `${ fileName } :1:1` ) } \n` ;
1620} ;
1721
1822function resolveFileName ( stats : StatsError ) {
@@ -228,8 +232,7 @@ export function formatStatsError(stats: StatsError, verbose?: boolean): string {
228232 verbose && stats . details ? `\nDetails: ${ stats . details } \n` : '' ;
229233 const stack = verbose && stats . stack ? `\n${ stats . stack } ` : '' ;
230234 const moduleTrace = formatModuleTrace ( stats , fileName ) ?? '' ;
231- const loc = stats . loc ? `:${ stats . loc } ` : '' ;
232- message = `${ formatFileName ( fileName + loc ) } ${ mainMessage } ${ details } ${ stack } ${ moduleTrace } ` ;
235+ message = `${ formatFileName ( fileName , stats ) } ${ mainMessage } ${ details } ${ stack } ${ moduleTrace } ` ;
233236
234237 // Remove inner error message
235238 const innerError = '-- inner error --' ;
0 commit comments