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

[RRFC] "npm pkg get <value> --raw" to get raw unquoted values for further use in scripts #634

Closed
ThePlenkov opened this issue Sep 15, 2022 · 6 comments
Labels
Agenda will be discussed at the Open RFC call

Comments

@ThePlenkov
Copy link

Current behavior

One of the most popular use cases for pkg get command is getting values for other scripts as variables. However currently it's returning the value with quotes:

npm pkg get version 
"4.12.2"

The current solution is to use it in a pipe and remove quotes somehow with sed or jq.:
Example:

nx build app version=$(npm pkg get version | jq -r)

However it comes with some cons:

  • It's not cross-platform
  • Requires additional packages installation
  • Code looks more complicated
  • No unique de-facto standard

Desired Behaviour

To introduce --raw/-r flag for npm pkg get command
Thus, for the following command we will expect the raw value:

npm pkg get version --raw
4.12.2

So the previous example would look like :

nx build app version=$(npm pkg get version --raw)

References

It's a simple case but you can see how much discussion about this topic:
https://gist.github.com/DarrenN/8c6a5b969481725a4413
https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code

@ljharb
Copy link
Contributor

ljharb commented Sep 15, 2022

This feature makes sense to me.

@ruyadorno
Copy link
Contributor

This sounds like a good idea! I just believe that what we want here is to add support to --parseable instead of adding a new raw config in the mix.

Just to add some background, there are basically 3 different types of output that the npm cli supports:

  • human readable (most often the default, prints things like trees, uses colors, etc)
  • json (I believe this is the default for npm pkg get today, prints stringified json output)
  • parseable (a more cli-friendly output, separates things with either tabs or colons, supported in npm ls, npm outdated, npm search and more)

That said, maybe this is too small of a feature to afford a full RFC. I can see this being an realatively-easy-to-merge contribution in case someone from the community submits a PR, or else it should be a backlogged item for the npm cli team.

@ljharb
Copy link
Contributor

ljharb commented Sep 15, 2022

parseable and a PR sounds great to me :-) hopefully the npm cli team can weigh in.

@bnb
Copy link

bnb commented Sep 21, 2022

very much +1 to parsable

@darcyclarke
Copy link
Contributor

Looks good. I'm +1 to npm version --parseable - if someone wants to pick this up & make a PR happen that would be much appreciated (don't think we need a full-blown RFC/conversation about this, as @ruyadorno noted)

@lukekarrys
Copy link
Contributor

Tracking as a feature enhancement in the CLI here: npm/cli#5508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agenda will be discussed at the Open RFC call
Projects
None yet
Development

No branches or pull requests

6 participants