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

Resolve the realpath of linkFolder before symlinking #7028

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

apfelfabrik
Copy link

Summary

I was affected by the bug described here: #1297

Symlinks created by yarn link will be broken if there's a symlink somewhere in the config path. This fixes the problem for me.

fs.symlink seems to not resolve existing symlinks in the target path when creating new ones, resulting in broken symlinks. Resolving the realpath of linkFolder before creating the symlink fixes this.

Test plan

This was previously not working when ~/.config was a symlink:

➜  dep-a $ yarn link
yarn link v1.15.0-0
success Registered "@company/dep-a".
info You can now run `yarn link "@company/dep-a"` in the projects where you want to use this package and it will be used instead.
✨  Done in 0.34s.

➜  dep-a $ cd ../..

➜  parent $ yarn link "@company/dep-a"
yarn link v1.15.0-0
error No registered package found called "@company/dep-a".
info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.

With this update, it is working. More details in the ticket, too.

@damncabbage
Copy link

Thanks for doing this; I personally just got bitten by this as well (my ~/.config being a symlink).

@jone
Copy link

jone commented Jun 18, 2019

I ran into this problem too (I link my dotfiles into the home directory). It would be great if this could get merged!

damncabbage added a commit to damncabbage/dotfiles that referenced this pull request Jun 21, 2019
@nemoDreamer
Copy link

This solves the issue!
Too bad CI is failing 😢 ...

@apfelfabrik
Copy link
Author

apfelfabrik commented Nov 22, 2019

Wow, didn't know so many people cared. I'll have a look at why the CI is failing.

Edit: Turns out the tests on macOS run in a temporary folder that is also a symlink. Fixing the linking exposed a similar problem with linking the binaries on that platform, so I went and fixed that too. The fix seems to be complete now, at least I'm not aware what else to look at.

@apfelfabrik apfelfabrik force-pushed the fix/yarn-link-when-nesting-symlinks branch 2 times, most recently from f9180d4 to 3029d40 Compare November 22, 2019 16:14
Copy link

@waleedahmed3045 waleedahmed3045 left a comment

Choose a reason for hiding this comment

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

Passed all the tests, no significant code changes

@apfelfabrik apfelfabrik force-pushed the fix/yarn-link-when-nesting-symlinks branch from 6adf9b4 to afb8fa4 Compare January 7, 2020 10:11
@apfelfabrik apfelfabrik force-pushed the fix/yarn-link-when-nesting-symlinks branch 4 times, most recently from 4d38c7d to e921aae Compare January 27, 2020 10:23
@apfelfabrik apfelfabrik force-pushed the fix/yarn-link-when-nesting-symlinks branch 2 times, most recently from cef8735 to 0edde59 Compare July 26, 2020 15:51
@apfelfabrik
Copy link
Author

apfelfabrik commented Jul 26, 2020

I've rebased the PR once more, I still think this is a worthwhile fix. The CI issues seem to not be related to this PR. It has been green in the past, and recent, unrelated, PRs against master fail with the same timeouts.

@apfelfabrik
Copy link
Author

@waleedahmed3045, is there anything else I can do?

fs.symlink seems to not resolve existing symlinks in the target path
when creating new ones, resulting in broken symlinks. Resolving the
realpath of linkFolder before creating the symlink fixes this.
Tests on macOS run in a symlinked folder and previously worked because
no path was resolved correctly. To work once more, both have to be
replaced with the realpath.
As per pull request template recommendation.
@apfelfabrik apfelfabrik force-pushed the fix/yarn-link-when-nesting-symlinks branch from 0edde59 to 55727ba Compare September 11, 2020 16:42
@svallory
Copy link

Is this ever going to be merged? I'm tired of going back to npm when I need to link packages. What can I do to help?

@corrjo
Copy link

corrjo commented May 13, 2021

Is yarn just not maintained?

@rodamaral
Copy link

Is yarn just not maintained?

By the way, for some reason the active development branch of yarn is not at this repository. It's at https://github.com/yarnpkg/berry

Not sure what it means for opened issues here...

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.

8 participants