Skip to content

Understanding monorepo in JS ecosystem

Monorepo allows developers to work in the single space where all projects live and their connections are visible. It simplifies cross-project changes, code and tooling reuse and encourages consistency and standardization. The expense is the overal codebase size and complexity, slower setup and less freedom given the consistency and centralisation. These points are critical especially for newcomers. Additional tooling may be required to manage the repo as well as additional docs to explain repo structure with respect to each stakeholder.

Managing multiple packages in monorepo

If the monorepo contains single package, no additional tooling is required. Otherwise it’s needed to use a tool to manage multiple packages. npm recently announced workspaces, a lower level feature that allows multiple projects (packages) to live within one repository. A higher level tool may be utilized to simplify monorepo management. The most popular tool in this category is Lerna. Lerna helps with dependency management, versioning, publishing and running scripts within many individual packages in monorepo using single command. Lerna also allows to import packages to a monorepo while keeping their git histories.

Side effects and future developments

Dev tooling, config and code-style sharing adoption is expected with monorepo.

Future project requirements may be better satisfied with monorepo. For example if the projects’s next opportunity lays in cloud-sync service, it will be desirable to share critical schemas and typings in standalone package within monorepo.

Managing multiple repositories

An alternative to mono and multi repo is meta repo, which allows to manage multiple repositories from single point e.g. create branch for a feature or commit in multiple repositories by single command. Additional cost of learning, setup, using and maintenance of meta-repo management tool must be considered though.

The meta repo approach brings access management opportunities. A standard mono-repo gives access to all the code whereas in meta repo, we can work on specified subset of repositories as if they were mono-repo. This is be useful in cases where its required to restrict developers access to the code.

Many & monorepo comparison table

Multiple repositoriesMonorepository
philosophy
more decentralisedmore centralised
cognitive load
1 logical project>= logical projects
1:1 of repo to package1:n of repo to packages
smaller codebase complexitybigger codebase complexity
difficult global cross-project overvieweasier global cross-project overview
development
low global code visibilityhigh global code visibility
difficult code reuseeasy code reuse
faster setup, builds and testsslower setup, builds and tests
discourages consistencyencourages consistency
granular version informationallows unified versioning
hard cross-project changes & refactoringsimplified cross-project changes & refactoring
difficult global code reviewsimple global code review
difficult integration testseasier integration tests
difficult dev tooling and config sharingsimple dev tooling and config sharing
open source tool and IDEs standardless tooling and IDEs support
culture
more individualisticteam unification & collaboration across teams
less activitymore activity
multiple places to submit issueone place to submit issue

Sources

  1. ‘Advantages of monorepos’. [Online]. Available: https://danluu.com/monorepo/
  2. N. Brousse, ‘The issue of monorepo and polyrepo in large enterprises’, in Proceedings of the Conference Companion of the 3rd International Conference on Art, Science, and Engineering of Programming, Genova Italy: ACM, Apr. 2019, pp. 1–4. doi: 10.1145/3328433.3328435.
  3. G. Brito, R. Terra, and M. T. Valente, ‘Monorepos: A Multivocal Literature Review’, arXiv:1810.09477 [cs], Oct. 2018, Accessed: Oct. 08, 2021. [Online]. Available: http://arxiv.org/abs/1810.09477