`npm ls --long --depth 0` breaks for deps with deps

Fixes #6311 by explicitly checking depth before adding children. This may not be the rootmost fix for this issue, but it works, not just with the test, but with all the example apps I throw at it (including my global install).

/cc @iarna for review