File tree 1 file changed +20
-6
lines changed
1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -14,18 +14,32 @@ const chalk = require('chalk');
14
14
15
15
module . exports = function formatBuildError ( err ) {
16
16
const message = get ( err , 'message' ) ;
17
+ const stack = get ( err , 'stack' ) ;
17
18
18
19
// Add more helpful message for UglifyJs error
19
- if ( typeof message === 'string' && message . indexOf ( 'from UglifyJs' ) !== - 1 ) {
20
+ if (
21
+ stack &&
22
+ typeof message === 'string' &&
23
+ message . indexOf ( 'from UglifyJs' ) !== - 1
24
+ ) {
20
25
try {
26
+ const matched = / U n e x p e c t e d t o k e n : ( .+ ) \[ ( .+ ) \: ( .+ ) \, ( .+ ) \] \[ .+ \] / . exec (
27
+ stack
28
+ ) ;
29
+ if ( ! matched ) {
30
+ throw new Error (
31
+ "The regex pattern is not matched. Maybe UglifyJs changed it's message?"
32
+ ) ;
33
+ }
34
+ const problemPath = matched [ 2 ] ;
35
+ const line = matched [ 3 ] ;
36
+ const column = matched [ 4 ] ;
21
37
console . log (
22
- 'Failed to minify the code from \n\n' ,
23
- chalk . yellow (
24
- / U n e x p e c t e d t o k e n : ( .+ ) \[ ( .+ ) \] \[ ( .+ ) \] / . exec ( err . stack ) [ 2 ]
25
- ) ,
38
+ 'Failed to minify the code from this file: \n\n' ,
39
+ chalk . yellow ( `${ problemPath } line ${ line } :${ column } ` ) ,
26
40
'\n'
27
41
) ;
28
- } catch ( e ) {
42
+ } catch ( ignored ) {
29
43
console . log ( 'Failed to minify the code.' , err ) ;
30
44
}
31
45
console . log (
You can’t perform that action at this time.
0 commit comments