Skip to content

fix(view): avoid wrapping array results#9745

Merged
reggi merged 1 commit into
latestfrom
fix/view-json-array-output
Jul 10, 2026
Merged

fix(view): avoid wrapping array results#9745
reggi merged 1 commit into
latestfrom
fix/view-json-array-output

Conversation

@reggi

@reggi reggi commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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.

Return a sole array-valued JSON result directly instead of adding a
second result wrapper. Preserve existing output shapes for scalar,
object, and multiple returned results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0891f659-c868-4bcb-b8df-c4ec5a368566
@reggi reggi requested review from a team as code owners July 10, 2026 15:22
@reggi reggi merged commit ecb02a8 into latest Jul 10, 2026
31 checks passed
@reggi reggi deleted the fix/view-json-array-output branch July 10, 2026 15:44
@github-actions github-actions Bot mentioned this pull request Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants