The fix is to append the contents of ~/.npmrc to the local /npmrc rather than overwrite it.
Also, this fixes an issue where only the first line would be appended (`always-auth` etc was getting lost). This was caused by echo only printing to the first carriage return. I've also stopped replacing whitespace with newlines as it seems error prone.