Assuming I have an external NPM lib dependency that is shared among different workspaces, is it possible to set a single version for all dependant workspaces? What if this dependency is a peer or dependency ?
e.g
// external-lib-dep in npm
//package1's package.json
...
"dependencies": {
"external-lib-dep": "^1.0.0"
}
...
// package2's package.json
...
"dependencies": {
"external-lib-dep": "^1.2.0"
}
...
// package3's package.json
...
"dependencies": {
"very-different-external-lib-dep": "^1.2.0"
}
...
Is it possible to somehow "share" the versions of deps instead of copying it over and over again? (just like dependencyManagement
in parent pom in maven).
What if the monorepo holds "common" libs for all services in a certain company. Will they solution work when I use one of the libs in my service?
It is possible to share the versions of dependency among workspaces in one specific way.
Your workspaces should declare
external-lib-dep
in theirpeerDependencies
. And in your monorepo rootpackage.json
you should declareexternal-lib-dep
independencies
. This way your workspaces will "inherit"external-lib-dep
version from the root workspace.