Skip to content

Fix package.json hover metadata broken in npm 12+ - #327951

Merged
Martin Aeschlimann (aeschli) merged 2 commits into
microsoft:mainfrom
guimmd2:fix/npm12-view-array
Aug 19, 2026
Merged

Fix package.json hover metadata broken in npm 12+#327951
Martin Aeschlimann (aeschli) merged 2 commits into
microsoft:mainfrom
guimmd2:fix/npm12-view-array

Conversation

@guimmd2

@guimmd2 Guilherme Menezes Magalhães (guimmd2) commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #327228

Description

npm 12 changed npm view --json to always return an array [{...}] instead of {...}. Handle both formats by checking Array.isArray.

Validation

  1. Created a test suite for npm extension and added 10 unit tests.
  2. Manually tested by building VS Code from source and hovering over package.json dependencies:
  • With npm 11: all metadata (description, latest version, homepage) displayed correctly
image
  • With npm 12: same, all metadata now displays correctly
image

Both versions work after the fix.

Copilot AI review requested due to automatic review settings July 29, 2026 03:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates npm package metadata parsing to support npm 12’s array response while retaining compatibility with earlier versions.

Changes:

  • Detects array-form npm view --json output.
  • Extracts the single package metadata object.
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Guilherme Menezes Magalhães (@guimmd2) Can we add a test for the fix?

@guimmd2

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@guimmd2

Copy link
Copy Markdown
Contributor Author

Guilherme Menezes Magalhães (Guilherme Menezes Magalhães (@guimmd2)) Can we add a test for the fix?

Hey Dmitriy Vasyura (@dmitrivMS), sure. The extension didn't have a test suite, so I created one and added some tests to cover this fix and the overall npm view functionality.

Thanks for checking the PR.

npm 12 changed npm view --json to always return an array [{...}]
instead of {...}. Handle both formats by checking Array.isArray.

Fixes #327228
Move the `npm view --json` parsing out of `npmView()` into a pure
`parseNpmViewOutput()` function so the npm 12+ array-format fix can be
unit tested without the vscode API. Add a mocha suite covering object
and array output, dist-tags.latest preference and fallback, missing
fields, invalid and non-object output, and register the npm extension
in .vscode-test.js so CI runs the tests.
@aeschli
Martin Aeschlimann (aeschli) merged commit 716116e into microsoft:main Aug 19, 2026
27 of 29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 19, 2026
Dileep Yavanmandha (dileepyavan) pushed a commit that referenced this pull request Aug 19, 2026
* Fix npm view --json returning array in npm 12+

npm 12 changed npm view --json to always return an array [{...}]
instead of {...}. Handle both formats by checking Array.isArray.

Fixes #327228

* Extract npm view output parsing into a testable module with tests

Move the `npm view --json` parsing out of `npmView()` into a pure
`parseNpmViewOutput()` function so the npm 12+ array-format fix can be
unit tested without the vscode API. Add a mocha suite covering object
and array output, dist-tags.latest preference and fallback, missing
fields, invalid and non-object output, and register the npm extension
in .vscode-test.js so CI runs the tests.
@guimmd2
Guilherme Menezes Magalhães (guimmd2) deleted the fix/npm12-view-array branch August 19, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants