问题描述
我正在尝试按照此存储库中的说明修补 Jest。
建议使用 patch-package,但我发现在使用 Yarn 2 时可以使用 yarn patch。
我设法修补了 jest-runtime,但似乎 Jest 的包中似乎不需要 jest-runtime
,所以我不知道它来自哪里,以将其用作声明修补文件的参考。
我知道如果 Jest 是需要修补的那个,我可以这样声明:
package.json
"devDependencies": {
"jest": "patch:[email protected]#./patches/jest.patch"
}
我尝试使用相同的逻辑来包含以下代码以包含 jest-runtime
,但没有奏效。
"devDependencies": {
"jest": "^26.6.3","jest-runtime": "patch:[email protected]#./patches/jest-runtime.patch"
}
我如何声明这个打过补丁的 jest-runtime 以便 Jest 可以使用它?
解决方法
清单中的 Resolutions 字段是声明我们未添加到 devDependencies
的修补模块(例如子模块)的正确方法。
resolutions
字段允许您指示 Yarn 使用特定分辨率,而不是解析器通常会选择的任何分辨率。这对于强制所有包使用单个版本的依赖项或向后移植修复程序很有用。
该问题的修复:
{
...
"dependencies": {
"jest": "^26.6.3",},"resolutions": {
"jest-runtime": "patch:[email protected]#./patches/jest-runtime.patch"
},}