Skip to content

Commit

Permalink
Add more details about workspaces implementation (yarnpkg#893)
Browse files Browse the repository at this point in the history
I found this missing each time I tell someone to read the doc. 
Hope it will helps others :)
  • Loading branch information
MoOx authored and Haroenv committed Dec 11, 2018
1 parent b9559fa commit e5f28aa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lang/en/docs/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ Finally, run `yarn install` somewhere, ideally inside the workspace root. If eve
/workspace-b/package.json
```

_Note: don't look for `/node_modules/workspace-b`. It won't be there unless some other package use it as a dependency._

And that's it! Requiring `workspace-a` from a file located in `workspace-b` will now use the exact code currently located inside your project rather than what is published on Github, and the `cross-env` package has been correctly deduped and put at the root of your project to be used by both `workspace-a` and `workspace-b`.

Please note the fact that `/workspace-a` is aliased as `/node_modules/workspace-a` via a symlink.
That's the trick that allow you to do require the package like if it was a normal one!
You also need to know that `/workspace-a/package.json#name` field is used and not the folder name.
This means that if `/workspace-a/package.json` `name` field was `"pkg-a"`, the alias will be as following:
`/node_modules/pkg-a -> /workspace-a` and you will be able to import code from `/workspace-a` with `const pkgA = require("pkg-a");` (or maybe `import pkgA from "pkg-a";`).

### How does it compare to Lerna? <a class="toc" id="toc-how-does-it-compare-to-lerna" href="#toc-how-does-it-compare-to-lerna"></a>

Yarn's workspaces are the low-level primitives that tools like Lerna can (and [do](https://github.com/lerna/lerna/pull/899)!) use. They will never try to support the high-level feature that Lerna offers, but by implementing the core logic of the resolution and linking steps inside Yarn itself we hope to enable new usages and improve performance.
Expand Down

0 comments on commit e5f28aa

Please sign in to comment.