-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove superfluous lodash usage #2938
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,11 @@ | |
|
||
'use strict'; | ||
|
||
const get = require('lodash/get'); | ||
const chalk = require('chalk'); | ||
|
||
module.exports = function printBuildError(err) { | ||
const message = get(err, 'message'); | ||
const stack = get(err, 'stack'); | ||
const message = err != null && err.message; | ||
const stack = err != null && err.stack; | ||
|
||
// Add more helpful message for UglifyJs error | ||
if ( | ||
|
@@ -23,24 +22,22 @@ module.exports = function printBuildError(err) { | |
message.indexOf('from UglifyJs') !== -1 | ||
) { | ||
try { | ||
const matched = /Unexpected token:(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec( | ||
stack | ||
); | ||
const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack); | ||
if (!matched) { | ||
throw new Error( | ||
"The regex pattern is not matched. Maybe UglifyJs changed it's message?" | ||
); | ||
throw new Error('Using errors for control flow is bad.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😺 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm short on time, but anyone who sees this can feel free to submit a PR removing the usage of this error for control flow. |
||
} | ||
const problemPath = matched[2]; | ||
const line = matched[3]; | ||
const column = matched[4]; | ||
console.log( | ||
'Failed to minify the code from this file: \n\n', | ||
chalk.yellow(`${problemPath} line ${line}:${column}`), | ||
chalk.yellow( | ||
`\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might as well hide the column if it's not useful. |
||
), | ||
'\n' | ||
); | ||
} catch (ignored) { | ||
console.log('Failed to minify the code.', err); | ||
console.log('Failed to minify the bundle.', err); | ||
} | ||
console.log('Read more here: http://bit.ly/2tRViJ9'); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other errors (e.g. unknown operator / invalid left hand assignment), so I went for the standard line format from this regex. Seems to work.