You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[RRFC] "npm pkg get <value> --raw" to get raw unquoted values for further use in scripts #634
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:
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.
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)
Reacted by Jordan Harband, Remco Tolsma and Ruy Adorno
Activity
ljharb commentedon Sep 15, 2022
This feature makes sense to me.
ruyadorno commentedon Sep 15, 2022
This sounds like a good idea! I just believe that what we want here is to add support to
--parseableinstead of adding a newrawconfig in the mix.Just to add some background, there are basically 3 different types of output that the npm cli supports:
npm pkg gettoday, prints stringified json output)npm ls,npm outdated,npm searchand 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 commentedon Sep 15, 2022
parseable and a PR sounds great to me :-) hopefully the npm cli team can weigh in.
bnb commentedon Sep 21, 2022
very much +1 to parsable
darcyclarke commentedon Sep 28, 2022
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 commentedon Nov 10, 2022
Tracking as a feature enhancement in the CLI here: npm/cli#5508