yarn
yarn copied to clipboard
feature: Add --force option to `yarn link` to overwrite existing link
Currently, trying to yarn link
a package which is already registered spits out a warning and does nothing. Manually removing the existing link adds unnecessary tedium. Having a yarn link --force
flag which replaces the existing link would be very useful.
Related issue: #7054
What is the process to unlink a directory that has been deleted? Do we have to create a whole new one just to delete it? I agree this would be a much better way.
At least tell us where the folder that is supposedly linked is, so we know where to delete
Bumped into the same. The case is quite simple: I'm doing some work on project 1, other work on project 2, other work on project 3. And suddenly:
❯ yarn link
yarn link v1.17.3
warning There's already a package called "my-addon" registered. This command has had no effect. If this command was run in another folder with the same name, the other folder is still linked. Please run yarn unlink in the other folder if you want to register this folder.
But ... what is the other folder? Where did it come from? I assume that yarn knows the location of the other folder so it would be more helpful to tell me:
There's already a package called "my-addon" registered in
${my-addon-path}
. This command has had no effect. If this command was run in another folder with the same name, the other folder is still linked. Please runcd ${my-addon-path}; yarn unlink
before you try to register this folder.
I created https://www.npmjs.com/package/manage-linked-packages to help with this, whilst Yarn doesn't have a --force
option
AFAICT yarn unlink
will unlink based on the package name in package.json, rather than based on the folder name. Is that correct?
If this command was run in another folder with the same name, the other folder is still linked.
I think the "folder with the same name" part is misleading, given that. In my testing it doesn't matter what the folder is named, nor do you need to find the "other folder" and unlink from there; any folder with the same name in its package.json should work.
This feature is desperately needed. Or at least a yarn links
command that would list out all the links with their paths. I apparently linked a package in the wrong place and it's hard to find
A workaround for this issue is to simply run yarn unlink && yarn link
inside the directory that you want to link. Yarn looks at the package name for unlink
, so it will unlink the package and then link the new directory.
Edit: please note that yarn unlink
will return an error when there is no linked package, so in order to use this as a replacement for yarn link --force
, one would have to do something like (yarn unlink || true) && yarn link
.
I think (yarn unlink || true) && yarn link
is equivalent to yarn unlink; yarn link
@phoenixeliot This is true so long as the shell isn't set to exit on a command failure (i.e. when the -e
flag is set). It is perhaps good practice to explicitly allow yarn unlink
to fail regardless.
Note that the subshell in that command isn't necessary; yarn unlink || true && yarn link
or yarn unlink || true; yarn link
behave almost identically to that example.
What is the status of this?
I am currently manually deleting links I do not need anymore in the ./config/yarn/link folder. This is my clumsy "unlink" process.