A monorepo is the concept of many software packages being stored in the same SCM repository. There are several key benfits
- Monorepo dependencies are always on latest.
- Atomic multi-package code changes
- Simpler external dependency
- Upstream changes validated against downstream test suites
In this course, we’ll refactor a small client/server app into monorepo. By the end, we’ll have
- Monorepo dependencies automatically linked
- Parallized dependency-aware task execution for build, linting and testing
- Commands for CI that run tests on only the code affected by the change
- Support for some packages in the monorepo being more coupled with each other than others, by design (e.g. using private functionality)
- Automatic code documentation
We’re going to be using some of the latest and greatest tooling, including
pnpmlernav7nxfor distributed cachingapi-extractorfor.d.tsrollupsapi-documenterfor auto-generated docs- GitHub
CODEOWNERSto control who should review which parts of the monorepo? changesetsfor unified changelogsmanypkgfor detecting common pitfalls inpackage.jsons across your monoreposyncpack(or an equivalentnxtool) to rally your monorepo around a single version of each dependency- …and more!!!
Project setup
1. Make sure you have pnpm installed
If you don’t using volta (get it at https://volta.sh) is a great way to obtain it.
First, install volta
shcurl https://get.volta.sh | bash
You may need to close and reopen your terminal before your can verify that your environment has volta installed
shvolta --version> 2.0.2
Then you can run
shvolta install pnpm
And you should be good to go. Alternatively you can follow pnpm’s direct installation instructions
2. Check out the git repo
shgit clone git@github.com:mike-north/ts-monorepos-v2
3. Install dependencies
shcd ts-monorepos-v2 # Enter the project folderpnpm install # Install dependencies
4. Test whether basic tasks work
shpnpm run build # Build the projectpnpm run lint # Lint the projectpnpm run test # Test the project
5. Test whether the dev script works
shpnpm run dev
- You should be able to go to http://localhost:3000/api/seeds in a browser and see some JSON
- You should be able to go to http://localhost:5173/ and see a UI that looks like this