Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress version output by default for JSON commands #34

Open
pting-me opened this issue Jan 25, 2022 · 0 comments
Open

Suppress version output by default for JSON commands #34

pting-me opened this issue Jan 25, 2022 · 0 comments

Comments

@pting-me
Copy link

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
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

No branches or pull requests

1 participant