zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Is there a JavaScript implementation of the jsemver BNF/syntax? #51

Closed chrisknoll closed 1 year ago

chrisknoll commented 5 years ago

Hi, @zafarkhaja . We're interested in utilizing semantic versioning in our application where the client (through a HTML/JS UI) specifies a dependency using semver syntax (ie ~1.0) and we have certain UI elements shown based on the desired semver dependency, and what that specific UI element supports.

On the back end, we have a Java component which will do the same sorts of checks: if the client request asks to do something, but the target dependnecy doesn't support it (via a semver range check), then it fails.

The problem is: the rules in jsemver are based on your own version of how the semantic versioning is described, while other javascript libraries have implementations that follow what node/npm semver rules dictate (for example, jsemver uses 4.5 & 4.6 while node-semver is simply 4.5 4.6.

So, my question is: do you provide a Javascript implementation of your jsemver rules? Our current option is to load a javascript parser (!) and the semver.js implementation into Java-land, and execute semver range checks that way so we get consistent results between client (HTML/JS UI) specification and the server side (Java implementation). I hate the idea of having to load a javascript engine in Java just to get consistency. I'd much rather have a jsemver javascript implementation that agrees with the java-side jsemver.

zafarkhaja commented 1 year ago

Hello Chris! Sorry it took me this long to get back to you.

If by any chance this is still relevant to you, unfortunately there is no javascript implementation of jsemver rules.

I get many requests for node-semver compatibility, and there are 2 options I see: 1) provide some compatibility by extending the current parser, or 2) provide full compatibility by writing a new parser. Currently I'm investigating the first option as the second one would require much more time and effort, but I guess it won't suffice for your needs. I do plan to eventually provide full compatibility but it's hard to say when.

chrisknoll commented 1 year ago

Yes, it's still relevant for us. We could reduce our codebase package size by 50MB if we didn't have to load the javascript engine in the JVM.

zafarkhaja commented 1 year ago

That's a lot... I'll see what I can do to squeeze it in the upcoming release, but can't give you any promises yet. I want to ship #15 first and don't want to put off the next release much longer.

I wonder if you have considered alternatives? There are other libraries with some/full support of node-semver ranges.

chrisknoll commented 1 year ago

I haven't looked around since 2019, so if you do have suggestions about alternatives that implement the node-semver methods, I'd definitely take a look.

zafarkhaja commented 1 year ago

Try semver4j/semver4j. It's actively maintained and does provide node-semver ranges support, not sure to what extent though.

chrisknoll commented 1 year ago

Yesk, the semver4j looks like it has an NPM mode which I hope covers the same semver expressions (the example above i created was 4.5 4.6 but if that was actually not a valid semver, we can make sure our javascript and java version syntax matches on both sides, and do some testing to verify that the javascript impl matches the java one (and if not, we can always file an issue with semver4j).

Thanks again, feel free to close this.

zafarkhaja commented 1 year ago

Sure, good luck!