9
9
10
10
'use strict' ;
11
11
12
- const get = require ( 'lodash/get' ) ;
13
12
const chalk = require ( 'chalk' ) ;
14
13
15
14
module . exports = function printBuildError ( err ) {
16
- const message = get ( err , ' message' ) ;
17
- const stack = get ( err , ' stack' ) ;
15
+ const message = err != null && err . message ;
16
+ const stack = err != null && err . stack ;
18
17
19
18
// Add more helpful message for UglifyJs error
20
19
if (
@@ -23,24 +22,22 @@ module.exports = function printBuildError(err) {
23
22
message . indexOf ( 'from UglifyJs' ) !== - 1
24
23
) {
25
24
try {
26
- const matched = / U n e x p e c t e d t o k e n : ( .+ ) \[ ( .+ ) : ( .+ ) , ( .+ ) \] \[ .+ \] / . exec (
27
- stack
28
- ) ;
25
+ const matched = / ( .+ ) \[ ( .+ ) : ( .+ ) , ( .+ ) \] \[ .+ \] / . exec ( stack ) ;
29
26
if ( ! matched ) {
30
- throw new Error (
31
- "The regex pattern is not matched. Maybe UglifyJs changed it's message?"
32
- ) ;
27
+ throw new Error ( 'Using errors for control flow is bad.' ) ;
33
28
}
34
29
const problemPath = matched [ 2 ] ;
35
30
const line = matched [ 3 ] ;
36
31
const column = matched [ 4 ] ;
37
32
console . log (
38
33
'Failed to minify the code from this file: \n\n' ,
39
- chalk . yellow ( `${ problemPath } line ${ line } :${ column } ` ) ,
34
+ chalk . yellow (
35
+ `\t${ problemPath } :${ line } ${ column !== '0' ? ':' + column : '' } `
36
+ ) ,
40
37
'\n'
41
38
) ;
42
39
} catch ( ignored ) {
43
- console . log ( 'Failed to minify the code .' , err ) ;
40
+ console . log ( 'Failed to minify the bundle .' , err ) ;
44
41
}
45
42
console . log ( 'Read more here: http://bit.ly/2tRViJ9' ) ;
46
43
} else {
0 commit comments