KEMBAR78
Npm: fetch latest version from registry.npmjs.org by samford · Pull Request #20734 · Homebrew/brew · GitHub
Skip to content

Conversation

samford
Copy link
Member

@samford samford commented Sep 19, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

livecheck's Npm strategy is currently broken because the npmjs.com website is behind Cloudflare and upstream may have have changed their security settings, as we're now seeing 403 (Forbidden) responses. This modifies the strategy to check the latest version from registry.npmjs.org instead, which doesn't seem to have the same problem.

Besides fixing the strategy, this change has some side benefits:

  • Checking the latest endpoint ensures that livecheck is tracking the version that's marked as "latest" on npm. In testing this, I saw one formula (yaml-language-server) where the version we're using is marked as "next" on npm and it's newer than "latest". We can revisit this approach if it becomes a problem in practice but it seems like a beneficial change on the surface.
  • We have some formulae where the npm package has an excessive number of previous versions (hundreds or thousands) and the Npm strategy was having to download more data than we need just to find the latest version. The responses from the latest endpoint involve much less data transfer, so these checks seem pretty snappy now (granted, I can't do a real comparison as the current Npm strategy is broken).

I tested this across all the existing formulae that use the Npm strategy and the only issue I saw was with gemini-cli, where the version from the latest endpoint was temporarily a dev version instead of the version that was reported as "latest" on npmjs.com. registry.npmjs.org is now back to reporting the correct latest version, so this may be a package-specific issue relating to how Google publishes new versions.

It's something we should keep an eye on but if it only affects a small number of packages over time (e.g., fewer than five), we can simply address those by adding a livecheck block in the formula to check a different source (noting the issue in a comment). If it ends up being a regularly-occurring and widespread issue, then we'll have to go back to the drawing board. This seems to work as expected for all the other packages, so I think we're okay moving forward with this for now.

livecheck's `Npm` strategy is currently broken because the npmjs.com
website is behind Cloudflare and upstream may have have changed their
security settings, as we're now seeing 403 (Forbidden) responses. This
modifies the strategy to check the latest version from
registry.npmjs.org instead, which doesn't seem to have the same
problem.

Besides fixing the strategy, this change has some side benefits:

* Checking the `latest` endpoint ensures that livecheck is tracking
  the version that's marked as "latest" on npm. In testing this, I
  saw one formula (`yaml-language-server`) where the version we're
  using is marked as "next" on npm and it's newer than "latest". We
  can revisit this approach if it becomes a problem in practice but it
  seems like a beneficial change on the surface.
* We have some formulae where the npm package has an excessive number
  of previous versions (hundreds or thousands) and the `Npm` strategy
  was having to download more data than we need just to find the
  latest version. The responses from the `latest` endpoint involve
  much less data transfer, so these checks seem pretty snappy now
  (granted, I can't do a real comparison as the current `Npm`
  strategy is broken).
Copy link
Member

@nandahkrishna nandahkrishna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks @samford!

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Sep 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 20, 2025
@chenrui333 chenrui333 added this pull request to the merge queue Sep 20, 2025
Merged via the queue into main with commit 145cd60 Sep 20, 2025
38 checks passed
@chenrui333 chenrui333 deleted the livecheck/npm-check-registry branch September 20, 2025 13:19
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

Successfully merging this pull request may close these issues.

4 participants