Skip to content
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

Merged
merged 5 commits into from
Aug 24, 2017
Merged

Add private flag for yarn init command #4165

merged 5 commits into from
Aug 24, 2017

Conversation

pierreneter
Copy link
Contributor

Summary
Close #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

{
key: 'private',
question: 'private',
default: '',
Copy link
Contributor

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").

Copy link
Contributor Author

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.

Copy link
Contributor

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: '',
Copy link
Contributor

@rally25rs rally25rs Aug 14, 2017

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)

Copy link
Contributor Author

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()})`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the additional .toString()?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

}

let answer;
let validAnswer = false;

if (yes) {
if (yes || (privateFlag && manifestKey === 'private')) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -141,6 +152,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

if (answer) {
if (manifestKey === 'private') {
Copy link
Contributor

@rally25rs rally25rs Aug 14, 2017

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); }

Copy link
Contributor

@rally25rs rally25rs left a 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.

BYK
BYK previously approved these changes Aug 14, 2017
Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -141,6 +152,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

if (answer) {
if (manifestKey === 'private') {
answer = yn(answer);
Copy link
Member

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?

@BYK BYK dismissed their stale review August 14, 2017 14:02

I haven't seen @rally25rs' review. He has good points so resigning.

@pierreneter
Copy link
Contributor Author

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.
The cases in my idea that I want to clarify.

yarn init -y

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}
yarn init -yp

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true
}
yarn init -p
yarn init v1.0.0
question name (test-yarn):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
success Saved package.json
Done in 3.85s.

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true
}
yarn init
yarn init v1.0.0
question name (test-yarn):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 2.30s.

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT"
}
yarn init
yarn init v1.0.0
question name (test-yarn):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private: false
success Saved package.json
Done in 5.34s.

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": false
}
yarn init
yarn init v1.0.0
question name (test-yarn):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private: true
success Saved package.json
Done in 5.34s.

{
  "name": "test-yarn",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "private": true
}

Just need this line in package.json when user needs it.

@BYK
Copy link
Member

BYK commented Aug 23, 2017

@rally25rs @pierreneter ping! Do you need anything from us to move this forward? I'd love to get this merged.

@rally25rs
Copy link
Contributor

@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?

@pierreneter
Copy link
Contributor Author

Hi,
@rally25rs you can create a PR to my fork, here: https://github.com/pierreneter-repositories/yarn/tree/init/private
I will merge it, no matter how.

@pierreneter
Copy link
Contributor Author

@rally25rs
So, I move yn to array of question like you want. And consolidate the tests to make sure all I want.
You can do anything free to satisfy the above cases that I give: #4165 (comment) or agree with what I do.
Please respond soon.
This RP has taken 10 days.
When I respond, no one responds. You can not ask others to do things and ignore them, not listen to them.

Copy link
Contributor

@rally25rs rally25rs left a 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!

@rally25rs
Copy link
Contributor

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)

@BYK
Copy link
Member

BYK commented Aug 24, 2017

or just merge this is github gives you that ability

Never, unless I really have to :D

@BYK
Copy link
Member

BYK commented Aug 24, 2017

When I respond, no one responds. You can not ask others to do things and ignore them, not listen to them.

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!

@BYK BYK merged commit 6bab5cc into yarnpkg:master Aug 24, 2017
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
**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
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.

3 participants