|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const get = require('lodash/get'); |
| 13 | +const chalk = require('chalk'); |
| 14 | + |
| 15 | +module.exports = function printBuildError(err) { |
| 16 | + const message = get(err, 'message'); |
| 17 | + const stack = get(err, 'stack'); |
| 18 | + |
| 19 | + // Add more helpful message for UglifyJs error |
| 20 | + if ( |
| 21 | + stack && |
| 22 | + typeof message === 'string' && |
| 23 | + message.indexOf('from UglifyJs') !== -1 |
| 24 | + ) { |
| 25 | + try { |
| 26 | + const matched = /Unexpected token:(.+)\[(.+)\:(.+)\,(.+)\]\[.+\]/.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]; |
| 37 | + console.log( |
| 38 | + 'Failed to minify the code from this file: \n\n', |
| 39 | + chalk.yellow(`${problemPath} line ${line}:${column}`), |
| 40 | + '\n' |
| 41 | + ); |
| 42 | + } catch (ignored) { |
| 43 | + console.log('Failed to minify the code.', err); |
| 44 | + } |
| 45 | + console.log('Read more here: http://bit.ly/2tRViJ9'); |
| 46 | + } else { |
| 47 | + console.log((message || err) + '\n'); |
| 48 | + } |
| 49 | + console.log(); |
| 50 | +}; |
0 commit comments