cli icon indicating copy to clipboard operation
cli copied to clipboard

Feature: npm pkg get <value> --raw

Open ThePlenkov opened this issue 2 years ago • 4 comments

Problem 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. It's ok, but this solution si not cross-platform or requires additional packages installation.

Suggestion 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

What do you think? 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

ThePlenkov avatar Sep 14 '22 15:09 ThePlenkov

Seems reasonable to me - you may want to file an RFC.

ljharb avatar Sep 14 '22 18:09 ljharb

@ljharb sure - but I don't know what is this. Do you have an example?

ThePlenkov avatar Sep 15 '22 09:09 ThePlenkov

Do you mean I'd better create it here? https://github.com/npm/rfcs/issues

ThePlenkov avatar Sep 15 '22 09:09 ThePlenkov

Just did: https://github.com/npm/rfcs/issues/634

ThePlenkov avatar Sep 15 '22 09:09 ThePlenkov

From the linked RFC (https://github.com/npm/rfcs/issues/634), this is a great feature enhancement (and something I would use personally 😄). If anyone wants to implement it, the flag should be --parseable. I'm going to close the linked RFC and use this issue for tracking.

lukekarrys avatar Nov 10 '22 20:11 lukekarrys

As the default value for the --json flag is false, this can be seen as a bug fix, not a feature and no flag should be necessary (breaking changes, etc, aside).

mbrevda avatar Nov 24 '22 09:11 mbrevda

Hi! I'm really wondering will any of flags ( --raw, --parseable, --json ) be considered to print version without quotes? Thanks!

ThePlenkov avatar Mar 18 '23 19:03 ThePlenkov