code: function setSortingLevels(packages, type) {
    function setLevel(initial, pkg) {
      var level = Math.max(pkg.sortingLevel || 0, initial);
      var deps = Object.keys(pkg.dependencies);
      // console.log('setLevel', pkg.name, level);
      pkg.sortingLevel = level;
      deps.forEach(depName => {
        depName = sanitizeRepo(depName);
        var dep = find(packages, _ => {
          if (type === "component") {
            var repo = _[dependencyLocator[type]];
            if (repo === depName) {
              return true;
            }
            // nasty hack to ensure component repo ends with the specified repo
            // e.g. "repo": "https://raw.github.com/component/typeof"
            var suffix = "/" + depName;
            return repo.indexOf(suffix, repo.length - suffix.length) !== -1;
          }
          return _[dependencyLocator[type]] === depName;
        });
  
        if (!dep) {
          var names = Object.keys(packages).map(_ => {
            return packages[_].name;
          }).join(", ");
          throw new Error("Dependency \"" + depName + "\" is not present in the list of deps [" + names + "]. Specify correct dependency in " + type + ".json or contact package author.");
        }
        setLevel(initial + 1, dep);
      });
    }
    packages.forEach(setLevel.bind(null, 1));
    return packages;
  }
docs: Iterate recursively over each dependency and increase level on each iteration.