Pato
Pato

Reputation: 219

peerDependencies configuration for publishable libraries with NX & Angular

I have a monorepo using NX & Angular and I am publishing some libs to NPM and i have the following scenario

apps
   only_App
libs
   lib_A // v1.0.0
   lib_B // v1.0.0
   lib_C // v1.0.0

lib_A depends on lib_B and lib_C.

In the pre-built package.json of lib_A doesn’t have any peerDependency and after i build it prior publishing it, automatically adds the peerDependencies like

// BUILT lib_A/package.json

{
...,
"peerDependencies":{
   "@myScope/lib-b": "1.0.0", //specifically that version
   "@myScope/lib-c": "1.0.0",
}
}

The problem is when i publish lib_A and use it in another project (outside NX and this repo). It will always expect me to use lib_B and lib_C v1.0.0, if I make a patch in lib_B upgrading it to v1.0.1, then im forced to also rebuild lib_A updating the peerDependency version. publish lib_A and upgrade lib_A's version too.

Is there a way i can configure this so when i build lib_A adds the ^ to my libs? i.e

// BUILT lib_A/package.json

{
...,
"peerDependencies":{
   "@myScope/lib-b": "^1.0.0", //automatically includes the ^ (caret)
   "@myScope/lib-c": "^1.0.0",
}
}

Allowing me in this way if I have a minor patch in lib_B, just to update lib_B and not lib_A as well.

So far the only “solution” is to manually copy and paste the peer dependencies generated in the built package.json in the pre-built package.json and add the ^ manually, but i know this is not scalable

Upvotes: 14

Views: 5505

Answers (1)

Olivier.B
Olivier.B

Reputation: 109

Add "buildableProjectDepsInPackageJsonType": "dependencies" in your build target in your project.json file.

https://nx.dev/packages/js/executors/tsc#buildableprojectdepsinpackagejsontype

Upvotes: -3

Related Questions