patch-package is a tool for this specific purpose
https://www.npmjs.com/package/patch-package
You commit your changes as a diff text file and add the patch-package command to your post-install hook so it runs after every install
My main use for it is fixing other packages' package.json exports field and Typescript definitions