Skip to content

Conversation

mdvorak
Copy link
Contributor

@mdvorak mdvorak commented Mar 13, 2025

Don't use console.log for logging, as it outputs to stdout instead of stderr.

When used from scripts, it is impossible to use e. g. release-it --release-version --increment major with conventional-changelog, because that outputs

VERSION=WARNING The recommended bump is "minor", but is overridden with "major".
1.0.0

instead of two streams, and version only in stdout.

I've checked that --release-version and --changelog arguments already use (correctly) console.log directly, and I've replaced log for cli commands.

@mdvorak mdvorak marked this pull request as ready for review March 13, 2025 13:31
@mdvorak
Copy link
Contributor Author

mdvorak commented Mar 13, 2025

If you would consider this change too much, less obtrusive variant would be replace it only for warn (and possibly info), and leave log method outputting to stdout.

Copy link

pkg-pr-new bot commented Mar 13, 2025

Open in Stackblitz

npm i https://pkg.pr.new/release-it@1207

commit: f897fdb

@webpro
Copy link
Collaborator

webpro commented Mar 13, 2025

Don't use console.log for logging, as it outputs to stdout instead of stderr.

I guess it depends on exactly what output we're talking about. Not ALL logging must go to stderr. What specifically is problematic or incorrect?

When used from scripts, it is impossible to use e. g. release-it --release-version --increment major with conventional-changelog, because that outputs

VERSION=WARNING The recommended bump is "minor", but is overridden with "major".
1.0.0

instead of two streams, and version only in stdout.

I would agree that the first line with the warning should not go to stdout, if that's what you mean?

I've checked that --release-version and --changelog arguments already use (correctly) console.log directly, and I've replaced log for cli commands.

There's a separate --ci mode which is automatically enabled in CI environments.

The default mode will ask feedback from the user and print changelog, etc. - this could go to stdout just fine I'd say.

If you would consider this change too much, less obtrusive variant would be replace it only for warn (and possibly info), and leave log method outputting to stdout.

It's a bit much indeed, but the good thing is that your timing is great as we're heading towards a new v19 which could introduce potentially breaking changes like this. Please consider this my initial review, I'll give it a closer look when I can.

@mdvorak
Copy link
Contributor Author

mdvorak commented Mar 13, 2025

OK, so proposed variant would be:

Log warnings and info to stderr, but log() method should still print to stdout, to follow console own behavior. I'll verify usage in the code.

This should work fine in CI, since commands that are useful in shell scripts should not use log(), even in nested code (I'll also verify this).

@webpro
Copy link
Collaborator

webpro commented Mar 14, 2025

Sounds like a plan to me! 👍 I won't have time today to review or work on things, but certainly within a few days.

@mdvorak
Copy link
Contributor Author

mdvorak commented Mar 18, 2025

Pushed updated version, plus I've added process.exit(1) for --release-version and --changelog, if the command failed. Otherwise it prints either empty string, or worse, "undefined".

console.log(version);
process.exit(0);
if (version) {
console.log(version);
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I like the idea and result of this all, here's a bit of a nitpick: why not use the Log class here anymore? In my mind, the Log class for logging, to abstract away stdout vs stderr and no need to use console.* directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it is not logging, its direct output of the command. But it does not really matter, I did the changes incrementally, and with final version, its not needed to modify this file anymore.

Don't use console.log for logging diagnostic, as it outputs to stdout instead of stderr, and is not compatible with shell usage.
@webpro
Copy link
Collaborator

webpro commented Mar 25, 2025

Fixed conflicts after merging another branch to main.

@webpro webpro merged commit 5913ae2 into release-it:main Mar 25, 2025
10 checks passed
@webpro
Copy link
Collaborator

webpro commented Mar 25, 2025

Thanks, Michal! Much appreciated.

@webpro
Copy link
Collaborator

webpro commented Mar 26, 2025

🚀 This pull request is included in v19.0.0-next.2. See Release 19.0.0-next.2 for release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants