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

npm commands fail if version is not in 100 most recent npm releases #216

Open
jshumaker-accusoft opened this issue May 7, 2018 · 2 comments

Comments

@jshumaker-accusoft
Copy link

nodist npm add 3.5.2
Fails with Cannot read property 'trim' of null.

Looking at the code, it's largely because semver.validRange thinks that an exact version is a range.
https://github.com/marcelklehr/nodist/blob/7a971d1d9c05f0a2bb98f8e3e0fadf5a20d699db/lib/npm.js#L190

The code then applies the "range" to the releases it pulled, except it's limited to the last 100 because the code only pulls the latest 100 releases, because requesting more would require multiple calls for multiple pages.

As a temporary fix for my local copy, I modified the if statement to exclude versions that are just a basic semver and not a range from going through range matching.

if(!v.match(/[0-9]+\.[0-9]+\.[0-9]+/) && semver.validRange(v)){

Maybe an acceptable solution? seems like there's a few other spots in the code that could use that.

Probably better long-term solution is to cache the versions, and only check for new versions if cache is older than X time, and retrieve multiple pages of releases until you hit a version in the cache already. That however is much more complicated to implement, and the above got us rolling again.

@jshumaker-accusoft
Copy link
Author

So this is still an issue. Part of the reason we use nodist is to lock the version we use for some projects. It's frustrating when we go to load up an old version and it fails. There's now ~230 releases of npm, but nodist still only recognizes the latest 100.

Did you close this as you don't intend to implement it? If so, if I was to provide an implementation any particular requirements you'd have? Simplest would be to look at the Link header and iterate through the pages to built the full list of releases, but that means 3x the queries every time an npm operation is done.

@nullivex
Copy link
Member

nullivex commented Jul 9, 2019

@jshumaker-accusoft I am going to go ahead and re-open this. I was under the impression it was working as intended.

The real issue here is the API we are asking about the versions they are clearly handing us a shortened result. Either code needs to be applied to fetch the remaining entries, perhaps on a page 2 or a different API call to list all the versions.

I am open to a PR on this.

@nullivex nullivex reopened this Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants