node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

[FEATURE] Allow piping into semver to read version

Open felixfbecker opened this issue 9 years ago • 7 comments

It would be very nice if we could do this:

node -v | semver -r ^5.4

Of course one could do semver $(node -v) but that only works in sh and not on Windows, which makes it bad for npm scripts.

felixfbecker avatar Jan 12 '16 17:01 felixfbecker

I'm ok with it. Patch welcome, as long as it includes docs and test :)

isaacs avatar Jan 12 '16 18:01 isaacs

Great. Is it possible to "detect" if there is data being piped from stdin or is a new command line flag needed?

felixfbecker avatar Jan 12 '16 18:01 felixfbecker

You can check process.stdin.isTTY and also default to stdin if - is an option or if no options are provided. The stdin stream should be a white space delimited set of versions, probably?

isaacs avatar Jan 12 '16 21:01 isaacs

You can check process.stdin.isTTY

thanks.

The stdin stream should be a white space delimited set of versions, probably?

I agree.

There is no engine field in package.json. What node versions have to be supported? I guess no arrow functions?

felixfbecker avatar Jan 13 '16 12:01 felixfbecker

I guess the whitespace splitting will not work completely because one version can contain spaces, like ">=0.2 <=0.8". I guess the only option is to split by line breaks?

felixfbecker avatar Jan 13 '16 12:01 felixfbecker

@felixfbecker Those are version ranges, not versions.

I'm imagining a thing like this:

get-list-of-versions-somehow | semver -r '>=2' > file-with-versions-gt-two.txt

So, the list of versions can be piped to stdin, but not the set of ranges

isaacs avatar Jan 15 '16 23:01 isaacs

can we merge this?

gWOLF3 avatar May 20 '20 23:05 gWOLF3