diff options
author | claudiahdz <cghr1990@gmail.com> | 2020-08-28 00:42:21 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2020-09-16 18:16:37 +0300 |
commit | 3743a42c854d9ea7e333d7ff86d206a4b079a352 (patch) | |
tree | 7c0e03d367101692f4fa70c092428ef999ef0642 /lib/outdated.js | |
parent | 63005f4a98d55786fda46f3bbb3feab044d078df (diff) |
test: add outdated tests
PR-URL: https://github.com/npm/cli/pull/1750
Credit: @claudiahdz
Close: #1750
Reviewed-by: @ruyadorno
Diffstat (limited to 'lib/outdated.js')
-rw-r--r-- | lib/outdated.js | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/outdated.js b/lib/outdated.js index fa626ecbd..96179b13c 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -22,7 +22,7 @@ const usage = usageUtil('outdated', const completion = require('./utils/completion/none.js') function cmd (args, cb) { - outdated(args, cb) + outdated(args) .then(() => cb()) .catch(cb) } @@ -78,14 +78,12 @@ async function outdated (args) { } output(table(outTable, tableOpts)) } - - process.exitCode = outdated.length ? 1 : 0 } async function outdated_ (tree, deps, opts) { const list = [] - const edges = new Set() + const edges = new Set() function getEdges (nodes, type) { const getEdgesIn = (node) => { for (const edge of node.edgesIn) { @@ -94,8 +92,14 @@ async function outdated_ (tree, deps, opts) { } const getEdgesOut = (node) => { - for (const edge of node.edgesOut.values()) { - edges.add(edge) + if (opts.global) { + for (const child of node.children.values()) { + edges.add(child) + } + } else { + for (const edge of node.edgesOut.values()) { + edges.add(edge) + } } } @@ -107,30 +111,19 @@ async function outdated_ (tree, deps, opts) { } } - // packument fetching memoizing - const packuments = new Map() async function getPackument (spec) { - if (packuments.has(spec)) { - return packuments.get(spec) - } const packument = await pacote.packument(spec, { fullMetadata: npm.flatOptions.long, preferOnline: true }) - packuments.set(spec, packument) return packument } async function getOutdatedInfo (edge) { const spec = npa(edge.name) - const node = edge.to - const { - path, - location, - package: { - version: current - } - } = node || { package: {} } + const node = edge.to || edge + const { path, location } = node + const { version: current } = node.package || {} const type = edge.optional ? 'optionalDependencies' : edge.peer ? 'peerDependencies' @@ -164,7 +157,7 @@ async function outdated_ (tree, deps, opts) { location, wanted: wanted.version, latest: latest.version, - dependent: edge.from.name, + dependent: edge.from ? edge.from.name : 'global', homepage: packument.homepage }) } |