diff options
author | Rebecca Turner <me@re-becca.org> | 2017-06-29 08:40:13 +0300 |
---|---|---|
committer | Kat Marchán <kzm@sykosomatic.org> | 2017-07-06 00:58:39 +0300 |
commit | 47e8fc8eb9b5faccef9e03ab991cf37458c16249 (patch) | |
tree | b63bbf4115b5068b38c1915246e8a9f8a9721c07 /lib | |
parent | 4f45ba222e2ac6dbe6d696cb7a8e678bbda7c839 (diff) |
ls: Take shrinkwrap into account in ls
PR-URL: https://github.com/npm/npm/pull/17508
Credit: @iarna
Reviewed-By: @zkat
Diffstat (limited to 'lib')
-rw-r--r-- | lib/install/inflate-shrinkwrap.js | 1 | ||||
-rw-r--r-- | lib/install/mutate-into-logical-tree.js | 7 | ||||
-rw-r--r-- | lib/ls.js | 47 |
3 files changed, 39 insertions, 16 deletions
diff --git a/lib/install/inflate-shrinkwrap.js b/lib/install/inflate-shrinkwrap.js index eec447789..26a6d9f53 100644 --- a/lib/install/inflate-shrinkwrap.js +++ b/lib/install/inflate-shrinkwrap.js @@ -105,6 +105,7 @@ function makeFakeChild (name, topPath, tree, sw, requested) { const pkg = { name: name, version: sw.version, + _id: name + '@' + sw.version, _resolved: adaptResolved(requested, sw.resolved), _requested: requested, _optional: sw.optional, diff --git a/lib/install/mutate-into-logical-tree.js b/lib/install/mutate-into-logical-tree.js index 018745cc5..37f90802a 100644 --- a/lib/install/mutate-into-logical-tree.js +++ b/lib/install/mutate-into-logical-tree.js @@ -81,7 +81,12 @@ function translateTree_ (tree, seen) { pkg._dependencies = pkg.dependencies pkg.dependencies = {} tree.children.forEach(function (child) { - pkg.dependencies[moduleName(child)] = translateTree_(child, seen) + const dep = pkg.dependencies[moduleName(child)] = translateTree_(child, seen) + if (child.fakeChild) { + dep.missing = true + dep.optional = child.package._optional + dep.requiredBy = child.package._spec + } }) function markMissing (name, requiredBy) { @@ -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 = {} |