Say I have an NPM package:
current_version="1.2.3";
latest_version=`npm view "$package_name" version`
how can I use the semver command line tool to determine if the latest version in npm has the same major version as the current_version? Something like:
semver --same-major "$current_version" "$latest_version"
?
Basically, what I want to do is install to the most recent version with the same major version.
Another related question - how can I find the most recent version in the NPM registry that has the same major semver version as the current_version
?
https://www.npmjs.com/package/semver
you can use carret range like this
semver -r "^$current_version" "$latest_version"
if the input is valid (the same major number), this command print the version and exit with status code 0
else this will print nothing and exit with code 1
PS: you can check for exit code with echo $?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With