![]() This blog post comes with working code that you can try out for yourself on GitHub. I’m also using it to manage my open-source Data-Forge Notebook project, which has projects for the browser and Electron that share packages between them, all contained within a monorepoĢ.I’m now using pnpm for my company’s closed-source microservices meta repo.Of course, pnpm is very flexible and these workspaces can be used in many different ways. The diagram below shows the layout of a typical full-stack, multipackage monorepo: I thought this was the best way to show the benefits of pnpm workspaces because I can show you how to share a package in the monorepo between both the frontend and backend projects. The monorepo contains both frontend and backend components, a browser-based UI, and a REST API. It’s full-stack because our repo contains a full-stack project. Normally, to share a package between multiple projects, we’d have to publish it to npm, but this would be overkill if the package were only going to be shared between a small number of projects, especially for proprietary or closed-source projects. A Node.js package is a project with a p ackage.json metadata file in its root directory. It’s multipackage because we have one or more packages in the repo. A meta repo has the convenience of a monorepo, but allows us to have separate code repos for each sub project. We can go from monorepo to meta repo by splitting each sub-project into its own repository, then tying them all back together using the meta tool. Instead of a monorepo, it could also be a meta repo, which is a great next step for your monorepo once it’s grown too large and complicated - or, for example, you want to split it up and have separate CI/CD pipelines for each project. It’s a monorepo because we have packed multiple (sub-)projects into a single code repository, usually because they belong together for some reason, and we work on them at the same time. ![]() In this case, we are talking about a Git code repository, with Git being the preeminent, mainstream version control software. It’s a repo because it’s a code repository. So what on earth are we talking about here? Let me break it down. What is a full-stack, multipackage monorepo? If you only care about how pnpm compares to npm, please jump directly to section 5. ![]() Running scripts on all packages in TypeScript.Sharing type definitions between projects.Sharing types in a full-stack TypeScript monorepo.Running scripts on all packages in JavaScript.Sharing code in a full-stack JavaScript monorepo.What is a full-stack, multipackage monorepo?.In this blog post, we’ll explore how to use pnpm to manage our full-stack, multipackage monorepo through the following sections: Though I started using pnpm for its renowned performance (and I wasn’t disappointed), I quickly discovered that pnpm has many special features for workspaces that make it great for managing a multipackage monorepo (or even a multipackage meta repo). For most new (and even some old) projects, I’ve replaced npm with pnpm and my working life is so much better for it. Then, at my colleagues’ insistence, I started using pnpm and I haven’t gone back. I spent so much time sitting and waiting for it to finish and thinking, there must be a better way! Working with more and more code repos meant doing more frequent npm installs. It seemed to be getting slower and slower. I became very frustrated working with npm. The “p” in pnpm stands for “performant” - and wow, it really does deliver performance! Managing a full-stack, multipackage monorepo using pnpm He is VP of Engineering at Hone and currently writing Rapid Fullstack Development and the second edition of Bootstrapping Microservices.įollow on Twitter for updates. Ashley Davis Follow Ashley Davis is a software craftsman and author.
0 Comments
Leave a Reply. |