<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dmitry Titenko on Medium]]></title>
        <description><![CDATA[Stories by Dmitry Titenko on Medium]]></description>
        <link>https://medium.com/@dtitenko?source=rss-4251e133cd26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*M2Tzvi0PnEfEbkYtg937KQ.jpeg</url>
            <title>Stories by Dmitry Titenko on Medium</title>
            <link>https://medium.com/@dtitenko?source=rss-4251e133cd26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:06:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dtitenko/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Link it all: monorepo by example with Yarn workspaces]]></title>
            <link>https://medium.com/@dtitenko/link-it-all-monorepo-by-example-with-yarn-workspaces-17f9008097ea?source=rss-4251e133cd26------2</link>
            <guid isPermaLink="false">https://medium.com/p/17f9008097ea</guid>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[symlink]]></category>
            <category><![CDATA[lerna]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Dmitry Titenko]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 07:40:45 GMT</pubDate>
            <atom:updated>2019-07-04T08:00:27.485Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*umo08O1UQq54L4XEs385Mg.jpeg" /></figure><p>Modularization is inevitable step towards project maturity by defining clear boundaries between components of a project. Splitting the project on the late stage is painful and expensive. Doing so to early, when the development of the components are still active, is time consuming: coordination of the changes require a lot of discipline and extra manipulations with versions, commits and pull requests.</p><p>Although keeping functionally bounded in separate repos seems logical, there is still a trend dictated by the practical aspect of the development. It is <a href="https://github.com/babel/babel/blob/master/doc/design/monorepo.md">monorepo</a>. That’s how big players like <a href="https://www.infoq.com/presentations/Development-at-Google/">Google</a>, <a href="https://www.youtube.com/watch?v=X0VH78ye4yY">Facebook</a>, <a href="https://www.youtube.com/watch?v=bjh4DHuOf4E">Twitter</a> etc., manage to maintain dozens of packages from a single team, from a single project. Doing so is definitely bring its benefits, but also has several differences from a regular project lifecycle which are important to understand to prevent mistakes.</p><p>There are <a href="https://hackernoon.com/4-ways-to-go-monorepo-in-2019-ea5d19fc1f08">several popular ways</a> of implementing monorepo and choosing one depends solely on the project structure. As I’ve been using Yarn since the very first versions of it, and because the project has been using it already, I decided to try <a href="https://yarnpkg.com/lang/en/docs/workspaces/">Yarn workspaces</a>.</p><p>Yarn is using dependency hoisting, which means your workspace dependencies will be hoisted higher into the filesystem hierarchy. This is a great feature to align dependencies of your modules and have single lock file across the project. But making assumptions about dependency layout is hazardous and can lead to unexpected behavior. You always have <a href="https://yarnpkg.com/blog/2018/02/15/nohoist/">nohoist</a> option, which is a workspace declaration to have it’s own dependencies.</p><p>Arguably, the most important feature of any monorepo implementation is that any package can be a dependency to another without going through npm or any package manager. The feature is usually implemented using <a href="https://yarnpkg.com/en/docs/cli/link">symlinks</a>. The idea is to create a link in node_modulesto the source package withing the same project. Your Webpack or Babel will recognize the dependency like any other module in node_modules.</p><p>Lets check the following example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-rVC5K4PR-rJh_Re_9ztw.png" /></figure><p>The root project.json file has the following configuration.</p><pre>{<br>  &quot;private&quot;: true,<br>  &quot;workspaces&quot;: [&quot;project-a&quot;, &quot;project-b&quot;]<br>}</pre><p>The project-a package.json has the following configuration.</p><pre>{<br>  &quot;name&quot;: &quot;project-a&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;project-b&quot;: &quot;1.0.0&quot;<br>  }<br>}</pre><p>Quite important here is that you can use module import instead of relative path to the source code.</p><pre>// Bad<br>import projectB from &#39;../project-b/src/index&#39;;</pre><pre>// Good<br>import projectB from &#39;projectB&#39;;</pre><p>Be a consumer of your own library, like if you added the package from npm. Run simultaneous watchers on Webpack or Babel, both, for the library and for the main project. Your dev environment should produce publish ready content which you can consume from other packages in the project. This will prevent later issues with the support.</p><p>There are several problems related to symlinks. First one is related to git and has <a href="https://github.com/git-for-windows/git/issues/607">an issue in their Windows repo</a>. When you do git clean , your linked source code will be removed, because it is considered by git as part of the node_modules folder, which is usually in .gitignore file and is a subject for removing. So, what helped us before and considered as a cool feature is now hitting our back. This issue is quite similar when using Lerna and having packages depend on each other. This has quite several workarounds. For Lerna, for example, you can do lerna clean before the actual git clean. Lerna will take care of removing node_modules considering symlinks are there. This does not work if you’re using CI and/or CD where build agent, by default does git clean before checkout and you need to configure extra step to do a symlink removing. The solution of mine was to use clean script which does yarn unlink and then git clean.</p><p>Next problem is quite related JS compilation with Webpack and Babel. Common Webpack configuration looks like this:</p><pre>module: {<br>  rules: [<br>    {<br>      test: /<strong>\.</strong>m?js$/,<br>      exclude: <strong>/node_modules/</strong>,<br>      use: {<br>        loader: &#39;babel-loader&#39;,<br>        options: {<br>          presets: [&#39;@babel/preset-env&#39;]<br>        }<br>      }<br>    }<br>  ]<br>}</pre><p>Bear with me here. Keep in mind our symlinks. Problem here is that resolved paths won’t contain node_modules in them and won’t be excluded during code transformation by Babel. This might result (depends on the further configuration and tricks applied) in warnings or even errors, when ES6 module is trying to import ES5 module from the workspace. By simply excluding workspace in the configuration might be a solution.</p><p>Here I highlighted some issues I faced when using monorepo approach. Worth to mention that overall I’ve got the solution I was looking for. This simplified development process a lot, unified lint, build, test and release process, allowed to receive instant feedback on any changes in dependency modules etc. Also, aforementioned hoisting allowed us to align dependency versions and single lock file allows to keep track of these versions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17f9008097ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>