Skip to content

feat(babel-cli): add a brief summary to build output#7439

Merged
Andarist merged 6 commits intobabel:masterfrom
thymikee:feat/babel-cli-output
Mar 3, 2018
Merged

feat(babel-cli): add a brief summary to build output#7439
Andarist merged 6 commits intobabel:masterfrom
thymikee:feat/babel-cli-output

Conversation

@thymikee
Copy link
Copy Markdown
Contributor

@thymikee thymikee commented Feb 27, 2018

Q                       A
Fixed Issues? Fixes #6303
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR No
Any Dependency Changes? No
License MIT

Adds a brief summary when running babel-cli. It displays even when --quiet flag is passed.
screen shot 2018-02-27 at 12 38 49

cc @hzoo @Andarist

function(err, res) {
if (err) return callback(err);
if (err) {
result.failure += 1;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For now I gather failures count, but don't use them anywhere. Happy to remove this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what happens when error occurs here? i suspect it crash whole process, right? in other words - can failure increase beyond 1 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It forwards the error object and crashes here with non-zero exit code. I don't use failures anywhere now (I used to show number of failed files but decided it's not necessary, as usually babel just crash the whole thing)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we could remove counting failure then and convert result to a "flat" counter of successes, would give future readers a clear purpose for this, with unused failures it might be a little bit unclear


handle(filename, function(err) {
if (err) throw err;
if (err) throw err.toString();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the stack trace of build errors isn't very helpful (lots of internal Babel stuff not necessarily helpful to the end user), I've decided to use only the stringified message. It works well on Node >=8. Node <=6 produces a totally unhelpful message anyway 🤷‍♂️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it a common practice in other CLI tools? is this error here crashing the process directly & going right into stderr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, crashes entire thing. Throwing err.toString() is definitely not something common, usually you end up creating your own error extending from Error and override stacktrace if necessary, for better error messages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so if this is direct exit point of the program & to avoid throwing non error it could be converted to smth like:

console.error(err.toString())
process.exit(1)

although im not entirely convinced that this is a good change, logged value is still logged currently, right? Only with less-readable for most users stack trace. Personally I often take such stack traces and go into my node_modules to get better understanding of what happened if the error message is not descriptive enough (which is most of the times 😉)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just noticed we throw raw error without wrapping it with an Error object. I've pushed a change to adjust that

Here's how it looks now:
screen shot 2018-02-27 at 23 41 15

imho better than:
screen shot 2018-02-27 at 23 42 23

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Definitely better!

@@ -1 +1,2 @@
src/index.js -> lib/index.js
Successfully compiled 1 file.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought about putting this into stderr instead of stdout (I wouldn't need to adjust all tests, just add a new one), but based on experience in Jest CLI, I'd rather avoid that, as users tend to abuse this stream for catching their own errors or such.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

stdout is imho a perfect place for this, stderr implies some kind of error, warning at least, and this is a regular info message

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Feb 27, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7043/

@existentialism existentialism added PR: New Feature 🚀 A type of pull request used for our changelog categories pkg: cli labels Feb 27, 2018

export function log(msg) {
if (!commander.quiet) console.log(msg);
export function log(msg, alwaysLog) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit picking: i think always would suffice here


handle(filename, function(err) {
if (err) throw err;
if (err) throw Error(err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this probably should be a new Error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While they might be equivalent, it's most commonly used as a constructor - I'd prefer to new it for consistency.

Copy link
Copy Markdown
Member

@Andarist Andarist left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and putting up with my nit picking.

@existentialism
Copy link
Copy Markdown
Member

Just spitballing, but any thoughts on prefixing the message (and maybe all other logs/errors from Babel)?

Babel: 🎉 Successfully compiled 1,492 files.

Might help with searching/parsing logs, or helping users understand where errors are coming from? Just thinking aloud :)

@thymikee
Copy link
Copy Markdown
Contributor Author

I was thinking of adding an emoji too! But it looked weird with Yarn output (unprefixed), because they use 2 spaces:

🎉 Successfully compiled 1,492 files.
✨  Done in 0.72s.

Not sure about prefixing though, it's not something I've seen in the wild tbh.

How about this (also aligning with Yarn):

🎉  Successfully compiled 1,492 files with Babel.
✨  Done in 0.72s.

web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" }
src/in2.js -> lib/in2.js No newline at end of file
src/in2.js -> lib/in2.js
🎉 successfully compil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems off, the line got splitted into 2, some other stdout.txt suffer from the same thing, any idea why this happens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

huh, that's just my regex not playing the way I liked. Weird that test didn't caught it (at least locally)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I was scoping my testing to babel-cli only, I'll update this shortly

delete opts.copyFiles;
delete opts.includeDotfiles;
delete opts.quiet;
delete opts.verbose;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

was this change requested somewhere? whats the motivation behind it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

discussed here: #6303 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@thymikee
Copy link
Copy Markdown
Contributor Author

thymikee commented Mar 1, 2018

npm:
screen shot 2018-03-01 at 22 45 24

yarn:
screen shot 2018-03-01 at 22 45 36

@Andarist
Copy link
Copy Markdown
Member

Andarist commented Mar 1, 2018

The only thing missing (I think) is like at least a single test covering default mode, right? (i dont see any test converted from previously quiet to now default)

@@ -1,2 +1 @@
src/bar/bar.js -> lib/bar/bar.js
src/foo.js -> lib/foo.js
🎉 Successfully compiled 2 files with Babel.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Andarist, here is the default without --verbose flag

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 disregard my comment then

web.immediate { "android":"4" }
web.dom.iterable { "android":"4" }
src/in.js -> lib/in.js No newline at end of file
🎉 Successfully compiled 1 file with Babel.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, all tests in babel-preset-env cover default quiet mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@thymikee
Copy link
Copy Markdown
Contributor Author

thymikee commented Mar 1, 2018

Travis failure seems unrelated.

@existentialism
Copy link
Copy Markdown
Member

@thymikee it almost certainly is, those particular tests have been finicky lately, haven't had a chance to look into it much. restarted it tho!

"Include dotfiles when compiling and copying non-compilable files",
);
commander.option("-q, --quiet", "Don't log anything");
commander.option("-v, --verbose", "Log everything");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, what do you think about the alias – should it be -v or maybe no alias at all? At least it doesn't collide with anything right now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, havent spotted that yesterday - I think verbose is not like the most wanted/common thing and it might not deserve alias just yet, especially that -v is most commonly used for version in other tools.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed it

@xtuc
Copy link
Copy Markdown
Member

xtuc commented Jul 2, 2018

Sorry I missed this PR and it's a while ago. I noticed that the flag --quiet has been renamed, people that relied on that flag will now get an error? It's a breaking change.

Also we'd like to remove the emojis #8250.

@thymikee
Copy link
Copy Markdown
Contributor Author

thymikee commented Jul 2, 2018

I noticed that the flag --quiet has been renamed, people that relied on that flag will now get an error? It's a breaking change.

Not sure about how CLI handles unknown flags passed to it. If it errors, then it's a breaking change – to unbreak it, we could add the --quiet flag back which would do nothing at the moment, and be there for future updates.

@Andarist
Copy link
Copy Markdown
Member

Andarist commented Jul 2, 2018

As removal of --quiet was merged only to beta line, I would assume it's OK for it to be a breaking change. If we do not need it right now then it doesn't seem necessary to add it only to avoid a breaking change in this situation. We might want to document this change though as breaking one.

@xtuc
Copy link
Copy Markdown
Member

xtuc commented Jul 2, 2018

I tried using 7.0.0-beta.51 (@babel/core 7.0.0-beta.51), passing an unknown flag returns an error and an exit code 1. It's a breaking change, even if it's since Babel 7 we should communicate accordingly.

IMO we should rather not introduce unnecessary breaking changes.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: cli PR: New Feature 🚀 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In babel-cli add a short log option when compiling

5 participants