Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn (or npm) swap nested dependency with a fork

Tags:

npm

yarnpkg

In my package.json I have a package:

{
  "somepackage": "^6.5.1"
}

This package has a dependency (from somepackage's package.json):

{
  "someotherpackage": "^9.4.2"
}

I want to swap someotherpackage to one of its fork. I know of yarn's Selective dependency resolution feature, but I guess that is only for different versions of the same package.

I could as well fork somepackage and change its dependencies manually, swapping someotherpackage to someotherpackage-fork, but if there is another way I would take that.

Thanks!

like image 958
marchello Avatar asked Jan 29 '18 16:01

marchello


1 Answers

The mentioned selective dependency resolution feature is the way to go. Under the hood it seems to be resolving packages the same way dependencies does which allows us to do the following:

"resolutions": {
  "**/someotherpackage": "npm:someotherpackage-fork@*"
}

You can also specify which version of your fork you want:

"resolutions": {
  "**/someotherpackage": "npm:[email protected]"
}

I haven't confirmed if this works for Yarn version 2 yet.

Showcase: https://github.com/dimitarnestorov/yarn-resolutions-showcase

like image 108
Dimitar Nestorov Avatar answered Oct 15 '22 10:10

Dimitar Nestorov