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

Allow piping into semver to read versions

Open richardgarnier opened this issue 9 years ago • 7 comments

This is a patch for #149.

Before entering the main, we check if the process is piped. If so then we fill the versions array and then we launch the main. In order to fill the array, we split on spaces.

NB : versions can be accepted both from the pipe and as arguments. For example echo 1.0.0 | semver -r '>=1' 1.1.1 is accepted.

NB2 : testing relies on comparing the output of the version without piping, and the version with piping.

richardgarnier avatar Jun 04 '16 06:06 richardgarnier

Coverage Status

Coverage remained the same at 94.624% when pulling 0841679f01c791509b75a695ba0781a828fdff16 on akatsukle:master into 8bd070b550db2646362c9883c8d008d32f66a234 on npm:master.

coveralls avatar Jun 04 '16 06:06 coveralls

Coverage Status

Coverage remained the same at 94.624% when pulling e63742a932752100f96951279127d50491d6e085 on akatsukle:master into 8bd070b550db2646362c9883c8d008d32f66a234 on npm:master.

coveralls avatar Jun 04 '16 06:06 coveralls

Coverage Status

Coverage remained the same at 94.624% when pulling d4ca6fbb6f3f7408595de0de836c416fa45f1ce0 on akatsukle:master into 8bd070b550db2646362c9883c8d008d32f66a234 on npm:master.

coveralls avatar Jun 04 '16 07:06 coveralls

Coverage Status

Coverage remained the same at 94.624% when pulling d149eb427bbc2ff7eb9f84719381036c1e53b3f7 on akatsukle:master into 8bd070b550db2646362c9883c8d008d32f66a234 on npm:master.

coveralls avatar Jun 04 '16 07:06 coveralls

Well that test was embarrassing... sorry

richardgarnier avatar Jun 04 '16 07:06 richardgarnier

This is ok, and seems to work, but it seems like it'd be better to open stdin, and parse/filter each version as lines are read. That way it could be done interactively. I could see this being really handy if you want to test out whether a given range works with various versions.

You can use node's builtin readline module to do this.

isaacs avatar Jun 29 '16 21:06 isaacs

Oh, I just realized something about this.

This means that any programs that spawn('semver') are going to hang until stdin is closed.

That's probably surprising. One approach would be to only read the stdin pipe if - is passed as an argument.

isaacs avatar Feb 08 '17 18:02 isaacs

Closing this one for now since it still has work to be done.

wraithgar avatar Apr 10 '23 14:04 wraithgar