Skip to content

[BUG] npm view $package versions --json returns non-JSON string for packages with only one version #3611

@jayeb

Description

@jayeb

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

As of 7.20.0, querying the versions field with the --json flag (npm view $package versions --json) for a package with only one published version will return a single string value, which is not parseable as JSON.

Expected Behavior

In versions prior to 7.20.0, querying the versions field with the --json flag (npm view $package versions --json) for a package with only one published version would return an array with a single string, which is parseable as JSON.

Steps To Reproduce

  1. Using npm 7.20.X, run npm view $package versions --json for a package with only one published version.
    • For example: npm view @types/spdx-satisfies versions --json
  2. Note that the stdout response contains a single string, rather than an array.

For comparison:

  1. Using npm 7.19.X, run npm view $package versions --json for a package with only one published version.
    • For example: npm view @types/spdx-satisfies versions --json
  2. Note that the stdout response is valid JSON: a single string wrapped in an array.

Environment

  • OS: macOS 11.4
  • Node: 14.17.0
  • npm: 7.20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueconfig:displayIssues dealing with display of data to terminal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions