Skip to content

fix: display multiple versions when --json on npm view #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: display multiple versions when --json on npm view
  • Loading branch information
claudiahdz committed Aug 11, 2020
commit 554c78ff607cb62bbbc1098bd6524b1da310fc7d
10 changes: 7 additions & 3 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ const fetchAndRead = async (nv, args, opts) => {

Object.keys(versions).forEach(function (v) {
if (semver.satisfies(v, version, true)) {
args.forEach(args => {
args.forEach(arg => {
// remove readme unless we asked for it
if (args.indexOf('readme') !== -1) {
delete versions[v].readme
}
results.push(showFields(pckmnt, versions[v], args))
results.push(showFields(pckmnt, versions[v], arg))
})
}
})
Expand Down Expand Up @@ -400,7 +400,11 @@ async function printData (data, name, opts) {
const k = Object.keys(msgJson[0])[0]
msgJson = msgJson.map(function (m) { return m[k] })
}
msg = JSON.stringify(msgJson[0], null, 2) + '\n'
if (msgJson.length === 1) {
msg = JSON.stringify(msgJson[0], null, 2) + '\n'
} else if (msgJson.length > 1) {
msg = JSON.stringify(msgJson, null, 2) + '\n'
}
}

// disable the progress bar entirely, as we can't meaningfully update it if
Expand Down
Loading