-
Notifications
You must be signed in to change notification settings - Fork 263
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
Replace npmlog
with consola
#829
base: master
Are you sure you want to change the base?
Conversation
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.
Amazing! Thank you!!
@br0p0p would you be able to fix the merge conflict? |
@benmccann done |
// eslint-disable-next-line node/no-missing-require | ||
const { createConsola } = require('consola/basic'); | ||
|
||
const log = createConsola({ stdout: process.stderr }); |
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.
why put all output to stderr
? that seems surprising. if we keep it we should at least add a comment to explain
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.
I did this to maintain the default behavior of npmlog
. See here and the README
Not exactly sure why this was the default
Probably a good call to add a comment at least. Maybe stderr
makes sense here since the logger outputs more debugging type output and console.log()
is used for user-facing output?
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.
I think we should remove this rather than trying to maintain the behavior of npmlog
. I checked (see below) and consola
logs warnings and errors to stderr and info type logs to stdout, which seems like what I'd want and expect out of a logging system. Let's just check that we're setting the log levels appropriately whenever we do logging - I left one comment where I think we should do log.error
to make sure an error goes to stdout
https://github.com/unjs/consola/blob/713ec3454889bf967e9c694bf800955f1cd60e52/src/reporters/basic.ts#L70
https://github.com/unjs/consola/blob/713ec3454889bf967e9c694bf800955f1cd60e52/src/constants.ts#L23
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.
Sure thing. Updated.
My thinking was to prevent potentially breaking dependents which rely on the stderr
output for whatever reason but I agree that not using stderr
for everything makes sense
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.
The main reason that most logging from npm
and node-gyp
goes to stderr (even now that neither use npmlog
) is that stdout is reserved for output that is expected to be used programmatically (usually json). We don't usually swap which output stream is used based on flags like --json
so the default is to place all logging on stderr so that if a json command is piped to something like jq
the logging won't inadvertently create invalid json.
There are a lot of gray areas to this rule and this is something I spent a lot of time figuring out for npm
in the past. I haven't actually review this code (yet) so I'm not saying that all output should be put on stderr, just that as a default stderr is usually better than stdout for CLI logging output.
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.
Thanks for this context @lukekarrys. Thoughts @benmccann?
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.
I have no objection to stderr
given that additional context. If @lukekarrys thinks it's the way to go I'll defer to him on that
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.
@br0p0p do you want to change this back to use stderr
by default? It might be the safer option to avoid changing that
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.
@benmccann sure, no problem
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.
lgtm except that it looks like the appveyor tests might be failing
@cclauss could you kick off the github actions tests on this PR?
@br0p0p I'm afraid all the CI jobs are failing with this PR. would you be able to take a look? |
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.
Hoping this gets merged soon. Thank you for your work! 🍻 |
This PR replaces the deprecated and dependency-laden
npmlog
with a smaller, modern alternative:consola
.npmlog
consola
Extrapolating based on the download stats for
@mapbox/node-pre-gyp
(5,730,435 downloads per week), this migration will have the following effects on the ecosystem as a whole:package-size-calculator
outputI will note that the output looks slightly different with these changes. Happy to update if the new format is not great
Before
After