<?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>DEV Community: icruzr93</title>
    <description>The latest articles on DEV Community by icruzr93 (@icruzr93).</description>
    <link>https://dev.to/icruzr93</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%2F337909%2F2809bcb7-58d2-4b91-ab49-63d205443c81.jpg</url>
      <title>DEV Community: icruzr93</title>
      <link>https://dev.to/icruzr93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/icruzr93"/>
    <language>en</language>
    <item>
      <title>How to migrate to Turbo from Lerna for Monorepo managemnt.</title>
      <dc:creator>icruzr93</dc:creator>
      <pubDate>Fri, 06 May 2022 17:33:01 +0000</pubDate>
      <link>https://dev.to/icruzr93/how-to-migrate-to-turbo-from-lerna-5a6b</link>
      <guid>https://dev.to/icruzr93/how-to-migrate-to-turbo-from-lerna-5a6b</guid>
      <description>&lt;p&gt;&lt;em&gt;For this read is really recommended to have context about Lerna setup, otherwise you can find this a bit confusing due that I'm not explaining too much about its setup&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As you might know, &lt;strong&gt;Lerna&lt;/strong&gt; was deprecated, so we had to look up for an utility that could help us to replace the basis of &lt;strong&gt;Lerna&lt;/strong&gt;, the chosen one was Turbo.&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1519436453729734657-385" src="https://platform.twitter.com/embed/Tweet.html?id=1519436453729734657"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1519436453729734657-385');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1519436453729734657&amp;amp;theme=dark"
  }



&lt;/p&gt;




&lt;h2&gt;
  
  
  TLDR
&lt;/h2&gt;

&lt;p&gt;First of all we read this article which helped us to compare the different, and popular, tools that actually exists for Monorepo management:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://monorepo.tools/" rel="noopener noreferrer"&gt;https://monorepo.tools/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We moved to Turbo due these basic reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We are migrating to Next.js and, if you don't know, Vercel is owner of both tools so on this way we felt that choosing Turbo could bring us a sense of alignment with the tools used.&lt;/li&gt;
&lt;li&gt;Based on their documentation the migration seemed easy (and it was).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was good enough for us to try it out first, don't hesitate on trying out other ones first.&lt;/p&gt;




&lt;h2&gt;
  
  
  Lerna Context
&lt;/h2&gt;

&lt;p&gt;To start I need to let you know how we have structured our projects and how we used it for the MonoRepo management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How we used to use Lerna:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We had it globally installed for both, local and ci.&lt;/li&gt;
&lt;li&gt;We built packages at devtime on dev mode and once that is finished we start apps on dev mode.&lt;/li&gt;
&lt;li&gt;We built "packages" on ci time and once that is finished we build apps.&lt;/li&gt;
&lt;li&gt;We don't push nothing into private packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Project structure:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apps/
../app-a
../app-b

packages/
../package-a
../package-b

lerna.json
package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Commands used with Lerna:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bootstrap workspaces
lerna bootstrap

# Link lerna repos
lerna link

# Build the packages workspaces
lerna run build --scope="@company/package-a" --scope="@company/package-b"

# Build the project workspaces
lerna run build --scope="@company/project-a"

# Build the project workspaces
lerna run build --scope="@company/package-b"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Things to know
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Turbo&lt;/strong&gt; is being used for task running and caching.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Yarn workspaces&lt;/strong&gt; is being used for symlinking packages.&lt;/li&gt;
&lt;li&gt;Don't forget to delete &lt;strong&gt;node_modules&lt;/strong&gt; and &lt;strong&gt;.lock&lt;/strong&gt; files, otherwise you can find errors due the migration.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Migrating to turbo
&lt;/h2&gt;

&lt;p&gt;On our case we are using it globally for both local and on ci, you can also install it directly on your package.json:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --global turbo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you need to delete your &lt;strong&gt;lerna.json&lt;/strong&gt; file and create your &lt;strong&gt;turbo.json&lt;/strong&gt; file with the next content:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://turborepo.org/docs/guides/migrate-from-lerna#example-migration" rel="noopener noreferrer"&gt;Link to Turborepo docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For us it was enough to start migrating our commands, the fun thing about this is that you only need to run 1 command to build all app deps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bootstrap workspaces
yarn install

# Build app a
turbo run build --scope="@company/app-a"

# Build app b
turbo run build --scope="@company/app-b"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Not Recommended) In case you want something more explicit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Bootstrap workspaces
yarn install

# Build package a
turbo run build --scope="@company/package-a" --no-deps

# Build package b
turbo run build --scope="@company/package-b" --no-deps

# Build app a
turbo run build --scope="@company/app-a" --no-deps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can modify &lt;strong&gt;turbo.json&lt;/strong&gt; file to add more commands to &lt;a href="https://turborepo.org/docs/core-concepts/pipelines#defining-a-pipeline" rel="noopener noreferrer"&gt;take advance of it&lt;/a&gt; but on our case it was ok having it on this way and for other commands we are using &lt;strong&gt;yarn workspaces&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn workspaces run lint:fix
yarn workspaces run prettier:fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Overview:
&lt;/h2&gt;

&lt;p&gt;I hope this article can help you to start migrating to Turbo and hope it could help you migrate a more complex workflow than us. &lt;/p&gt;

&lt;p&gt;Don't forget to follow me on &lt;a href="https://twitter.com/icruzr93" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;, I honestly don't post anything but I retweet a lot of things that I find interesting for either Backend and Frontend devs.&lt;/p&gt;

</description>
      <category>lerna</category>
      <category>turbo</category>
      <category>javascript</category>
      <category>monorepo</category>
    </item>
  </channel>
</rss>
