Skip to content

Suppress version output by default for JSON commands #34

Description

@pting-me

Ran into an issue while running the following command with hnvm:

> npx browserslist@latest --update-db

SyntaxError: Unexpected token  in JSON at position 0
    at JSON.parse (<anonymous>)
    at getLatestInfo (/Users/philipting/dev/modus-web/platform/node_modules/browserslist/update-db.js:51:15)
    at updateDB (/Users/philipting/dev/modus-web/platform/node_modules/browserslist/update-db.js:202:16)
    at Object.<anonymous> (/Users/philipting/dev/modus-web/platform/node_modules/browserslist/cli.js:40:3)

The reason for this is because browserslist is using npm view with a --json flag to generate JSON output, but hnvm adds version information to the output.

I was able to fix this issue by adding HNVM_QUIET to my .hnvmrc. However, I feel this to be a workaround, rather than a proper fix. I had to dig into node_modules and dump the output into a separate file before discovering that the JSON output was incorrect because of the extra output generated by hnvm.

I feel that regardless of the HNVM_QUIET flag, any npm commands that output JSON should never have version information printed on the top. It causes JSON objects to be invalid.

Quick glance through npm commands tells me the following commands have a JSON flag.

npm audit
npm config
npm explain
npm fund
npm org
npm outdated
npm pack
npm pkg
npm profile
npm prune
npm search
npm team
npm version
npm view

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions