[BUG] minVersion returns 0.0.0 when a 0.0.0 prerelease is the true minimum

オープン 初心者向け
#934 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@thisisshivamtiwari がすでに取り組んでいます。

2026年10月29日 から。

  • #936 @thisisshivamtiwari による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js
領域
backend

調査の方向性

issueで指定されているranges/min-version.jsのショートカットから始め、関連するminVersionのテストと、プレリリースバージョンが0.0.0とどのように比較されるかを調べます。issueの例を再現し、includePrereleaseを指定した場合に>=0.0.0-alpha <1.0.0と*の最小バージョンが正しく返されることを確認します。これらのケースが、文書化されている最小バージョンの動作を変更せずに通れば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug Needs Triage
Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

This is admittedly a bit pedantic, but minVersion seems to treat 0.0.0 as a special case. A prerelease lower bound is respected on every tuple except 0.0.0:

semver.minVersion('>=1.0.0-alpha <2.0.0').version // '1.0.0-alpha'
semver.minVersion('>=0.0.1-alpha <1.0.0').version // '0.0.1-alpha'
semver.minVersion('>=0.0.0-alpha <1.0.0').version // '0.0.0'

The same thing happens with includePrerelease, where 0.0.0-0 satisfies * but 0.0.0 is returned:

semver.minVersion('*', { includePrerelease: true }).version // '0.0.0'

This comes from the shortcut at the top of ranges/min-version.js, which tries 0.0.0 before 0.0.0-0 and returns the first one that matches.

Expected Behavior

I'd expect '0.0.0-alpha' and '0.0.0-0' respectively, since the README describes minVersion as returning "the lowest version that can match the given range", and the rest of the library agrees that these sort below 0.0.0 (lt, sort, minSatisfying).

I couldn't find anything (docs, tests, or the original PR npm/node-semver#241) suggesting 0.0.0 is meant to be special here, so I suspect the shortcut just wasn't written with prerelease lower bounds in mind. But if this is intentional it might be worth documenting.

Steps To Reproduce
  1. npm install [email protected]
  2. Run node -e "console.log(require('semver').minVersion('>=0.0.0-alpha <1.0.0').version)"
  3. See 0.0.0
Environment
  • npm: 11.20.0
  • Node: 26.12.1
  • OS: macOS 26.6.1
  • platform: Apple Silicon (arm64)
  • semver: 7.8.5 (same code on main)

AI disclosure: this issue was discovered with AI assistance

主要言語
JavaScript
スター
5.5k
フォーク
622
平均マージ
4日 23時間
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/node-semver のほかの issue

npm/node-semver の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。