Search code examples
node.jsnpmlerna

Install the dev dependencies of my dependencies


I have a monorepo where I have a /packages folder with many packages.

I can use npm i ./packages or npm i if they are already specified using using the file pointer.

Looks something like this:

  "dependencies": {
    "@reggi/command": "file:packages/command",
    "@reggi/dep-merge": "file:packages/dep-merge",
    "@reggi/dep-merge-cli": "file:packages/dep-merge-cli",
    "@reggi/dep-pointer": "file:packages/dep-pointer"
  }

The issue is that if I install these packages I don't get dev dependencies.

What I really want is to also install the devDependencies of these dependencies.

lerna a popular tool that has pioneered the usage of monorepos, suggests that you should add all the devDependencies for these packages in the root package. The issue with this is that it eliminates the ability for two packages to depend on different versions of a given dev dependency.

What I have done is created a script that merges all the devDependencies into dependencies at preinstall then undoes the changes. This works but can be kind of wonky at times, especially when explaining all this to shrinkwrap.

It would be nice if I could just npm i --allDevDepsFromDeps and it would install all of my dependencies dev dependencies.

Is there any other solution I am missing?


Solution

  • I don't see what you're trying to achieve there, aren't the devDepencies used for ... development?

    If you want different version for different package just don't put them in the root but in each package.

    The issue is that if I install these packages I don't get dev dependencies.

    You should consider those packages as 'production'/'bundled' packages, you don't need dev dependencies in this case.

    For example, when you are working on @pkg/A, it will have its own devDep but then if you work on @pkg/B that depends on @pkg/A, the @pkg/A should be the production/bundled version (without devDeps).

    Maybe you should have a look at bundledDependencies or peerDependencies, that might help you.