Skip to content

feat: unifying npm registry requests with caching#641

Open
OrbisK wants to merge 13 commits intonpmx-dev:mainfrom
OrbisK:feat/concept-npm-requests
Open

feat: unifying npm registry requests with caching#641
OrbisK wants to merge 13 commits intonpmx-dev:mainfrom
OrbisK:feat/concept-npm-requests

Conversation

@OrbisK
Copy link
Contributor

@OrbisK OrbisK commented Feb 1, 2026

I think it is not an easy change to refactor all npm requests to useNpmRegistry (yet). As a first step, we could migrate all npm requests to $npmRegistry and $npmApi. Wdyt?

@vercel
Copy link

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Error Error Feb 6, 2026 11:55am
npmx.dev Ready Ready Preview, Comment Feb 6, 2026 11:55am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Feb 6, 2026 11:55am

Request Review

…ests

# Conflicts:
#	app/composables/useNpmRegistry.ts
#	app/utils/package-name.ts
@OrbisK OrbisK changed the title wip: proof of concept unifying all registry requests feat: unifying npm registry requests with caching Feb 1, 2026
@danielroe
Copy link
Member

this looks good!

would you investigate why the browser tests might be failing?

@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 1, 2026

this looks good!

would you investigate why the browser tests might be failing?

Working on it. Maybe you know what the issue is. e.g. the org page is broken.

https://npmxdev-git-fork-orbisk-feat-concept-npm-requests-poetry.vercel.app/@nuxt

image

Here: https://github.com/npmx-dev/npmx.dev/pull/641/changes#diff-93fe589cec6bc2b865b353a91ba90b4407706ff4baf16189a4c2c538351aa26aR523

@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 1, 2026

I think the problem is that cachedFetch from the plugin uses the server side fetch on the client 🤷🏽‍♂️

I think I have a fix.

@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 1, 2026

I am super confused. Are $npmRegistry request meant to run client side? Because there are cors issues when requesting the orgs

@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 1, 2026

Okay. The request returns the data and 200 but cors is still blocking it 🤔

@danielroe
Copy link
Member

danielroe commented Feb 1, 2026

$npmRegistry should be idempotent, yes. (it should be safe to call in either case)

if there's stale data (or missing data) from the server, then it will refetch on the client

@danielroe danielroe self-requested a review February 1, 2026 17:24
@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 1, 2026

Progress: I have fixed it locally. But i am not sure how...

Comment on lines 33 to 34
const { $npmApi } = useNuxtApp()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danielroe this line seems to be the problem.

replacing it by a simple mock "fixes" the issue. Any ideas 😅

 const $npmApi = ()=>{
  return Promise.resolve({data: null,})
 }

@codecov
Copy link

codecov bot commented Feb 3, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This pull request replaces hard-coded NPM registry/API usage with Nuxt-injected runtime helpers ($npmRegistry, $npmApi) provided by a new plugin. Multiple npm-related composables and utilities were updated to use those injected helpers instead of direct constants or useCachedFetch. useCachedFetch now merges default fetch options via defu and its _ttl parameter has a default value. NPM endpoint constants were consolidated into shared constants, tests were updated to expect relative API paths, and vitest browser headless was made explicit.

Possibly related PRs

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description relates directly to the changeset, which migrates npm requests to use $npmRegistry and $npmApi helpers as an incremental step toward unified request handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@43081j
Copy link
Contributor

43081j commented Feb 3, 2026

caught it up from main for you @OrbisK (lots of conflicts)

code has moved around a fair bit so can you have a read through again to be sure its all good?

@OrbisK
Copy link
Contributor Author

OrbisK commented Feb 3, 2026

caught it up from main for you @OrbisK (lots of conflicts)

code has moved around a fair bit so can you have a read through again to be sure its all good?

looks good. 👍🏽 Not sure how to fix the Nuxt instance issue though. I think this might be a Nuxt bug.

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