コード例 #1
0
 return packages.map(function (p) {
   return packageUtil.isPath(p)
       && typeof this.graphData[p] == 'object'
       && this.graphData[p].packageJSON
       && this.graphData[p].packageJSON.name
       && this.graphData[this.graphData[p].packageJSON.name]
     ? this.graphData[p].packageJSON.name
     : packageUtil.cleanName(p)
   }.bind(this))
コード例 #2
0
  , processPackage = function (parents, graphData, processSubgraph, pkg, callback) {
      var name = packageUtil.cleanName(pkg)

        , getJSONData = function (callback) {
            // get dependency list from package.json
            packageUtil.readPackageJSON(parents, name, function (err, json) {
              if (err) return callback(err) // wrapped in package-util.js
              callback(null, {
                  data         : json
                , dependencies : packageUtil.getDependenciesFromJSON(json)
              })
            })
          }

        , getDirectoryDependencies = function (callback) {
            // dependency list from the package's node_modules directory

            if (packageUtil.isPath(name)) {
              // not installed under ./node_modules/, 'name' is a dir, so don't fetch deps from dir/node_modules
              return callback(null, { dependencies: [] })
            }

            packageUtil.getDependenciesFromDirectory(parents, name, function (err, dependencies) {
              if (err) return callback(err) // wrapped in package-util.js
              callback(null, { dependencies: dependencies })
            })
          }

        , finish = function (err, data) {
            var childPackages

            if (err) {
              if (err.code == 'ENOENT') {
                graphData[name] = 'missing'
                return callback()
              }
              return callback(err) // wrapped in package-util.js (see getJSONData & getDirectoryDependencies)
            }

            // we have the data, now do something with it
            graphData[name] = {
                packageJSON  : data.json.data
              , dependencies : {} // init as empty
              , parents      : parents.slice(0) // make a copy of parents array
            }

            // concat dependencies in node_modules with those in package.json but don't duplicate
            childPackages = data.dir.dependencies.concat(data.json.dependencies.filter(function (p) {
              return data.dir.dependencies.indexOf(p) == -1
            }))

            // processSubgraph() is actually just constructDependencyGraphPart()
            processSubgraph(
                parents.concat([ pkg ])
              , graphData[name].dependencies
              , childPackages
              , callback
            )
          }

      if (graphData[name]) return callback() // already done this part of the graph

      async.parallel(
          {
              json : getJSONData
            , dir  : getDirectoryDependencies
          }
        , finish
      )
    }