Monorepos will ruin your life – but they're worth it
thenable.io
thenable.io
Nx will figure out the affected dependency graph for packages in your mono repo so you are able to only build/test/deploy the changes.
It can get hard to get some things working well. Eg expo, which has a 3rd party package, but it's usually pretty far behind on the version of nx it supports.
Personally, I've just started using blitz js for smaller things, no need to split things into packages.
Monorepos might be good for Google or Facebook where you have company-size teams to maintain all the tooling around them and there is no risk of "the guy that did all the tooling left and now we don't know how this works anymore".
You're not facebook, you're not google.
Keep services on their own repositories, with their own pipelines, don't write internal libraries that reinvent the wheel, and if you do, just create them in their own repo and publish them as packages.
Monorepos and all the associated bullshit is for teams which want to do technology for the sake of technology and for their resume. 90% of companies don't need monorepos, don't waste company's time and money because something is just fun to you.
DAG Pipelines to the rescue! Even our horrific 40+ services with 5+ React apps monorepo only takes 10 minutes to build because we build everything in parallel!
Is this a joke? That’s so long! I feel like 1 minute is too long since I lose my train of thought and get distracted
Those are rookie numbers! We have literally 1000s of services and apps in one single monorepo. A full build in parallel takes upwards of 12 hours.
[0] https://www.adaltas.com/en/2021/01/05/js-monorepos-project-i...
yarn plugin import https://yarn.build/latest
It’s really powerful when you use many local workspaces (packages), that have dependencies on each other. Provided they’re not circular. Theres a build command that runs in the right topological order calling build in your package.json. And caching the status of builds, so it only rebuilds with changes.
After that I added a yarn test command, to do the same thing but run test.
This has been really powerful for me. As it’s meant I can treat each workspace as if it was coming from NPM. As such, boundaries are hard, and defined.
I often need to ship a nodejs lambda, so I added a bundle command. That works similar to how Bazel does a build. It copies your repo to a temporary directory. Then removes everything you don’t need (local workspaces that aren’t dependencies of the workspace to bundle). And drops an entrypoint.js in the root dir, that reexports your main script (as defined in package.json). Finally it zips it up, ready for lambda or any other nodejs environment.
And finally, because yarn.build just calls the build script, it can build anything. So I’ve used I with go quite a bit. You just call go build in the package.json build script (add a test script and test it along with the other workspaces).
But some go devs aren’t big fans of a package.json hanging around. So I wrote this other neat (and kinda wild) plug-in [1], that allows package.json to be written as package.yaml (with comments!). Like actual yaml. yarn plugin import https://yarn.build/yaml
The yaml plug-in sits in between the file system. It works much better than I expected, though I mostly use it on non-node stuff. As node expects package.json on disk for some stuff. Thankfully the plug-in is opt in per workspace, so it happily falls back to json if that’s there. And only uses yaml if there’s a package.yaml and no package.json.[1] https://github.com/ojkelly/yarn.build#plugin-package-yaml