feat(babel-cli): add a brief summary to build output#7439
feat(babel-cli): add a brief summary to build output#7439Andarist merged 6 commits intobabel:masterfrom
Conversation
packages/babel-cli/src/babel/dir.js
Outdated
| function(err, res) { | ||
| if (err) return callback(err); | ||
| if (err) { | ||
| result.failure += 1; |
There was a problem hiding this comment.
For now I gather failures count, but don't use them anywhere. Happy to remove this.
There was a problem hiding this comment.
what happens when error occurs here? i suspect it crash whole process, right? in other words - can failure increase beyond 1 here?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
packages/babel-cli/src/babel/dir.js
Outdated
|
|
||
| handle(filename, function(err) { | ||
| if (err) throw err; | ||
| if (err) throw err.toString(); |
There was a problem hiding this comment.
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 🤷♂️
There was a problem hiding this comment.
Is it a common practice in other CLI tools? is this error here crashing the process directly & going right into stderr?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😉)
| @@ -1 +1,2 @@ | |||
| src/index.js -> lib/index.js | |||
| Successfully compiled 1 file. | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
stdout is imho a perfect place for this, stderr implies some kind of error, warning at least, and this is a regular info message
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7043/ |
packages/babel-cli/src/babel/util.js
Outdated
|
|
||
| export function log(msg) { | ||
| if (!commander.quiet) console.log(msg); | ||
| export function log(msg, alwaysLog) { |
There was a problem hiding this comment.
nit picking: i think always would suffice here
packages/babel-cli/src/babel/dir.js
Outdated
|
|
||
| handle(filename, function(err) { | ||
| if (err) throw err; | ||
| if (err) throw Error(err); |
There was a problem hiding this comment.
this probably should be a new Error
There was a problem hiding this comment.
There was a problem hiding this comment.
While they might be equivalent, it's most commonly used as a constructor - I'd prefer to new it for consistency.
Andarist
left a comment
There was a problem hiding this comment.
Thanks for the PR and putting up with my nit picking.
|
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 :) |
|
I was thinking of adding an emoji too! But it looked weird with Yarn output (unprefixed), because they use 2 spaces: Not sure about prefixing though, it's not something I've seen in the wild tbh. How about this (also aligning with Yarn): |
| 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 |
There was a problem hiding this comment.
this seems off, the line got splitted into 2, some other stdout.txt suffer from the same thing, any idea why this happens?
There was a problem hiding this comment.
huh, that's just my regex not playing the way I liked. Weird that test didn't caught it (at least locally)?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
was this change requested somewhere? whats the motivation behind it?
|
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. | |||
There was a problem hiding this comment.
@Andarist, here is the default without --verbose flag
| 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. |
There was a problem hiding this comment.
Also, all tests in babel-preset-env cover default quiet mode.
|
Travis failure seems unrelated. |
|
@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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* feat(babel-cli): add a brief summary to build output * address feedback * further adjustments * Use quiet output as default, add --verbose * fix tests * remove verbose alias
|
Sorry I missed this PR and it's a while ago. I noticed that the flag Also we'd like to remove the emojis #8250. |
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 |
|
As removal of |
|
I tried using IMO we should rather not introduce unnecessary breaking changes. |




Adds a brief summary when running

babel-cli. It displays even when--quietflag is passed.cc @hzoo @Andarist