npm / npm-registry-client

http://npm.im/npm-registry-client
ISC License
264 stars 108 forks source link

get fails with scoped packages #123

Closed mjackson closed 8 years ago

mjackson commented 8 years ago

I can't seem to use the get method to fetch package info about scoped packages. In my node prompt:

> var RegistryClient = require('npm-registry-client')
> var client = new RegistryClient
undefined
> client.get('https://registry.npmjs.org/@cycle/core', { timeout: 5000 }, function (error) { console.log(error) })
info attempt registry request try #1 at 12:55:30 AM
http request GET https://registry.npmjs.org/@cycle/core
http 404 https://registry.npmjs.org/@cycle/core
{ [Error: Not found : @cycle] pkgid: '@cycle', statusCode: 404, code: 'E404' }

Am I doing something wrong?

othiym23 commented 8 years ago

npm-registry-client is due for a rewrite, for this reason and many others. If you look at how npm calls into it, you'll see that scoped package names are encoded such that / becomes %2f (due to legacy CouchDB-related reasons). Also, you're going to need to pass along a bearer token as auth in the request's options parameter to get metadata on scoped packages. It should work without auth for scoped public packages, but it definitely won't for private.

As this is all by design, I'm going to close this issue, but rest assured that a new major version of npm-registry-client with a much less obtuse API is a high priority for the team.

mjackson commented 8 years ago

Thank you for the explanation, @othiym23. For now I'm only interested in getting info on public scoped packages. Is there a workaround for the encoding issue? From the error message, it looks like the registry is only recognizing @cycle as the package name, not @cycle/core.

mjackson commented 8 years ago

Perhaps there is a straight-up HTTP endpoint I could hit to get data about packages? I'm only ever doing GETs, so I actually don't need most of the fancy stuff npm-registry-client gives me.

mjackson commented 8 years ago

Ah, nm. I just followed the source and found out how to call it. Thanks again, @othiym23!

tiansijie commented 8 years ago

@mjackson could you share how you call it with scoped packages? thanks

mjackson commented 8 years ago

@tiansijie https://github.com/mjackson/npm-http-server/blob/b4719424f168648e8cf164cc1abea3c44237b43e/modules/getPackageInfo.js#L9-L23

That's how you encode the package name in the registry URL.

tiansijie commented 8 years ago

@mjackson thanks!