This is an example repo which uses Yarn Workspaces and Yarn 2.
The repo contains a bunch of example packages:
devtoolsis a fantasy CLI which helps managing node.js projects. It holds a cyclic dependency withenv-managerto illustrate the use case.env-manageris a simple shared library which only exists to depend on the made-up CLIdevtools.greeter-serviceis a very simple backend which runs on Hapi and is used to illustrate how a single service can be released out of a monorepo.text-libis a plain ol' shared library which is consumed by thegreeter-service.
Only greeter-service and devtools provide any runnable logic per se. The other two packages just exist in their workspace to show how code interacts in the context of a monorepo.
Inside packages/greeter-service you can use make to run the existent steps:
make buildto build the production docker container for the service.make runto run it on your machine
Since devtools is nothing much but a CLI, it cannot be productionised but only released:
-
make release-minorto release a new minor and automatically bump the new version on all of its consumers. -
make release-majorto do the same but with a major version instead.
This sample monorepo supports a couple of use cases:
- Install necessary dependencies only: In docker, only install the dependencies which are strictly needed, thus keeping the production image small.
- Automatic release and version bumping: When a new version of a package is released, all consuming workspaces automatically get that version bumped in their deps tree.
- Cyclic dependencies: Releases do not get messed up by a cyclic dependency.
There are still a couple of things to be done. Especially these two scenarios deserve a test:
- Showcase the use of different package versions alongside each other, all handled with a central lock file