简体   繁体   English

从私有存储库以不同的软件包名称安装npm

[英]npm install from private repository as a different package name

I need to install a module from a private github repo. 我需要从私有github存储库安装模块。 In order to do that I'll run npm install git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch> . 为此,我将运行npm install git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch> My package.json file would look something like this: 我的package.json文件如下所示:

"dependencies: {
    ...
    "private-repo-name": "git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>",
    ...
}

In this case, "private-repo-name" corresponds to the name field of the package.json of the private repo, ie: 在这种情况下, "private-repo-name"对应于私有仓库的package.jsonname字段,即:

"name": "private-repo-name"

My question is: How do I change the package name during npm install without changing the name field of the private repo? 我的问题是:如何在npm install过程中更改软件包名称而不更改私有仓库的name字段?

Note: For public npm modules this wouldn't be a problem due to npm modules not sharing namespaces in the npm registry, but for privately developed modules that arent hosted in npm, there is a potential for the module name to conflict with current or future public npm modules in the npm registry. 注意:对于公共npm模块,由于npm模块不共享npm注册表中的命名空间,这将不是问题,但对于npm中托管的私有开发的模块,模块名称有可能与当前或将来的名称冲突npm注册表中的公共npm模块。

it can be done by setting up system HTTP_PROXY and HTTPS_PROXY environment variable to your private repo. 可以通过将系统HTTP_PROXYHTTPS_PROXY环境变量设置为您的私有存储库来完成。 after that it will work for command like npm install . 之后,它将适用于npm install类的命令。 but it will install the package with the name they have in the repo. 但是它将使用回购中安装的名称安装软件包。

It turns out that you can simply run npm install new-name@git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch> 事实证明,您只需运行npm install new-name@git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>

how to install multiple versions of package using npm 如何使用npm安装软件包的多个版本

There's no coupling between the keys in the dependencies field & the name field in the private repo. 私有存储库中的dependencies字段和name字段中的键之间没有耦合。

ie

"dependencies: {
    ...
    "new-name": "git+https://[API-KEY]:x-oauth-basic@github.com/<name>/<repo>.git#<branch>",
    ...
}

After this, commands like npm update new-name would work as expected. 此后, npm update new-name类的命令将按预期工作。

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

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