-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] How to increment a version with a prefix / range in the dependency string #343
Comments
You should be able to parse those ranges and then examine the sets of comparators inside the range. Here's an example of the internals of
|
What / Why
What would be the best approach to increment the version of a dependency.
Some libraries are doing this writing their own string parser, like https://github.com/raineorshine/npm-check-updates
I'm writing a CLI for a monorepo that bumps version, and possibly change versions specified as dependencies.
If I'm parsing a
package.json
and find that kind of string for a dependency:What would be the best way to change this string:
to:
I tried a few things like:
But that doesn't work. I also tried to find a way to extract the version from the range but didn't find anything. I suppose I would need something like:
I'm kinda guessing that this would be hard with some ranges like "1.0.x"?
lerna version --exact is somewhat close because they use npm version --save-prefix but that's for the versions themselves, not the dependency ranges.
npm-check-update do that writing their own parser.
Any advice?
Update:
I'm still after a lighter solution, until then I will use the npm-check-updates cli:
Another solution with a slightly updated regex from:
https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39
#32
And another one:
https://regex101.com/r/Ly7O1x/196
Converted to:
Where
In a private monorepo context
References
Originally posted there:
semver/semver#613
The text was updated successfully, but these errors were encountered: