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 transient bin links overriding direct ones #5012

Closed
wants to merge 2 commits into from
Closed

Fix transient bin links overriding direct ones #5012

wants to merge 2 commits into from

Conversation

AndersAstrand
Copy link

@AndersAstrand AndersAstrand commented Nov 28, 2017

Summary

This fixes #4937

The problem still exists when doing yarn add in an already installed module however, but that is unaffected by this patch as far as I can tell, and all tests pass.

This is my very first foray into the yarn code base, so please feel free to comment on anything in here. However petty it might seem to you!

Test plan

Run the test suite.

If a transient dependency has a bin link with the same name as a direct
dependency, sometimes the top level bin link with lead to the transient
dependency rather than the direct one after install.

This test asserts that bin links from direct dependencies are installed.
The bin links are created in two passes during install. In the first
pass all direct dependencies for the installing module and transient
dependencies are created in their respective bin directories. In the
second pass top level bin links are created for all modules, including
transient dependencies.

This patch makes sure the second pass doesn't overwrite links from the
first pass which fixes a problem where links from transient dependencies
could overwrite links from direct dependencies.
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.

This new test only passes because your direct deps a-dep and b-dep are alphabetically sorted before the transitive c-dep and d-dep.

If you rename a-dep to z-dep then the test will fail (z-dep will be bin linked later than it's transitive deps now, and so the bin link will exist already and won't be overwritten)

Also, I mess this up all the time myself too, but the correct term is "transitive" not "transient", it would be nice to fix that term where it shows up in code. Some of them are probably my fault 😞

My own understanding of how these bin links were made was wrong after I actually stepped through the code. I was mistaking "top level deps" for "direct deps" in my own thought process.

It seems like before we loop over the packages to link, we should re-order them not just alphabetically as they are now, but by non-direct (transitive) first, then direct deps second (which is what I thought it actually did, but apparently does not).

@rally25rs
Copy link
Contributor

rally25rs commented Nov 29, 2017

Unfortunately I can't push a commit to this, but I pushed a commit to my fork of Yarn that would fix this issue.

@AndersAstrand ~~~have a look at rally25rs@c471ccf and see what you think. We could either incorporate those changes to this PR, or I could PR my branch and close this one (I'd hate to hijack your PR).~~~ Edit: I figured out that I can just submit a PR from my fork to yours: https://github.com/AndersAstrand/yarn/pull/1

Thank you for writing the test case for this, it really helps! 👍

@rally25rs rally25rs self-assigned this Nov 29, 2017
@AndersAstrand
Copy link
Author

AndersAstrand commented Nov 30, 2017

Thanks a lot for your comments!

Transitive, got it, I read transient somewhere I think and just went with it :).

You are, of course, correct about the z-dep thing, and here I thought I was so clever when I made sure they were cross referencing the same bin names.

I suspected my proposed fix was way too naive to actually work, but a green test run have a tendency to instill confidence :).

Feel free to just close this pull request or hi-jack it completely. I'm only happy if I could be of any help in getting this bug fixed since it's what's stopping us from switching to yarn.

@rally25rs
Copy link
Contributor

Transitive, got it, I read transient somewhere I think and just went with it :).

Trust me, I do the same thing myself all the time 😆

Feel free to just close this pull request or hi-jack it completely.

Closing this PR and opening #5016 to replace it (it's the same as this PR with 1 additional commit)

I'm only happy if I could be of any help in getting this bug fixed since it's what's stopping us from switching to yarn.

And we thank you for your contribution! 🎉 The more community members we can get involved, the better this project will be 👍

@rally25rs rally25rs closed this Nov 30, 2017
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.

Sub dependency .bin symlinks can override top level dependency .bin symlink
2 participants