[英]npm install from private registry with fallback to a git repository URL
I am kind of a newbie regarding the npm
, so please help. 关于
npm
,我是一个新手,所以请帮忙。
Let's say that i have some modules i am working on using a git repository for each one of them and i also installed sinopia
to have a private registry. 假设我有一些模块,我正在为每一个使用git存储库,我还安装了
sinopia
以获得私有注册表。 The problem is that we are 2 teams. 问题是我们是2支球队。 A team in a city and the other one is at world's end.
一个城市的团队和另一个团队在世界尽头。 In my team i have installed the private registry to be available in the local network.
在我的团队中,我已经安装了私有注册表,可以在本地网络中使用。 The issue here is that when we push on git, the other team doesn't have a private registry of their own, and even if they did they would need to publish each version of each module in their private registry.
这里的问题是,当我们推送git时,另一个团队没有他们自己的私有注册表,即使他们这样做,他们也需要在他们的私有注册表中发布每个模块的每个版本。 Also another issue is that we can't ( and don't want to ) make the
sinopia
server public via IP. 另一个问题是我们不能(也不想)通过IP公开
sinopia
服务器。
Now the question is: How can we configure the package.json
/ npm
to manage dependencies from both the private registry ( if the registry responds ) and the git repository also ( if the private registry doesn't respond -- aka it doesn't exist -- ). 现在问题是:我们如何配置
package.json
/ npm
来管理来自私有注册表(如果注册表响应)和git存储库的依赖关系(如果私有注册表没有响应 - 也就是说它没有存在 - )。
I know that we could set up each dependency to refer to a git tag/branch/commit but we want also to use the registry if possible. 我知道我们可以设置每个依赖项来引用git标记/分支/提交,但我们也希望尽可能使用注册表。
UPDATE UPDATE
So basically I would need a package.json that would know that if this part fails: 所以基本上我需要一个package.json,知道如果这部分失败:
"dependencies": {
"app.core": "0.1.1"
}
because the private registry is not installed or not available, it could still load the dependecy from something like this: 因为私有注册表未安装或不可用,它仍然可以从以下内容加载依赖:
"dependencies": {
"app.core": "git+ssh://git@repo.mydomain.com:group/app-core.git#v0.1.1"
},
Also note that i would prefer something that can be pushed in the git repository so that neither one of the teams should change the package.json locally. 另请注意,我更喜欢可以在git存储库中推送的内容,这样任何一个团队都不应该在本地更改package.json。
Hope that someone can help. 希望有人可以提供帮助。
The only way that i found to work for the moment is to have a package.json like this: 我发现目前工作的唯一方法是有一个像这样的package.json:
"scripts": {
"postinstall" : "node fallbackDependencies.js"
}
"dependencies": {
"app.core": "git+ssh://git@repo.mydomain.com:group/app-core.git#v0.1.1"
},
"optionalDependencies": {
"app.core": "0.1.1"
}
And in the fallbackDependencies.js
file to run a script that takes all the dependencies from the package.json which are also in the optionalDependencies
and for each of them check if there is a folder with that name in the node_modules
folder. 并且在
fallbackDependencies.js
文件中运行一个脚本,该脚本从package.json获取所有依赖项,这些依赖项也在optionalDependencies
并且对于每个依赖项,检查node_modules
文件夹中是否存在具有该名称的文件夹。 If there is no folder then run npm install <json.dependencies[x]>
. 如果没有文件夹,则运行
npm install <json.dependencies[x]>
。
This is the only temporary solution that i could think of. 这是我能想到的唯一临时解决方案。
If someone has a better approach to this please feel free to answer. 如果有人有更好的方法,请随时回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.