#monorepo mode - package.json

10 messages · Page 1 of 1 (latest)

sharp sentinel
#

In monorepo mode, the package.json stays at the root by default. Each project generated is independent of one other, but they all share the same package.json. I am a little confused about how this is best organized as the repository grows.

  1. Should/can I have a packages.json each project have its own package.json? Different projects will have different dependency requirements, and having one big giant manifest of everything seems odd.

  2. If the intent is to have only one package.json for all projects, what is the best way to organize all the scripts that run the individual apps?

tawdry bay
#
  1. not really
  2. Honestly, use a monorepo tool like Nx. Nest's monorepo mode is very basic in comparison and is really only useful when you only have nest projects with similar dependencies. With Nx you can generate a package.json for each application after using a single package.json in the dev env
sharp sentinel
tawdry bay
#

I've got a pretty great sample if you wanna take a look

sharp sentinel
#

yea that would be great

tawdry bay
#

This monorepo has a nest app, react app, and nest-commander app, along with libs for migrations, docker build plugin, database access, ui components, and server modules

fast perch
#

@sharp sentinel - Have a look at Rush. It specifically requires for each project in the monorepo to have its own package.json and when you do a rush install or rush update it "merges" the packages all to a top level node_modules. I'm using Rush with PNPM and I wont say I haven't had any issues, but probably 80% of them were due to my own denseness. Rush also allows each project to have different dependencies of the same package, if you needed it, however that is considered bad practice. Check it out. https://rushjs.io/pages/intro/welcome/

Rush makes life easier for JavaScript developers who build and publish many NPM packages at once. If you're looking to consolidate all your projects into a single repo, you came to the right place! Rush is a fast, professional solution for managing this scenario. It gives you:

sharp sentinel
#

@tawdry bay I immediately see the value of Nx. What's your take on using Nests monorepo mode with Nx in place? With the Nx tooling in place, seems like enabling Nest monorepo mode could be some sort of anti-pattern to Nx. It's like a monorepo within a monorepo.

Essentially, add apps to the Nest monorepo or add apps to the Nx workspace?

tawdry bay
#

I don't ever really use nest's monorepo mode, if that helps answer your question. I almost always reach for Nx first