Skip to content
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

Merged
merged 1 commit into from
Aug 10, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/react-dev-utils/printBuildError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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);
Copy link
Contributor Author

@Timer Timer Aug 10, 2017

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.

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.');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😺

Copy link
Contributor Author

@Timer Timer Aug 10, 2017

Choose a reason for hiding this comment

The 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 : ''}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand Down