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
fix: prevent version name collision #1986
Conversation
throw new YError( | ||
[ | ||
'"version" is a reserved word.', | ||
'Please do one of the following:', |
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 throwing an error is too heavy handed, as it would break a lot of applications. Here's what I would do:
- emit a custom warning with a similar message to this, using the approach described here. We should make sure that we don't show it more than once, using the approach outlined in the docs.
- I think we should turn off our own handling of
.version()
if someone configures it themselves, which the warning message can draw attention to.
What I'm not sure of, is whether we should call this a breaking change.
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.
Questions
- Would emitting a warning be sufficient? It would keep this from becoming a breaking change.
- I left
process.emitWarning
as a noop in the deno shim. Is there a deno equivalent that I can use instead? - I left type and deduplicationID separate, so that
process.emitWarning
can be called without a type, but still prevent duplicate warnings. Does that make sense? - I didn't know what values to use for type/deduplicationID -- can I get your suggestions?
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.
see comments.
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.
This seems like a really solid work to me 👍 , thank you. I'm sure we'll get additional usage out of emitWarning
.
My only concern is if a major project, e.g., mocha
, starts emitting on this warning, and we get a ton of users complaining on yargs.
I'm comfortable with shipping this, and keeping an eye on issues opened against yargs.
Addresses: #1979 and #1864
Problem
"version" can be passed as a key to
yargs.option()
, but this messes up parsing.The
yargs.version()
method already occupies that namespace.This code
produces this result:
Solution
I added a check in
yargs.option
that willthrow an erroremit a warning if an option (or its alias) is "version", unless they disabled version withyargs.version(false)
.