diff options
Diffstat (limited to 'lib/ls.js')
-rw-r--r-- | lib/ls.js | 47 |
1 files changed, 32 insertions, 15 deletions
@@ -13,12 +13,12 @@ var archy = require('archy') var semver = require('semver') var color = require('ansicolors') var npa = require('npm-package-arg') -var iferr = require('iferr') var sortedObject = require('sorted-object') var extend = Object.assign || require('util')._extend var npm = require('./npm.js') var mutateIntoLogicalTree = require('./install/mutate-into-logical-tree.js') var computeMetadata = require('./install/deps.js').computeMetadata +var readShrinkwrap = require('./install/read-shrinkwrap.js') var packageId = require('./utils/package-id.js') var usage = require('./utils/usage') var output = require('./utils/output.js') @@ -36,15 +36,13 @@ function ls (args, silent, cb) { silent = false } var dir = path.resolve(npm.dir, '..') - readPackageTree(dir, andComputeMetadata(iferr(cb, function (physicalTree) { - lsFromTree(dir, physicalTree, args, silent, cb) - }))) -} - -function andComputeMetadata (next) { - return function (er, tree) { - next(null, computeMetadata(tree || {})) - } + readPackageTree(dir, function (_, physicalTree) { + if (!physicalTree) physicalTree = {package: {}, path: dir} + physicalTree.isTop = true + readShrinkwrap.andInflate(physicalTree, {fakeChildren: true}, function () { + lsFromTree(dir, computeMetadata(physicalTree), args, silent, cb) + }) + }) } function inList (list, value) { @@ -224,7 +222,11 @@ function getLite (data, noname, depth) { ', required by ' + packageId(data) lite.problems.push(p) - return [d, { required: dep.requiredBy, missing: true }] + if (dep.dependencies) { + return [d, getLite(dep, true)] + } else { + return [d, { required: dep.requiredBy, missing: true }] + } } else if (dep.peerMissing) { lite.problems = lite.problems || [] dep.peerMissing.forEach(function (missing) { @@ -262,7 +264,7 @@ function unloop (root) { var deps = current.dependencies = current.dependencies || {} Object.keys(deps).forEach(function (d) { var dep = deps[d] - if (dep.missing) return + if (dep.missing && !dep.dependencies) return if (dep.path && seen[dep.path]) { dep = deps[d] = extend({}, dep) dep.dependencies = {} @@ -353,11 +355,26 @@ function makeArchy_ (data, long, dir, depth, parent, d) { unmet = color.bgBlack(color.red(unmet)) } } - data = unmet + ' ' + d + '@' + data.requiredBy + var label = data._id || (d + '@' + data.requiredBy) + if (data._found === 'explicit' && data._id) { + if (npm.color) { + label = color.bgBlack(color.yellow(label.trim())) + ' ' + } else { + label = label.trim() + ' ' + } + } + return { + label: unmet + ' ' + label, + nodes: Object.keys(data.dependencies || {}) + .sort(alphasort).filter(function (d) { + return !isCruft(data.dependencies[d]) + }).map(function (d) { + return makeArchy_(sortedObject(data.dependencies[d]), long, dir, depth + 1, data, d) + }) + } } else { - data = d + '@' + data.requiredBy + return {label: d + '@' + data.requiredBy} } - return data } var out = {} |