[WIP] Add options to improve development with linked modules #3753
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Currently, setting up and maintaining links between many modules in local development is very painful. Not only do you have to manually link modules together, but once you do you can easily end up with many duplicate dependencies. This leads to errors e.g. when multiple copies of react are loaded if several linked dependencies also depend on react. A workaround is to install react globally and link to that from every place that uses it, but doing this everywhere is painful.
This pull introduces two options to help with these problems:
yarn link --deep
- Instead of linking the global copy to the current directory itself, this creates a link for every file/directory inside the current directory excluding ignored files (most importantlynode_modules
). This means that when you install a linked module, the dependencies are not duplicated (see 2). It does mean that if you add a file in the root of the linked module, you must runyarn link --deep
again to add a link to it globally, however. This is kinda like the knit proposal.yarn install --link
- This automatically sets up links to all dependencies that are linked globally and installs their dependencies. This means that once you've setup global links for all of the dependencies in your project withyarn link
(e.g. after cloning from git), you can just run this one command to setup all of the links and install all normal dependencies in one go. If those links are produced with the--deep
option, dependencies will be fully deduped.As mentioned above, this is similar to the
knit
proposal. (1) is pretty much the same idea as plainyarn knit
. (2) is different in that it automatically installs all linked dependencies rather than needing to manually callyarn knit dep
for each one. I think this is important to enable easy setup of projects using many linked modules. However, I should note that you can also callyarn add dep --link
as well, which is more similar toyarn knit dep
.I know workspaces are also being worked on at the moment, however I think this solves a different problem. Where workspaces are great for a tree of related modules (e.g. in a monorepo), the options in this pull are for linking together modules in separate trees, e.g. something that might be shared between multiple workspaces.
Test plan
If this is something the yarn community is interested in including, I'll clean up this PR, add tests and such. So far I'm just playing around, but it seems to work for my needs.