fix depth==maxDepth edge case

Part of the patch for https://github.com/npm/npm/pull/5276