Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request (satisfies)]: support ranges with || #63

Closed
kindoflew opened this issue Sep 26, 2022 · 6 comments
Closed

[feature request (satisfies)]: support ranges with || #63

kindoflew opened this issue Sep 26, 2022 · 6 comments

Comments

@kindoflew
Copy link

Hi, thanks for this library!

I was wondering if it'd be possible to add support for ranges that contain multiple ranges using || -- ie, something like:

^12.22.0 || ^14.17.0 || >=16.0.0

I'm currently using a workaround where I split the string and test if any of them pass satisfies:

const rangeArray = dep.version.split('||').map((range) => range.trim());
const doesSatisfy = rangeArray.some((range) => satisfies(version, range));

but I think it would be nice if it was supported out of the box. I'd be happy to open a PR if you are into this idea! Thanks again!

@kindoflew kindoflew changed the title [feature request]: support ranges with || [feature request (satisfies)]: support ranges with || Sep 27, 2022
@omichelsen
Copy link
Owner

omichelsen commented Dec 15, 2022

Thanks for suggesting this. I am working on adding this to the existing satisfies function so it adheres to the npm spec. I expect to release this as a breaking version v6, since it would be looking for spaces and potentially break existing usage.

I have released v6.0.0-rc.1, please check if it works as expected.

Example usage: 1.2.7 || >=1.2.9 <2.0.0
Spec: https://docs.npmjs.com/cli/v6/using-npm/semver#ranges

@kindoflew
Copy link
Author

kindoflew commented Dec 21, 2022

I think I might have found a small bug in satisfies (I actually don't think it's related to this feature, but I noticed it while testing v6.0.0-rc.1):

A package in the project I'm using this for has an incorrectly formatted range (>= 12.0.0 -- note the space between the operator and the version number). This seems to cause satisfies to try to parse >= by itself, which isn't a valid range, so it throws.

Not sure if this is a thing that should be resolved in userland or handled by the library. In my use case, I'm fetching these ranges from npm (reading the engines field of project dependencies), so I don't have control over how they're formatted.

However, if I do something like satisfies(version, range.replaceAll(' ', '')), everything works as expected!

@omichelsen
Copy link
Owner

omichelsen commented Dec 21, 2022

Thanks for testing. This is tricky, because in semver ranges || is an "or" and space is "and", so the simple solution of removing space would not work. It also throws in v5, but the message is a little clearer since it doesn't try to break up the statement. I'll see what the semver package does in this case and think about a solution.

@kindoflew
Copy link
Author

Ohhh yeah, that's a great point.

@kindoflew
Copy link
Author

kindoflew commented Dec 21, 2022

@omichelsen
Copy link
Owner

omichelsen commented Jul 7, 2023

I finally got around to working on this and released 6.0.0-rc.3 to address the malformed input for ranges (extra spaces).

Example: > 1.2.3 <= 1.2.5 || 0.0.0 => >1.2.3 <=1.2.5 || 0.0.0

Thanks for the feedback and suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants