admin管理员组文章数量:1310160
Is there some smart or "industry standard" way to keep dependencies in sync inside workspaces/modules in a monorepo?
Let's say we have following structure in the repository
AwesomeProject/
├─ workspaceA/
│ ├─ packageA.json
├─ workspaceB/
│ ├─ packageB.json
├─ workspaceC/
│ ├─ packageC.json
packageRoot.json
We can install a dependency into a workspace with npm install --save --workspace=workspaceA
. Let's assume that we are using some dependency in two or more of our workspaces i.e. axios
. At some point the dependency is updated into only one of the workspaces. This happens multiple times during the development along the years and soon we'll end up into a situation where the workspaces are not using the same version of the dependency anymore. As time passes, this might become a big problem and it is really cumbersome to start updating and syncing the packages.
As a solution to this in some projects I have used overrides in the root package.json.
// packageA.json and packageB.json
{
...
dependencies: {
...
axios: "*",
...
}
}
packageRoot.json
{
...
overrides: {
axios: "1.2.3",
...
}
}
This works fine to some extent. I know this is kind of risky as overrides is overriding also the subdependencies from other dependencies, if they happen to have any overridden dependencies listed as their dependency. The smaller the project, the less likely this conflict is to happen.
However, on the contrary, the bigger the project grows, the more likely you are going to run into problems with this overriding method.
So, is there a way to define the dependencies in a monorepo so that all the workspaces are using the same version of a dependency they are all using without the need to define these overrides? If you update the dependency X it is updated in all workspaces, but at the same time the 3rd party dependencies keep using their defined dependencies unless specifically overriden in the overrides.
There might be different ways to do it depending which package manager is used, so solution for each package manager is welcome. And if there is a solution that suits all the package managers even better!
本文标签: npmHow to keep monorepo deps in sync in JSTS projectStack Overflow
版权声明:本文标题:npm - How to keep monorepo deps in sync in JSTS project? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741827394a2399725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论