简体   繁体   English

查询有关作用域npm包的特定版本的信息

[英]Querying information about specific version of scoped npm package

I can successfully query meta information for a specific version of a specific NPM package like this: 我可以成功查询特定NPM包的特定版本的元信息,如下所示:

GET https://registry.npmjs.org/<name>/<version>

for example: https://registry.npmjs.org/camelcase/2.1.1 例如: https//registry.npmjs.org/camelcase/2.1.1

But for scoped packages like @angular/core this doesn't work. 但对于像@angular/core这样的范围包,这不起作用。 I tried all of the following, but they all fail: 我尝试了以下所有方法,但都失败了:

What is the correct way for querying a specific version of a scoped package? 查询特定版本的作用域包的正确方法是什么?

You can do this from a bash command: 您可以通过bash命令执行此操作:

npm view @angular/core/6.1.10

So npm is adding some authentication to the request for scoped packages. 因此,npm正在为范围包的请求添加一些身份验证。 For this to work you have to have a valid package.json in the local directory. 为此,您必须在本地目录中拥有有效的package.json。

Of course, worst case, you can do a process.spawn() to run the npm command. 当然,最坏的情况是,你可以做一个process.spawn()来运行npm命令。

FYI, I tried using the npm-registry-client package, with my npm credentials: 仅供参考,我尝试使用npm-registry-client软件包和我的npm凭证:

 var RegClient = require('npm-registry-client') var client = new RegClient({ username: 'mememe', password: 'xxxxx' }) var uri = "https://registry.npmjs.org/@angular/core/6.1.10" var params = {timeout: 1000} client.get(uri, params, function (error, data, raw, res) { console.log(data); }) 

and I got this: 我得到了这个:

info attempt registry request try #1 at 09:52:09
http request GET https://registry.npmjs.org/@angular/core/6.1.10
http 401 https://registry.npmjs.org/@angular/core/6.1.10
WARN notice ERROR: you cannot fetch versions for scoped packages

It appears they don't allow specific version querying, but per @RobC's comments below, they do allow grabbing the entire repository's information, so you can do this client-side: 看起来他们不允许特定的版本查询,但根据@ RobC的评论,他们确实允许抓取整个存储库的信息,所以你可以做这个客户端:

 url = 'https://registry.npmjs.org/@angular%2fcore'; const fetch = require('node-fetch'); fetch(url).then(response => response.json()).then(results => { console.log(results.versions['6.1.10']); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM