Upgrade global npm modules safely

As per npm/npm#6247.