This is why it's important to use containers for development - or at least SELinux on your development host machine.
Simply restrict file access of npm to its cache folders, so it cannot access your other user configuration files.
Use additionally a host firewall like opensnitch to block npm from any other host than npmjs.com.