Wow, it’s been a fair while since I last blogged! Well: let’s get straight to it!
Yesterday I discovered that yarn
(the alternative npm
client from Facebook)
had introduced a new feature called yarn workspaces
which makes working with
monorepos a lot easier. I’m working on a couple of projects recently that use
the monorepo approach (one is a client project in which I introduced the
monorepo approach to share code between React, React-Native and Chrome
extension apps easily; the other is the Graphile OSS
project I’m currently working on). We’ve had a few
minor irritations working with lerna
, the most notable of which is that when
we want to install a new dependency we can’t just yarn install
it - instead
we have to add it to package.json and run lerna bootstrap
again. At first
this wasn’t so bad, but it quickly becomes a chore!
Upon reading the announcement it immediately sounded like yarn workspaces would solve this problem (and more!) so I decided to get on board!
This is awesome; I'm going to try this out with Graphile tomorrow! https://t.co/213mvRmGbX
— Benjie Gillam (@Benjie) August 3, 2017
So, without further ado, here’s how I switched graphile-build to yarn workspaces (still with lerna):
First we must install v2.0.0 of lerna and v0.28+ of yarn; currently yarn@latest
is 0.27.5, so:
1
|
|
Now, since yarn workspaces is experimental we must manually enable this feature:
1
|
|
We must also enable useWorkspaces
in our lerna.json
- open it up and add the following:
1
|
|
We also need to declare that this project uses yarn workspaces (which is
independent of Lerna), so in package.json
ensure that private
is set to
true, and add the workspaces
key:
1 2 3 4 |
|
Now we’re pretty much ready to go, so let’s clear out the old stuff and start afresh:
1 2 3 4 |
|
And that’s it! Enjoy your new workspaces-enabled monorepo!
You can see the changes I made in this pull request: