Skip to content

Commit d36945d

Browse files
fix!: do not unwrap single-item arrays in --json output
BREAKING CHANGE: npm view --json now always returns an array.
1 parent 6628d05 commit d36945d

3 files changed

Lines changed: 229 additions & 198 deletions

File tree

lib/commands/view.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,12 @@ class View extends BaseCommand {
240240
})
241241

242242
if (json) {
243-
// TODO(BREAKING_CHANGE): all unwrapping should be removed.
244-
// Users should know based on their arguments if they can expect an array or an object.
245-
// And this unwrapping can break that assumption.
246-
// e.g. `npm view abbrev@^2` should always return an array, but currently since there is only one version matching `^2` this will return a single object instead.
243+
// Users can expect an array .
247244
const first = Object.keys(res[0] || {})
248245
const jsonRes = first.length === 1 ? res.map(m => m[first[0]]) : res
249246
if (jsonRes.length === 0) {
250247
return
251248
}
252-
if (jsonRes.length === 1) {
253-
return jsonRes[0]
254-
}
255249
return jsonRes
256250
}
257251

0 commit comments

Comments
 (0)