简体   繁体   中英

How to patch jest-rutime when using Yarn 2?

I am trying to follow the instructions in this repository to patch Jest.

Patch Jest .

It is suggested to use patch-package but I figured out that I can use yarn patch when using Yarn 2.

I managed to patch jest-runtime but seems Jest doesn't seem to require jest-runtime in its package so I don't know where it comes from to use it as a reference to declare the patched file.

Jest package.json

I understand if Jest was the one that needs to be patched I could declare it like this:

package.json

"devDependencies": {
   "jest": "patch:jest@26.6.3#./patches/jest.patch"
}

I tried to use the same logic to include the following code to include jest-runtime but it didn't work.

"devDependencies": {
   "jest": "^26.6.3",
   "jest-runtime": "patch:jest-runtime@26.6.3#./patches/jest-runtime.patch"
}

How can I declare this patched jest-runtime so Jest can use it?

The Resolutions field in the manifest is the correct approach to declare the patched modules that we didn't add to devDependencies such as submodules.

The resolutions field allows you to instruct Yarn to use a specific resolution instead of anything the resolver would normally pick. This is useful to enforce all your packages to use a single version of a dependency, or backport a fix.

The fix for that issue:

{
 ...
  "dependencies": {
    "jest": "^26.6.3",
  },
  "resolutions": {
    "jest-runtime": "patch:jest-runtime@26.6.3#./patches/jest-runtime.patch"
  },
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM