-
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
Use "-v" to display version number instead of "-V" #3395
Conversation
Any idea how to make it non breaking? |
I don't really agree; |
But it seems that at current version running with |
Ok, considering that opinions are split regarding -v/-V I propose to get rid of both and use only long version for arguments. I agree that it is annoying when running |
Do you mean that do not execute |
Maybe if there is not package.json. |
Or we could just make
|
I quite like that |
I like |
@arcanis I think the example you showed is a good idea, except the first usage. |
Any thoughts on how to proceed? |
Do you prefer to making Yarn not execute |
This is nuanced. |
I think using -v is convenient to check if yarn has been installed successfully, not only display version number. Maybe using -v to check that for any tools is a habit, I think. |
Well -v could print a version and show help message :)
…On 24 May 2017 at 11:45, Pig Fang ***@***.***> wrote:
I think using -v is convenient to check if yarn has been installed
successfully, not only display version number. Maybe using -v to check that
for any tools is a habit, I think.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3395 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACBdWGwomKizN5zta4rgncqSUVzBwsnoks5r9ApMgaJpZM4NZ738>
.
|
How about making running |
How should I add tests? |
@g-plane, sorry for a delay, I was in a bug crunch and then a time off.
Sounds non consistent, people are used to have On that note, when you do
Which shows version of Yarn. |
@bestander Well, I have done something at the last commit, which make yarn won't save lock file. Here is the code: ff00684 The first line Anything should be changed? I will do. |
src/cli/index.js
Outdated
@@ -29,7 +29,7 @@ const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length | |||
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length); | |||
|
|||
// set global options | |||
commander.version(version); | |||
commander.version(version, '-v, -V, --version'); |
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.
let's not alias -v/-V to --version yet because we have not agreed whether people will confuse it with --verbose.
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.
Only use --version
?
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.
Yeah, we avoid ambiguous shorthands in Yarn.
src/cli/commands/install.js
Outdated
|
||
// `fs.exists()` is deprecated since nodejs v8 | ||
try { | ||
await fs.access(loc); |
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.
looks a bit radical, I think this may be done coming from another angle.
If package.json does not exist then patterns from fetchRequestFromCwd call would be empty.
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.
Okay, how should I 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.
Do you mean I should call the function fetchRequestFromCwd
?
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, it is called on line 421.
depRequests contains all the patterns from a package.json.
If it is empty and it is not an Add command then installation should stop without saving a lockfile.
@bestander I have done a force push for the commit: 93ddc5d . You can review the code. If something should be changed, I will do. Screenshot: |
It seems there are some conflicts with unit test. |
Yeah, a few tests were relying on previous behavior |
So should I change the test? |
src/cli/commands/install.js
Outdated
@@ -431,6 +431,10 @@ export class Install { | |||
this.scripts.setArtifacts(artifacts); | |||
} | |||
|
|||
if (Object.getPrototypeOf(this) === Install.prototype && depRequests.length === 0) { |
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.
Look at code on line 367, it saves explicitly when there is nothing to install.
Maybe that logic should be there?
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.
Maybe I should move the code to there?
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 you can just enhance the code there, you probably don't need to check for Install.prototype.
The logic should be "don't save lockfile if there are no dependencies"
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.
Ok. I will try.
@@ -29,7 +29,7 @@ const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length | |||
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length); | |||
|
|||
// set global options | |||
commander.version(version); | |||
commander.version(version, '--version'); |
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.
what this command changes?
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.
Yes, as long as the change is reasonable. |
Ok, this looks good now, thanks @g-plane. |
How about: |
Maybe not needed.
What does it output now?
…On 22 June 2017 at 18:32, Pig Fang ***@***.***> wrote:
How about: No package.json found. ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3395 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACBdWLPcI_mW-6uy4dVrHSxH9QJlohhqks5sGxXDgaJpZM4NZ738>
.
|
Yeah, then no package.json found sounds good. |
Sorry for delay. |
Can you run |
src/cli/commands/install.js
Outdated
await this.saveLockfileAndIntegrity(topLevelPatterns, workspaceLayout); | ||
if (topLevelPatterns.length || await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME))) { | ||
await this.saveLockfileAndIntegrity(topLevelPatterns, workspaceLayout); | ||
} |
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.
how about
} else {
reporter.info(reporter.lang('noPackageJsonFound'));
}
Then the the block at line 843-846 can be removed
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 I missed this one, do you need to check await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME)
?
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.
Check what? I am sorry that I do not quite understand what you mean.
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 are you doing this
if (topLevelPatterns.length || await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME))) {
instead of this?
if (topLevelPatterns.length) {
}
What does the second condition mean?
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.
When running remove
command, yarn will update lock file by running install
.
https://github.com/yarnpkg/yarn/blob/master/src/cli/commands/remove.js#L74
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 see, good thinking.
Yes, makes sense in that case.
Would you add a comment for that?
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.
Ok, I will.
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.
One more thing, fs.exists()
is deprecated since node 8. Should I make a change?
https://nodejs.org/dist/latest-v8.x/docs/api/fs.html#fs_fs_exists_path_callback
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, we use our own wrapper of fs.exists, so it is fine
src/reporters/lang/en.js
Outdated
@@ -181,6 +181,8 @@ const messages = { | |||
foundWarnings: 'Found $0 warnings.', | |||
foundErrors: 'Found $0 errors.', | |||
|
|||
noPackageJsonFound: 'No package.json found.', |
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.
How about
notSavedLockfileNoDependencies: 'Lockfile not saved, no dependencies.',
We are not focusing on a package.json existence but on the packages that were installed
Good job, @g-plane, just a few nits. |
I have run |
Try rebasing to master, |
Is that OK? |
Great job, @g-plane! |
Thanks! |
Do not save lockfile when no dependencies (yarnpkg#3395)
…encies this reverts most of yarnpkg#3395 992b5c9 which appears only necessary to work around yarnpkg#3329 (requesting the yarn version with -v triggered install)
…5843) **Summary** this reverts most of #3395 992b5c9 which appears only necessary to work around #3329 (requesting the yarn version with -v triggered install). As noted in #5839, `yarn -v` and `yarn check` no longer have `install` as a side effect and IMO, the original behavior where an empty lock file is generated as part of install is the correct behavior. Many tools currently sniff for a yarn.lock file to determine if yarn is being used. It seems more consistent with `yarn import` which generates a lockfile even if the existing node_modules is empty. fixes #5839 **Test plan** `yarn run test` passes `yarn run lint` passes `yarn-local install` saves an empty lockfile `yarn-local import` continues to save an empty lockfile `yarn-local -v` will not trigger install and will not generate a lock file. correctly displays a version. `yarn-local check` will not trigger install and will not generate a lock file
Summary
Before, we run
yarn -V
oryarn --version
to display version number of Yarn. But we are used to using-v
to display it, like runningnode -v
andnpm -v
.Maybe caused by commander.js, flags of command for displaying version number cannot be
'-v, -V, --version'
. In other word, we cannot runyarn -V
to display version number any more.Test plan
Just run
yarn -v
. Note that do NOT useyarn -V
any more.