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

feat(config): Add custom config for init private flag #4377

Merged
merged 5 commits into from
Nov 1, 2017
Merged

feat(config): Add custom config for init private flag #4377

merged 5 commits into from
Nov 1, 2017

Conversation

pierreneter
Copy link
Contributor

@pierreneter pierreneter commented Sep 9, 2017

Summary

Here is a small custom; I add this because it relates to https://yarnpkg.com/en/docs/cli/init#toc-setting-defaults-for-yarn-init. I discovered this was necessary while writing introduces for this flag.

Test plan

New init and config tests.

@BYK
Copy link
Member

BYK commented Sep 10, 2017

I do not understand this change fully, can you explain your aim a bit more? Are you trying to make private-flag the default? Do we have to cast this to a string? Can we just do config.getOption('private-flag') === true instead?

BYK
BYK previously requested changes Sep 10, 2017
@@ -31,6 +31,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
email: config.getOption('init-author-email'),
url: config.getOption('init-author-url'),
};
const _defaultPrivateFlag = String(config.getOption('init-private'));
const defaultPrivateFlag = _defaultPrivateFlag === 'undefined' ? '' : _defaultPrivateFlag;
Copy link
Member

Choose a reason for hiding this comment

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

Why not simply

const defaultPrivateFlag = config.getOption('init-private') || '';

This is actually safer since it allows the literal 'undefined' value too. (not that I expect it to be used but it is "more accurate")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. I tried this way first. But this not pass the lint test. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can see here: https://circleci.com/gh/yarnpkg/yarn/tree/pull%2F4377
Ok, I just thought of a shorter way. Let me try.

@pierreneter
Copy link
Contributor Author

@BYK about this, config.getOption return a string value. Wait a second. Let me push a commit.

@pierreneter
Copy link
Contributor Author

In this PR, I would like to add the ability for users to use yarn config set init-private <value>, same as another argument in init.

@@ -94,7 +94,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
{
key: 'private',
question: 'private',
default: '',
default: String(config.getOption('init-private') || ''),
Copy link
Contributor Author

@pierreneter pierreneter Sep 10, 2017

Choose a reason for hiding this comment

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

This's a string value, and L157 will pass string value of private flag to boolean

Copy link
Member

Choose a reason for hiding this comment

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

Yarn automatically detects "magic" boolean strings true and false and converts the value into booleans. Try and see yourself ;)

@BYK
Copy link
Member

BYK commented Sep 13, 2017

Hey, sorry for the very late turnaround :( I tried adding --init.private true to my .yarnrc file and it seems to do the trick. Is that not enough?

@pierreneter
Copy link
Contributor Author

Hey, I tried your trick with my .yarnrc but it doesn't work. (Windows, 1.0.1). Hm. If it works ok, so, it will be strange to what the user is used to https://yarnpkg.com/en/docs/cli/init#toc-setting-defaults-for-yarn-init

@BYK
Copy link
Member

BYK commented Sep 14, 2017

It did work for me. What do you see when you run yarn init at the "private" stage?

@pierreneter
Copy link
Contributor Author

pierreneter commented Sep 16, 2017

@BYK here are my screen and .yarnrc
yarn init

.yarnrc

@BYK
Copy link
Member

BYK commented Sep 18, 2017

@BYK here are my screen and .yarnrc

I've tested this locally and it works but apparently, the lockfile parser is allergic to Windows-style line ending so it may be that if you edited the file manually. Make sure you have Unix-style line endings and it should work.

@BYK
Copy link
Member

BYK commented Sep 18, 2017

Added a PR for \r\n here: #4495

@pierreneter
Copy link
Contributor Author

But, what about enable setting default config like another init option :'( ?

@BYK
Copy link
Member

BYK commented Sep 18, 2017

But, what about enable setting default config like another init option :'( ?

Good point. Added a comment. LMK if that's not the case. Also shouldn't we have at least one test case for this?

@BYK BYK self-assigned this Sep 29, 2017
@BYK
Copy link
Member

BYK commented Oct 3, 2017

@pierreneter let's finish this with a test case! 😉

@BYK BYK dismissed their stale review October 26, 2017 12:34

Removing myself from reviewers since I edited/wrote code for the PR

Copy link
Member

@kaylie-alexa kaylie-alexa left a comment

Choose a reason for hiding this comment

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

minor comment, looks good

@@ -96,7 +96,7 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
{
key: 'private',
question: 'private',
default: '',
default: config.getOption('init-private') || '',
Copy link
Member

Choose a reason for hiding this comment

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

any reason this shouldn't default to false?

Copy link
Member

Choose a reason for hiding this comment

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

No idea :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, because, default this's not set yet. It will not add to package.json. If set it's false, always it will be add to package.json: private: false.

@BYK BYK changed the title Add custom config for init private flag feat(config): Add custom config for init private flag Nov 1, 2017
@BYK BYK merged commit 7d40146 into yarnpkg:master Nov 1, 2017
calvinhuang pushed a commit to calvinhuang/yarn that referenced this pull request Nov 9, 2017
**Summary**

Here is a small custom; I add this because it relates to https://yarnpkg.com/en/docs/cli/init#toc-setting-defaults-for-yarn-init. I discovered this was necessary while writing introduces for this flag.

**Test plan**

New init and config 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.

4 participants