compare-versions icon indicating copy to clipboard operation
compare-versions copied to clipboard

`"latest"` support

Open yowainwright opened this issue 2 years ago • 7 comments

Hello! Love this module!

Any considerations around "latest" support?

In Example:

{
  "lodash": "lastest"
}

Thank you!

yowainwright avatar Aug 25 '22 01:08 yowainwright

Not sure I understand? If you add "latest" as a version in your package.json it works fine with compare-versions:

"compare-versions": "lastest"

omichelsen avatar Aug 26 '22 02:08 omichelsen

@omichelsen thanks for your fast response!

It's might be a me thing—usually is. 😄 I'll try to reproduce the issue in a Stackblitz in a bit. I'll close if I can't reproduce the issue! 👌

yowainwright avatar Aug 27 '22 06:08 yowainwright

Here's the reproduction:

  • https://stackblitz.com/edit/typescript-fhup6r?file=index.ts

Looking forward to your feelings on this!

  • I could see capturing "latest" and doing something (flagging it in some way) or just setting "latest" to latest, haha

Thanks again!!!

yowainwright avatar Aug 29 '22 06:08 yowainwright

Ah I see, you want to use "latest" as a version name to compare against. I don't see a way that this would work, since the code running your comparison has no idea what "latest" means (which version is newest at any given time). It would be equivalent to either rejecting or accepting everything.

omichelsen avatar Sep 03 '22 16:09 omichelsen

That, along with workspace protocols, is a current limitation of the api, right? Perhaps it should be documented? Or:

  1. An optional options argument could be added to compare-version functions to let the executor enable meaning to their sorting/comparing function invocations.
  2. Sorting/comparing checks could be done by traversing package.json's.
  3. Sorting/comparing checks could be done by capturing latest or workspace protocols via checking what "latest" actually is in a registry.
  • Option 3 is weak as it would degrade compare-version performance but options 1 and 2 are viable.
  • Documentation updates would work too! I had to update code in a few places to mitigate this issue so it might be good for other users to know about this limitation so they can write code accordingly.

Thanks so much for the awesome utility!

Let me know if I can help. I feel this issue is important to document as compare-versions is very useful for monorepos but lastest and workspace protocol support is a limitation that's good to be aware of when using the compare versions utility!

Sorry if I'm misunderstanding any of the api 💛🙏

yowainwright avatar Sep 03 '22 17:09 yowainwright

Thanks for describing your use cases. I think these examples goes beyond the scope of this project though. This is a tiny (few hundred bytes) library intended to compare version strings according to the official semver spec (with a few additions). It has no concept of npm, yarn or any other package/module manager systems controlling the "latest" concept you are describing.

I'm not sure how you are using it in your monorepo work, but maybe you need a (new) more specialized library? If you were to create such a library, it could perhaps still use the basic functionality of compare-versions, but add features specific to npm (package.json) usage?

I'd be happy to clarify the documentation with any improvements you might think of. Please feel free to open a PR 😀

omichelsen avatar Sep 04 '22 04:09 omichelsen

@omichelsen sorry for my slow response.

Your comment resonated with me:

Small library (and matching of semver spec).

I wouldn't want to overcomplicate the API or docs as this library is SO HELPFUL as is.

Here's a contrived example for reference if anyone comes across this same sort of thing.

I'll subscribe to this issue and am happy to support more if needed.

  • Feel free to (at)me later. I'm specifically using this lib at work and here, here, here, and here for monorepo-related functionality.

Feel free to close the issue from my perspective, @omichelsen!

Thank you!!!

yowainwright avatar Sep 13 '22 02:09 yowainwright