[GH-ISSUE #613] How to increment a version with a prefix / range in the dependency string #2167

Closed
opened 2026-04-20 10:08:49 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @soundstep on GitHub (Sep 17, 2020).
Original GitHub issue: https://github.com/semver/semver/issues/613

Hi,

This is more a question than a bug.

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:

{
  "dependency": {
    "my-package-1": "^1.0.0",
    "my-package-2": "~1.0.0",
    "my-package-3": ">=1.0.0",

It might make sense only in our case, but what would be the best way to change this string:

>=1.0.0

to:

>=1.0.1

I tried a few things like:

semver.inc('>=1.0.0', patch);

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:

const extracted = semver.extract('>=1.0.0');
console.log(extracted.version); // 1.0.0
console.log(extracted.range); // >=

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.

Any advice?

Originally created by @soundstep on GitHub (Sep 17, 2020). Original GitHub issue: https://github.com/semver/semver/issues/613 Hi, This is more a question than a bug. 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: ``` { "dependency": { "my-package-1": "^1.0.0", "my-package-2": "~1.0.0", "my-package-3": ">=1.0.0", ``` It might make sense only in our case, but what would be the best way to change this string: ``` >=1.0.0 ``` to: ``` >=1.0.1 ``` I tried a few things like: ``` semver.inc('>=1.0.0', patch); ``` 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: ``` const extracted = semver.extract('>=1.0.0'); console.log(extracted.version); // 1.0.0 console.log(extracted.range); // >= ``` I'm kinda guessing that this would be hard with some ranges like "1.0.x". [lerna version --exact](https://github.com/lerna/lerna/tree/master/commands/version#--exact) is somewhat close because they use [npm version --save-prefix](https://docs.npmjs.com/misc/config#save-prefix) but that's for the versions themselves, not the dependency ranges. Any advice?
Author
Owner

@ljharb commented on GitHub (Sep 17, 2020):

This seems like a better issue for https://github.com/npm/node-semver rather than this repo.

<!-- gh-comment-id:694455053 --> @ljharb commented on GitHub (Sep 17, 2020): This seems like a better issue for https://github.com/npm/node-semver rather than this repo.
Author
Owner

@soundstep commented on GitHub (Sep 18, 2020):

Right I see, I will re-create there!

<!-- gh-comment-id:694702593 --> @soundstep commented on GitHub (Sep 18, 2020): Right I see, I will re-create there!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#2167