Patching a third-party dependency with style

Avatar

Share

ย โ€ขย 

3 months ago

ย โ€ขย 

View on Twitter

Ever wanted to change something in third-party dependency of your Node project but forking it would be too much hassle โ€“ or you were rather bending something which wouldn't make sense to contribute back at all? ๐Ÿงถ Yarn 2+ has "patch" command to help you do exactly that.

And as you guessed correctly, in that case, you need to make sure those patches are versioned with the rest of your code so it gets correctly patched in every environment you ran the code, similarly to "yarn.lock". https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

Also a little small tip โ€“ if you don't want yarn binary (which should be versioned in ".yarn/releases" โ€“ https://jukben.codes/one-yarn-to-rule-them-all) to skew your Github stats you can override it in ".gitattributes" like this. ๐Ÿ˜Ž

Btw does this all sound familiar? In the past I used https://www.npmjs.com/package/patch-package but it's nice to have it built-in, isn't it. ๐Ÿค“ Happy hacking!