配置npm以使用工件作为npm注册表和github的代理来解决依赖关系 [英] Configure npm to resolve dependencies using artifactory as proxy for both npm registry and github

查看:129
本文介绍了配置npm以使用工件作为npm注册表和github的代理来解决依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法访问互联网的构建服务器,我需要解析来自github.com和Registry.npmjs.org的依赖关系.构建服务器可以访问Artifactory,因此我已经创建了一个NPM存储库来代理Registry.npmjs.org,并且可以正常工作,并且我刚刚创建了一个VCS存储库来代理github.com.

I have a build server with no internet access, and I need to resolve dependencies from both github.com and registry.npmjs.org. The build server has access to Artifactory, so I have created an NPM repo to proxy for registry.npmjs.org and that is working, and I just created a VCS repo to proxy for github.com.

如何配置npm来解决这两个问题?由于这两个存储库是不同的类型,因此我无法将它们聚合到一个虚拟存储库中.可以配置NPM来解决这两个方面的依赖性吗?

How can I configure npm to resolve from both of these? Since the 2 repos are different types, I can't aggregate them into a single virtual repo. Can NPM be configured to resolve dependencies from both of these?

推荐答案

VCS存储库与NPM依赖项的相关性为零. VCS存储库只是通往远程git服务器上一组API的网关,可帮助您缓存源二进制文件(即特定分支/标签甚至发布的zip/tarball). npm客户端不熟悉Artifactory为此类存储库公开的REST端点.

VCS repos have zero correlation to NPM dependencies. A VCS repo is just a gateway to a set of APIs on the remote git server that will help you cache source binaries (i.e a zip/tarball of a particular branch/tag or even a release). The npm client is not familiar with the REST endpoints that Artifactory exposes for such repos.

对于在package.json中引用github repos的NPM软件包(请参阅URL作为依赖关系&Git URL作为依赖关系部分

For NPM packages that reference github repos inside their package.json (see URLs as dependencies & Git URLs as Dependencies sections here), you want to look into Artifactory's dependency-rewrite mechanism.

由于您的NPM客户端运行在无法访问Internet的计算机上,因此您自己的package.json文件不应直接依赖于"github依赖项",因为它们使客户端绕过〜/内部的注册表配置. npmrc并直接转到github而不是Artifactory.

Since your NPM client is running on a machine that has no access to the internet, your own package.json files should not depend directly on "github dependencies", since these make the client bypass the registry configuration inside your ~/.npmrc and go directly to github instead of Artifactory.

当您项目的一个依赖项的package.json使用github依赖项,并且该软件包通过Artifactory进行解析时,依赖项重写机制会在将其返回给客户端之前即时修改该package.json,以便后续的依赖项请求解决此类依赖关系的方法是通过Artifactory而不是通过github进行的,这对于诸如您这样的用例来说是完美的.

When the package.json of one of your project's dependencies uses github dependencies, and this package is resolved via Artifactory, the dependency rewrite mechanism modifies the package.json on the fly before returning it to the client, so that subsequent dependency requests to resolve such dependencies are attempted via Artifactory, and not via github -- this is perfect for use cases such as yours.

总而言之,您应该专门使用Artifactory上的NPM存储库,但也要利用虚拟存储库的依赖项重写机制,以避免通过github直接解决依赖关系.

In summary, you should stick with NPM repositories on Artifactory specifically, but also utilize the dependency rewrite mechanism of the Virtual Repository in order to avoid direct resolution of dependencies via github.

HTH,

这篇关于配置npm以使用工件作为npm注册表和github的代理来解决依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆