frewsxcv / rust-crates-index

Rust library for retrieving and interacting with the crates.io index
https://docs.rs/crates-index/
Apache License 2.0
72 stars 37 forks source link

Latest version isn't semver-accurate #20

Closed kornelski closed 4 years ago

kornelski commented 6 years ago

Currently, crate.latest_version() for nom gives 4.0.0-beta3, but should give 4.0.0 stable.

frewsxcv commented 6 years ago

Is your crates-index git repo up-to-date? Not sure how this can happen if so... 🤔

For reference https://github.com/rust-lang/crates.io-index/blob/master/3/n/nom

kornelski commented 6 years ago

Yes (980c95aa38f51b34c13983ac1dc0d085833c44f0).

4.0.0 is in versions(), but it's not last in the array.

kornelski commented 6 years ago

OK, from the code I don't see how can it happen either. My computer must be cursed ;)

kornelski commented 6 years ago

I've found another case where it gives "wrong" result:

https://github.com/rust-lang/crates.io-index/blob/56dd5b1e0c58b52db2a1aed160ba08820de9b6e1/ra/nd/rand#L42

The issue is that "latest" here means most recently published, rather than highest according to semver. If that's the intended behavior, I think it should come with huge warning in the docs, since that is not a useful behavior for version resolution.

frewsxcv commented 6 years ago

I'd be in favor of introducing new functionality which retrieves the highest semver crate version (via the semver crate). I'm not sure what this would be called, maybe highest_version? To me, latest_version implies the newest published crate version, but I can see how it can be interpreted to be the highest semver version. I'm a bit short on time, but if you or anyone else wants to open a PR for this, I'd accept such a change.

mainrs commented 4 years ago

I can open a PR to implement this if there is still interest to merge it.

kornelski commented 4 years ago

In building https://lib.rs I've noticed that I need highest stable version as often as absolutely highest including prereleases. Having both would be useful.

I'm not sure how to name them.

mainrs commented 4 years ago

I have implemented a draft over at #39. Feedback welcome. I am not sure about the naming with the _unchecked version. The latest_semver_version one should be enough. I just return the values returned by Iterator::max, but since I can't think of a case where a crate is inside the index but has no single semver compatible version we might as well unwrap directly as it seems to be a safe operation.