99
1010'use strict' ;
1111
12- const get = require ( 'lodash/get' ) ;
1312const chalk = require ( 'chalk' ) ;
1413
1514module . 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 ;
1817
1918 // Add more helpful message for UglifyJs error
2019 if (
@@ -23,24 +22,22 @@ module.exports = function printBuildError(err) {
2322 message . indexOf ( 'from UglifyJs' ) !== - 1
2423 ) {
2524 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 ) ;
2926 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.' ) ;
3328 }
3429 const problemPath = matched [ 2 ] ;
3530 const line = matched [ 3 ] ;
3631 const column = matched [ 4 ] ;
3732 console . log (
3833 '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+ ) ,
4037 '\n'
4138 ) ;
4239 } catch ( ignored ) {
43- console . log ( 'Failed to minify the code .' , err ) ;
40+ console . log ( 'Failed to minify the bundle .' , err ) ;
4441 }
4542 console . log ( 'Read more here: http://bit.ly/2tRViJ9' ) ;
4643 } else {
0 commit comments