Fix some edge cases

cc @sh1mmer @Matt-Esch
I hope there is no mismatch between local npm and any other programmatic use of npm ...