-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add private flag for yarn init command #4165
Conversation
{ | ||
key: 'private', | ||
question: 'private', | ||
default: '', |
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.
Could also add validation
and validationError
fields to ensure the user enters something that "yn" can convert to boolean (or only accept "true" and "false" and eliminate the dependency on "yn").
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 1
i shorter way user want to fill this key, so i use yn
. And everything can be become a boolean when we use yn
. So, if users want to change it, they can change it later by edit package.json
file. Just boolean
value is approved.
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 is a valid point. I was thinking yn might error if the user types in something like "i guess so" as the answer, but I suspect it will just try to convert it anyway. As long as yn doesn't throw an exception, then I would be OK with no validation.
{ | ||
key: 'private', | ||
question: 'private', | ||
default: '', |
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.
If the default was default: defaultFlag ? 'true' : 'false'
then it would eliminate a conditional below
If the above change is not done, the default should probably be "false" instead of empty string so that when the question is printed to the user they can see that it is explicitly false by default. Empty string might make someone question if the default is actually going to end up true or false (in reality it depends how "yn" interprets empty string)
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 keep ''
because we don't need add line private: {boolean}
into package.json
If users don't set value for private when they run: yarn init
. And one thing, true
and false
are a boolean
value, not a string
, so I don't wrapper it in ''
.
if (def) { | ||
question += ` (${def})`; | ||
question += ` (${def.toString()})`; |
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 the additional .toString()
?
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.
because after i add this flag, def
could be string
or possibly boolean
. I want to make sure it will be a string
when added to question
.
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.
But it's already inside a string interpolation, so would get converted to a string already.
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.
If removed it will generate 2 errors:
$ eslint . && flow check
Error: src/cli/commands/init.js:130
130: question += ` (${def})`;
^^^ boolean. This type cannot be coerced to
130: question += ` (${def})`;
^^^^^^^^^^^ string
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.
That's interesting. That is Flow complaining about the type. I didn't think it would complain inside an interpolated string. Oh well, in that case the .toString()
is fine.
@@ -114,14 +121,18 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |||
def = val; | |||
} | |||
|
|||
if (manifestKey === 'private' && privateFlag) { |
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 conditional could be eliminated if the default is set above in the array of questions
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.
no need, just add true
when user uses this flag.
src/cli/commands/init.js
Outdated
} | ||
|
||
let answer; | ||
let validAnswer = false; | ||
|
||
if (yes) { | ||
if (yes || (privateFlag && manifestKey === 'private')) { |
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 this additional ||
would also be eliminated if the default
was set based ont he flag in the array of questions.
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.
Like I said below. No default value.
src/cli/commands/init.js
Outdated
@@ -141,6 +152,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |||
} | |||
|
|||
if (answer) { | |||
if (manifestKey === 'private') { |
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.
It would be a better design to add something like dataType: 'boolean'
to the schema of questions when they are defined, then here check that data type and use "yn" in the case of booleans only.
Or perhaps even inputFormatter: yn
in the questions schema, then here: if( question.inputFormatter) { answer = question.inputFormatter(answer); }
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.
Thank you for the contribution!
Added some comments that I thing would simplify the code. I dislike the "special case" if manifestKey === 'private'
conditionals. It would be nice to eliminate those.
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.
Nice!
src/cli/commands/init.js
Outdated
@@ -141,6 +152,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |||
} | |||
|
|||
if (answer) { | |||
if (manifestKey === 'private') { | |||
answer = yn(answer); |
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.
We probably should make use of yn
more since we added it?
I haven't seen @rally25rs' review. He has good points so resigning.
I think we need a specific document to describe my idea of implementation. And a document on the site to guide users to use this flag.
Just need this line in |
@rally25rs @pierreneter ping! Do you need anything from us to move this forward? I'd love to get this merged. |
@BYK I would go refactor out some of the conditionals myself, but I don't think there is a way for me to directly modify this PR? |
Hi, |
@rally25rs |
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.
Sorry for the delay on this @pierreneter , I didn't realize you were waiting on me to reply. Looks good, and we appreciate your contribution!
The failing CircleCI tests seems unrelated to this PR, and passes on other integrations. @BYK I can't merge this unless those pass. I also can't trigger a rebuild on CircleCI because I don't have permissions. Could you re-kick Circle? (or just merge this is github gives you that ability) |
Never, unless I really have to :D |
Hey @pierreneter, sorry for the communication issues. It is easy to miss notifications from GitHub as they tend to be a lot, for active projects like Yarn. Would you like to join our Discord server so you can ping members directly in case they don't notice the updates? Also, apologies, since I try to go over all open PRs regularly to make sure they are not forgotten and I missed this one. Thanks a lot for your hard work and sticking to the end with this one! |
**Summary** Closes yarnpkg#4113. This PR create the `private` flag for `yarn init` command. Can use both `yes` and `private` flags. Or can use `private` flag alone to set `private` is `true` when run command. **Test plan** Have added tests
Summary
Close #4113, this PR create the
private
flag foryarn init
command. Can use bothyes
andprivate
flags. Or can useprivate
flag alone to setprivate
istrue
when run command.Test plan
Have added tests