gather-dependencies.js
function buildDependencyReport (report, data, options, depth) {
  if (!report) report = {}
  if (!data) data = {}
  if (!options) options = {}
  if (!depth) depth = 0

  var lookup = {}
  var npmDependencyTypes = depth ? depthNpmDependencyTypes : topLevelNpmDependencyTypes

  // build list of all dependencies
  npmDependencyTypes.forEach(function types (type) {
    if (data.package[type] && Object.keys(data.package[type]).length) {
      report[type] = data.package[type]

      // remap versions as objects instead of a string
      Object.keys(report[type]).forEach(function dep (name) {
        // build lookup to reference back to build off of
        lookup[name] = type
        report[type][name] = { requestedVersion: report[type][name] }
      })
    }
  })

  data.children.forEach(function childDeps (depData) {
    if (!lookup[depData.package.name]) return // not a relevant dependency (probably devDep)

    var entry = report[lookup[depData.package.name]][depData.package.name]
    entry.version = depData.package.version
    entry.from = depData.package._from
    entry.realpath = depData.realpath

    buildDependencyReport(entry, depData, options, depth + 1)
  })

  return report
}
function buildDependencyReport (report, data, options, depth) {
  if (!report) report = {}
  if (!data) data = {}
  if (!options) options = {}
  if (!depth) depth = 0

  var lookup = {}
  var npmDependencyTypes = depth ? depthNpmDependencyTypes : topLevelNpmDependencyTypes

  // build list of all dependencies
  npmDependencyTypes.forEach(function types (type) {
    if (data.package[type] && Object.keys(data.package[type]).length) {
      report[type] = data.package[type]

      // remap versions as objects instead of a string
      Object.keys(report[type]).forEach(function dep (name) {
        // build lookup to reference back to build off of
        lookup[name] = type
        report[type][name] = { requestedVersion: report[type][name] }
      })
    }
  })

  data.children.forEach(function childDeps (depData) {
    if (!lookup[depData.package.name]) return // not a relevant dependency (probably devDep)

    var entry = report[lookup[depData.package.name]][depData.package.name]
    entry.version = depData.package.version
    entry.from = depData.package._from
    entry.realpath = depData.realpath

    buildDependencyReport(entry, depData, options, depth + 1)
  })

  return report
}
function buildDependencyReport ( report , data , options , depth ) { if ( ! report ) report = { } if ( ! data ) data = { } if ( ! options ) options = { } if ( ! depth ) depth = 0 var lookup = { } var npmDependencyTypes = depth ? depthNpmDependencyTypes : topLevelNpmDependencyTypes // build list of all dependencies npmDependencyTypes . forEach ( function types ( type ) { if ( data . package [ type ] && Object . keys ( data . package [ type ] ) . length ) { report [ type ] = data . package [ type ] // remap versions as objects instead of a string Object . keys ( report [ type ] ) . forEach ( function dep ( name ) { // build lookup to reference back to build off of lookup [ name ] = type report [ type ] [ name ] = { requestedVersion : report [ type ] [ name ] } } ) } } ) data . children . forEach ( function childDeps ( depData ) { if ( ! lookup [ depData . package . name ] ) return // not a relevant dependency (probably devDep) var entry = report [ lookup [ depData . package . name ] ] [ depData . package . name ] entry . version = depData . package . version entry . from = depData . package . _from entry . realpath = depData . realpath buildDependencyReport ( entry , depData , options , depth + 1 ) } ) return report }
Build dependency report
@param  {object} report report object being operated on
@param  {object} data   npm dependency tree data
@param  {object} options
@param  {number} depth  Depth to evaluate. 0 is top level only.
@return {object}        Completed report object.
Build dependency report