code: function mapByDepth(rootPackage) {
      var depth = 0
        , allDeps = {}
        , superDepsList = {}
        ;
  
      function traverseDeps(childPackage) {
        depth += 1;
  
        childPackage.dependencyTree = childPackage.dependencyTree || {};
        Object.keys(childPackage.dependencyTree).forEach(function (depName) {
          var childDeps = (childPackage.dependencyTree[depName] || {}) || {}
            ;
  
          if (superDepsList[depName]) {
            // a dependency can't (meaning shouldn't) have a path in which it depends on itself
            // this kind of resolution isn't as important as it once was
            // since the modules can be loaded out-of-order
            return;
          }
  
          superDepsList[depName] = true;
  
          allDeps[depth] = allDeps[depth] || [];
          allDeps[depth].push(depName);
  
          if (childDeps) {
            traverseDeps(childDeps);
          }
  
          superDepsList[depName] = false;
        });
  
        depth -= 1;
      }
  
      traverseDeps(rootPackage);
  
      return allDeps;
    }
docs: You could traverse it like this