SIGN IN SIGN UP

fix(view): avoid wrapping array results (#9745)

npm 12.0.0 breaks downstream updaters by returning nested arrays for
`npm view <pkg> versions --json`.

## The bug

On npm 12.0.0, a single array-valued field is wrapped in the outer
results array:

```
$ npm view abbrev versions --json
[["1.0.3","1.0.4", ...]]   # should be ["1.0.3","1.0.4", ...]
```

This happens in `lib/commands/view.js` `#packageOutput`: for a
single-field query it maps to `res.map(m => m[first[0]])`, and when that
field's value is itself an array (e.g. `versions`), it gets
double-wrapped.

## The fix

Return a sole array-valued JSON result directly instead of adding a
second result wrapper. Existing output shapes are preserved:

- scalar and object results still return in an array (`["1.0.0"]`,
`[{...}]`)
- multiple matching versions keep the result boundary (`[[...],[...]]`)
- a single array-valued result is returned directly
(`["1.0.0","1.0.1"]`)

Docs and tests updated to cover flat array, nested array,
object-wrapper, workspace, and multi-match cases.

Co-authored-by: Martin Ruiz <martin.ruiz.mares@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T
Tea Reggi committed
ecb02a88a7ca0940d25957d941dc7c66736af4f7
Parent: 47fc8b1
Committed by GitHub <noreply@github.com> on 7/10/2026, 3:44:15 PM