semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

NPM compatibility

Open algobardo opened this issue 7 years ago • 5 comments

The following checks throw an exception, while are regular constraints in npm

new Semver("0.0.7", SemverType.NPM).satisfies("~1.9.1-6")
new Semver("3.3.1", SemverType.NPM).satisfies(">=2.4.x")
new Semver("3.3.1alpha", SemverType.NPM).satisfies(">=2.4.0")

algobardo avatar Feb 02 '17 13:02 algobardo

@algobardo any idea why? I don't have the time to look into it yet but if you figure out why and send a fix, I will gladly merge it!

vdurmont avatar Feb 09 '17 16:02 vdurmont

i have the same problem, the issue is in: Requirement.evaluateReversePolishNotation(Requirement.java:357) where a Range is constructed with SemverType.LOOSE even when the given type is NPM.

  public Range(String version, RangeOperator op) {
        this(new Semver(version, Semver.SemverType.LOOSE), op);
    }

So none of the satisfies methods work with ANY type except LOOSE , does not matter if u force NPM, or anything else....

new Semver("3.3.1", SemverType.NPM).satisfies(">=2.4.x") fails and new Semver("3.3.1", SemverType.NPM).satisfies(Requirement.buildNPM(">=2.4.x")) fails as well, the Range will always create a LOOSE type which does not accept 'x' as patch notation...

maybe @vdurmont can help, this seems a serious problem... i integrated this library into a validator tool with dependencies of NPM style, and expected some basic functionality, like the satisfies method, and reading versions and patch versions, nothing more, and got quite surprised it's not working even with the simple examples on the homepage... am i using it incorrectly ? if not, then we need to write some test cases... and i can help with fixing stuff, it's just i don't understand why you used Semver.SemverType.LOOSE in the Range constructor, maybe there's a reason....

thanks much !!

mpostelnicu avatar Aug 10 '17 12:08 mpostelnicu

Have you tried if the same happens on what we have https://github.com/algobardo/semver4j ? I attempted to solve some of the problems in #12

algobardo avatar Aug 10 '17 12:08 algobardo

i don't want to repackage the library as artifact myself and i don't want to use the source code directly, so for the moment i patched my code not to use wildcards... thanks anyway.

mpostelnicu avatar Aug 15 '17 11:08 mpostelnicu

@algobardo if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1

piotrooo avatar Jul 22 '22 22:07 piotrooo