diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2020-08-24 23:07:19 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-08-25 21:08:23 +0300 |
commit | 50f9740ca8000b1c4bd3155bf1bc3d58fb6f0e20 (patch) | |
tree | 4e02431e70b22ac48bb5580503612c77141fd69c /lib/fund.js | |
parent | aa0152b58f34f8cdae05be63853c6e0ace03236a (diff) |
fix: fund with multiple funding sources
`npm fund` human output was appending any items that had multiple
funding sources to the current package title as comma-separated names.
This commit fixes the problem by properly selecting the first item of a
each funding element and only using that as its index for printing the
human output tree representation.
PR-URL: https://github.com/npm/cli/pull/1717
Credit: @ruyadorno
Close: #1717
Reviewed-by: @isaacs
Diffstat (limited to 'lib/fund.js')
-rw-r--r-- | lib/fund.js | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/fund.js b/lib/fund.js index fde01f469..d1c58d9b9 100644 --- a/lib/fund.js +++ b/lib/fund.js @@ -42,26 +42,33 @@ function printHuman (fundingInfo, { color, unicode }) { const result = depth({ tree: fundingInfo, + + // composes human readable package name + // and creates a new archy item for readable output visit: ({ name, version, funding }) => { - // composes human readable package name - // and creates a new archy item for readable output - const { url } = funding || {} + const [fundingSource] = [] + .concat(normalizeFunding(funding)) + .filter(isValidFunding) + const { url } = fundingSource || {} const pkgRef = getPrintableName({ name, version }) - const label = url ? tree({ - label: color ? chalk.bgBlack.white(url) : url, - nodes: [pkgRef] - }).trim() : pkgRef let item = { - label + label: pkgRef } - // stacks all packages together under the same item - if (seenUrls.has(url)) { - item = seenUrls.get(url) - item.label += `, ${pkgRef}` - return null - } else { - seenUrls.set(url, item) + if (url) { + item.label = tree({ + label: color ? chalk.bgBlack.white(url) : url, + nodes: [pkgRef] + }).trim() + + // stacks all packages together under the same item + if (seenUrls.has(url)) { + item = seenUrls.get(url) + item.label += `, ${pkgRef}` + return null + } else { + seenUrls.set(url, item) + } } return item |