<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Santiago</title>
    <description>The latest articles on Forem by Santiago (@anonimoconiglio).</description>
    <link>https://forem.com/anonimoconiglio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F100292%2F86dfac85-2fe2-4f64-9125-53683482b0c1.png</url>
      <title>Forem: Santiago</title>
      <link>https://forem.com/anonimoconiglio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anonimoconiglio"/>
    <language>en</language>
    <item>
      <title>What is a mono-repository and why you should try Lerna</title>
      <dc:creator>Santiago</dc:creator>
      <pubDate>Wed, 10 Jul 2019 17:39:25 +0000</pubDate>
      <link>https://forem.com/anonimoconiglio/what-is-a-mono-repository-and-why-you-should-try-lerna-57lm</link>
      <guid>https://forem.com/anonimoconiglio/what-is-a-mono-repository-and-why-you-should-try-lerna-57lm</guid>
      <description>&lt;h3&gt;
  
  
  Learn how to set up a Gatsby Theme Project with Lerna: this guide will help you understand what is a mono-repo and how to manage it with Lerna using NPM instead of Yarn Workspaces.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is Lerna and why it's worth a try?&lt;/li&gt;
&lt;li&gt;Setting Lerna with NPM from the shell&lt;/li&gt;
&lt;li&gt;Scaffolding folders and files with shell&lt;/li&gt;
&lt;li&gt;
Using Lerna

&lt;ul&gt;
&lt;li&gt;Choose your approach&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Orchestrate everything with Lerna bootstrap&lt;/li&gt;
&lt;li&gt;Run commands and scripts&lt;/li&gt;
&lt;li&gt;Update Wizard&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Lerna and why it's worth a try?
&lt;/h2&gt;

&lt;p&gt;I started to follow the &lt;a href="https://egghead.io/courses/gatsby-theme-authoring"&gt;Gatsby Theme Authoring course&lt;/a&gt; from Jason Lengstorf (&lt;a class="comment-mentioned-user" href="https://dev.to/jlengstorf"&gt;@jlengstorf&lt;/a&gt;
) and soon realized that I don't know nothing about 'Yarn Workspaces'. It's a pretty way to manage what's called a mono-repo: a repository that has more than one project inside and could share dependencies.&lt;/p&gt;

&lt;p&gt;By doppelmutzi from &lt;a href="https://doppelmutzi.github.io/monorepo-lerna-yarn-workspaces/"&gt;doppelmutzi.github.io&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Such projects are called workspaces or packages. In contrast, using multiple repositories with each repository housing only one project is called a Multi-Repo approach. [...] &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One thing that amazed me with the mono-repo approach was that my &lt;em&gt;Packages/Workspaces&lt;/em&gt; can locally share the same &lt;code&gt;node_modules&lt;/code&gt; dependencies. This saves me time and physical space.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;lerna and yarn workspaces give us the ability to build libraries and apps in a single repo without forcing us to publish to npm or other registries. The beauty behind these technologies is that they can find package dependencies by analyzing package.json files located at each project’s root folder. Thereby, these tools make it obsolete to manually create symlinks or use "low-level" npm link directly.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, even if you are already using &lt;code&gt;yarn workspaces&lt;/code&gt; I think Lerna worth the try because it provides a series of vantages. Besides you could use Lerna with Yarn Workspaces:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;with one lerna command you can iterate through all or particular packages, running a series of operations (such as linting, testing, and building) on each package. Thereby, it compliments yarn workspaces that takes over the dependency management process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So finally I decided to learn Lerna - sorry for the tongue twister  - but I didn't want to switch to Yarn (since I'm just comfortable with npm). Here's how I managed to make it work:&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Lerna with NPM from the shell
&lt;/h2&gt;

&lt;p&gt;Create a directory for your project and enter on it with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;try-lerna
&lt;span class="nb"&gt;cd &lt;/span&gt;try-lerna
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can install Lerna globally (&lt;code&gt;npm i -g lerna&lt;/code&gt;) or use it with npx.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Init lerna&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx lerna init --independent
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;init&lt;/code&gt; a git repository &lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;package.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;lerna.json&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;create a &lt;code&gt;packages&lt;/code&gt; folder (here you can place your workspaces). &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Packages&lt;/strong&gt; is how lerna call &lt;em&gt;workspaces&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can arrange the &lt;em&gt;Packages&lt;/em&gt; as you want, if you prefer you can put all the packages in the root folder and then change the array in order to match (like a "yarn workspaces" approach).&lt;/p&gt;

&lt;p&gt;My &lt;strong&gt;lerna.json&lt;/strong&gt; file has &lt;code&gt;stream: true&lt;/code&gt; (in order to see gatsby output when run develop with lerna) and &lt;code&gt;hoist: true&lt;/code&gt; (in order to &lt;em&gt;hoist&lt;/em&gt; node_modules also with the command &lt;code&gt;lerna add&lt;/code&gt;; I'll explain this last feature forward):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"packages"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="s2"&gt;"packages/*"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"independent"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"stream"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"bootstrap"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"hoist"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can add this manually or use this simple shell command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;packages&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:[&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;packages/*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;],&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;independent&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;stream&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:true,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;command&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;bootstrap&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;hoist&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:true&lt;/span&gt;&lt;span class="se"&gt;\r\t\t&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\r\t&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\r&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lerna.json       
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Scaffolding folders and files with shell
&lt;/h2&gt;

&lt;p&gt;This section can be done by hand following the first lesson from Jason Lengstorf's course linked in the introduction.&lt;br&gt;
I just collect all the basic passages in order to accomplish them with few commands from the shell.&lt;br&gt;&lt;br&gt;
In case you want to use my approach remember to replace "NAME" with the name of your theme and then just copy and paste this commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; packages/&lt;span class="o"&gt;{&lt;/span&gt;gatsby-theme-NAME,site&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;packages/&lt;span class="o"&gt;{&lt;/span&gt;gatsby-theme-NAME,site&lt;span class="o"&gt;}&lt;/span&gt;/&lt;span class="o"&gt;{&lt;/span&gt;index.js,package.json&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"//loop"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; packages/&lt;span class="o"&gt;{&lt;/span&gt;gatsby-theme-NAME,site&lt;span class="o"&gt;}&lt;/span&gt;/index.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Initial content for package.json on the site folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;private&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:true,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;site&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;1.0.0&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;license&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;MIT&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:{&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;builds&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gatsby build&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;develop&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gatsby develop&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;clean&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gaysby clean&lt;/span&gt;&lt;span class="se"&gt;\"\r\t&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\r&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; packages/site/package.json    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;package.json on the folder theme (replace NAME again and also insert YOUR_NPM_USER):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;@YOUR_NPM_USER/gatsby-theme-NAME&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;version&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;1.0.1&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;license&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;MIT&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;main&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;index.js&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: {&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;builds&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gatsby build&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;develop&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gatsby develop&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\r\t\t\"&lt;/span&gt;&lt;span class="s2"&gt;clean&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;gaysby clean&lt;/span&gt;&lt;span class="se"&gt;\"\r\t&lt;/span&gt;&lt;span class="s2"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\r&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; packages/gatsby-theme-NAME/package.json    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here's the result:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── packages
│  ├── site
│  └── gatsby-theme-NAME
├── .gitignore
├── package.json
└── lerna.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;PS: I advice you to create a &lt;code&gt;.gitignore&lt;/code&gt; and add &lt;code&gt;node_modules&lt;/code&gt; right away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"node_modules"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .gitignore
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Lerna
&lt;/h2&gt;

&lt;p&gt;One problem with Lerna is that you can't install multiple dependencies per Package with one single command (like you do with &lt;code&gt;yarn workspace name_workspace add package1 package2 etc&lt;/code&gt;). You need to do it one by one, like this (if you didn't install it globally you'll have to precede every command with &lt;code&gt;npx&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;lerna add gatsby &lt;span class="nt"&gt;--scope&lt;/span&gt; site 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;lerna add react &lt;span class="nt"&gt;--scope&lt;/span&gt; site
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;lerna add react-dom &lt;span class="nt"&gt;--scope&lt;/span&gt; site
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;--scope site&lt;/code&gt; is used to tell Lerna to install only in the Package "site".&lt;/p&gt;

&lt;p&gt;However, you can install a dependency, let's say &lt;code&gt;gatsby&lt;/code&gt;, for every &lt;em&gt;Package&lt;/em&gt; with just one command:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna add gatsby
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This command will: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Gatsby for every Package (so in this case for Site and also for the Theme Package). &lt;/li&gt;
&lt;li&gt;If you enabled &lt;code&gt;hoist&lt;/code&gt; on the lerna.json it will create a node_modules folder in your root (see 'Lerna Bootstrap forward'):&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Choose your approach
&lt;/h4&gt;

&lt;p&gt;If you like this approach you can continue installing all the common dependencies (&lt;code&gt;react&lt;/code&gt;, &lt;code&gt;react-dom&lt;/code&gt;) on the Packages. If you need to install some dependencies only for one Package use &lt;code&gt;--scope name_of_the_package&lt;/code&gt; (remember it's the name specified on the package.json not the name of the folder). &lt;/p&gt;

&lt;p&gt;You could also use npm by installing every dependency you want in the respective Package. But remember this approach will install a node_modules dependencies for every respective folder. This could be clean and then hoisted afterwards. Although this option is valid it will take you more time.&lt;/p&gt;

&lt;p&gt;Whatever option you choose remember to add/link the local Theme Package as a dependency for the Site Package (use the name you set on &lt;code&gt;package.json&lt;/code&gt;):&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna add @YOUR_NPM_USER/gatsby-theme-NAME --scope=site
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Orchestrate everything with Lerna bootstrap
&lt;/h2&gt;

&lt;p&gt;In the end you can safely do: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna bootstrap 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This command is really helpful, specially if you already have your package.json filled with their respective dependencies. &lt;/p&gt;

&lt;p&gt;With &lt;code&gt;hoist: true&lt;/code&gt; option (on &lt;code&gt;lerna.json&lt;/code&gt;) it will place a shared &lt;code&gt;node_modules&lt;/code&gt; folder located in the root, then it will link local dependencies in their respective &lt;code&gt;package.json&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;I really like &lt;a href="https://github.com/lerna/lerna/tree/master/commands/bootstrap#--hoist-glob"&gt;--hoist feature&lt;/a&gt; it's a process that avoid duplicated dependencies on the node_modules, so it saves physical space and installation time.&lt;/p&gt;

&lt;p&gt;If for whatever reason you want to clean anything first you could do:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna clean &amp;amp;&amp;amp; lerna link &amp;amp;&amp;amp; lerna bootstrap 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Run commands and scripts
&lt;/h2&gt;

&lt;p&gt;To run scripts (placed on the &lt;code&gt;package.json&lt;/code&gt;) you need to specify (or not) the target Package:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna run develop --scope Package_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Lerna also let you run any commands from the root to every Package (use dash). For example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lerna exec -- rm -rf node_modules 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will remove node modules on every Package folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update Wizard
&lt;/h2&gt;

&lt;p&gt;In the future, when you'll need to update your packages you can use the &lt;a href="https://www.npmjs.com/package/lerna-update-wizard"&gt;update-wizard&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev lerna-update-wizard
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;then you'll need to run only this command and the wizard will help you: &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lernaupdate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>lerna</category>
      <category>gatsby</category>
      <category>npm</category>
      <category>yarnworkspaces</category>
    </item>
  </channel>
</rss>
