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

Fix yarn version which yields same output as yarn --version (#2491) #2510

Merged

Conversation

ConAntonakos
Copy link
Contributor

@ConAntonakos ConAntonakos commented Jan 20, 2017

There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name version was shared. In other words, executing the command yarn version would yield the same output as yarn --version. This fixes #2491. This also seems to relate to PR #2268.

Let me know what you think. And sorry for the issue reference spam! Thanks!

@bestander
Copy link
Member

tests got broken

@ConAntonakos
Copy link
Contributor Author

ConAntonakos commented Jan 20, 2017

Yeah; odd because running yarn run test-only did not yield these errors...

Is that the best way to ensure testing is smooth? Or am I missing something else?

Pardon my ignorance since this is the first time I've delved into the Yarn source. 😄

@bestander
Copy link
Member

@ConAntonakos, the CI could fail because of network issues or was based on an unstable commit.
Can you please rebase on latest master?

@ConAntonakos
Copy link
Contributor Author

Sure! Thanks for letting me know.

@bestander
Copy link
Member

I think CI shows a genuine break in tests now

@markstos
Copy link
Contributor

Since yarn version vs yarn --version made it into a release, it seems there must have been a lack of test coverage that led to this bug being introduced. So it would be great if the fix included some additional test coverage that confirms that yarn version works expected (or at least that doesn't just print the version!).

@ConAntonakos
Copy link
Contributor Author

@markstos That's a good idea. I essentially reverted a previous change that caused the break. I'll keep at it and consider test coverage as well.

@ConAntonakos
Copy link
Contributor Author

ConAntonakos commented Jan 28, 2017

Ok, I was able to get unit tests working again. It seems they weren't playing nicely with node v7, which breaks them. I'll get a screen capture of the error output next time. So I downgraded to node v6.9.x.

I'm delving more into the source - and subsequently, the commander package with which I'm not familiar - and I noticed that similarly named commands and parsed flags are executing the same logic, i.e., help and --help (version and --version). I can't tell yet if that's a commander issue or a yarn source issue.

The major culprit is this line: https://github.com/yarnpkg/yarn/blob/master/src/cli/index.js#L174

If the above line is removed, yarn version and yarn --version work perfectly, but it breaks the https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/add.js tests.

@bestander
Copy link
Member

To rebase properly I usually do

git rebase master
git push <my fork> <my branch> --force

Merging a master branch does not work well with github PRs

@ConAntonakos
Copy link
Contributor Author

Ugh! I apologize for that. Do you want me to redo that?

@bestander
Copy link
Member

No worries, yeah, better rebase, otherwise I don't know what happens when the PR is merged :)

Constantine Antonakos added 2 commits January 30, 2017 13:39
…pkg#2491)

There was a conflict when commander attempts to parse the incoming args
between the command executed and the options since the name `version`
was shared. In other words, executing the command `yarn version`
would yield the same output as `yarn --version`. This relates to PR yarnpkg#2268.
…ting name bug

Relating to tj/commander.js#346, when an arg shares the same name as an
option, it wrongly ignores the arg command and executes the option
instead. Therefore, executing 'yarn version' would instead translate
to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
@ConAntonakos
Copy link
Contributor Author

ConAntonakos commented Jan 31, 2017

Looks like it's failing the following test type TEST_TYPE="test-ci -- -- --maxWorkers 1" and its timing out these subsequent tests:

  • --production flag ignores dev dependencies (90009ms)
  • install transitive optional dependency from lockfile (90009ms)

Also, TODO: Add tests (or, improve tests) for src/cli/commands/version.

@bestander
Copy link
Member

@ConAntonakos, don't worry about the MacOS build on travis, it is a bit flaky.
Would you add a test in this PR?

@bestander
Copy link
Member

I'll merge the fix now.
@ConAntonakos a follow up PR with a test would be really great.

@bestander bestander merged commit d66575e into yarnpkg:master Feb 1, 2017
bestander pushed a commit that referenced this pull request Feb 1, 2017
… (#2510)

* Fix `yarn version` which yields same output as `yarn --version` (#2491)

There was a conflict when commander attempts to parse the incoming args
between the command executed and the options since the name `version`
was shared. In other words, executing the command `yarn version`
would yield the same output as `yarn --version`. This relates to PR #2268.

* Shift first arg that shares name with an option to circumvent conflicting name bug

Relating to tj/commander.js#346, when an arg shares the same name as an
option, it wrongly ignores the arg command and executes the option
instead. Therefore, executing 'yarn version' would instead translate
to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
bestander pushed a commit that referenced this pull request Feb 1, 2017
… (#2510)

* Fix `yarn version` which yields same output as `yarn --version` (#2491)

There was a conflict when commander attempts to parse the incoming args
between the command executed and the options since the name `version`
was shared. In other words, executing the command `yarn version`
would yield the same output as `yarn --version`. This relates to PR #2268.

* Shift first arg that shares name with an option to circumvent conflicting name bug

Relating to tj/commander.js#346, when an arg shares the same name as an
option, it wrongly ignores the arg command and executes the option
instead. Therefore, executing 'yarn version' would instead translate
to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
@ConAntonakos
Copy link
Contributor Author

@bestander Indeed! I want to digest the structure of the testing (and subsequently, the flow of logic) and figure out why they weren't catching this error.

@ConAntonakos
Copy link
Contributor Author

This is very odd. Instantiating rprter returns an undefined result: https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/version.js#L32

mnsn pushed a commit to mnsn/yarn that referenced this pull request Feb 15, 2017
…pkg#2491) (yarnpkg#2510)

* Fix `yarn version` which yields same output as `yarn --version` (yarnpkg#2491)

There was a conflict when commander attempts to parse the incoming args
between the command executed and the options since the name `version`
was shared. In other words, executing the command `yarn version`
would yield the same output as `yarn --version`. This relates to PR yarnpkg#2268.

* Shift first arg that shares name with an option to circumvent conflicting name bug

Relating to tj/commander.js#346, when an arg shares the same name as an
option, it wrongly ignores the arg command and executes the option
instead. Therefore, executing 'yarn version' would instead translate
to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
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.

yarn version not working as stated in docs?
3 participants