"postinstall" script does not run after "npm install some-package"
The recommended way to make sure that patch-package applies its patches is to set it to run within package.json's postinstall script.
However, for npm at least, the postinstall script is only called when running npm install -- not when installing a new package (eg. npm install lodash). I've confirmed this myself (just now and prior), and it has also been confirmed by others. (eg. see here)
This is not ideal, because it means that if someone, say, uninstalls a package that has a patch applied -- but then realizes that they still want/need the package, and reinstalls it -- it will leave their node_modules in an incorrect state (without the patch applied).
This answer here suggests a possible solution. However, it doesn't work on Windows (I just tried it), because the hook-script filename has to exactly be "postinstall", which makes Windows unable to recognize it as an executable (it just errors with Exit status 1, and doesn't run the file, regardless of if I use a (previously) .exe, .js, .bat, or .cmd file).
Does anyone know of a way to set up patch-package to run after npm install XXX commands, in a way that also works on Windows?
I managed to fix this by making my published module (in my case, an executable) run patch-package based on how the package is installed - this migrated from using postinstall (install time) but instead running this at runtime
(more info: https://www.jvt.me/posts/2025/04/12/patch-package-distribute/)