在我的package.json我有一个包:
{
"somepackage": "^6.5.1"
}
Run Code Online (Sandbox Code Playgroud)
这个包有一个依赖项(来自somepackage's package.json):
{
"someotherpackage": "^9.4.2"
}
Run Code Online (Sandbox Code Playgroud)
我想将另一个包交换到它的一个叉子上。我知道纱线的Selective dependency resolution功能,但我想这仅适用于同一包的不同版本。
我也可以somepackage手动fork并更改其依赖项,交换someotherpackage到someotherpackage-fork,但如果有另一种方式,我会采取这种方式。
谢谢!
提到的选择性依赖解析功能就是可行的方法。在幕后,它似乎以相同的方式解析包dependencies,这允许我们执行以下操作:
"resolutions": {
"**/someotherpackage": "npm:someotherpackage-fork@*"
}
Run Code Online (Sandbox Code Playgroud)
您还可以指定您想要的分叉版本:
"resolutions": {
"**/someotherpackage": "npm:someotherpackage-fork@3.0.2"
}
Run Code Online (Sandbox Code Playgroud)
我尚未确认这是否适用于 Yarn 版本 2。
展示: https: //github.com/dimitarnestorov/yarn-resolutions-showcase