如何支持生活在一个git repo中的多个私有npm包?

时间:2023-02-05 15:16:30

npm is very good at supporting packages publishes to the global/central npm repo, which doesn't work well for private, application code. npm also supports adding a git repo as a dependency, which lets you have a private dependency.

npm非常擅长于支持包发布到global/central npm repo,这对于私有的应用程序代码并不适用。npm还支持将git repo添加为依赖项,使您拥有一个私有依赖项。

The problem is, as I understand to be best practice, my npm packages tend to be very tight and small, whereas my git repos tend to be larger, and will include several npm packages. I do not know any way to attain this granularity while pointing to a github URL. How to solve this?

问题是,正如我所理解的最佳实践,我的npm包往往非常紧凑和小,而我的git repos往往更大,并且将包含几个npm包。我不知道在指向github URL时如何达到这种粒度。如何解决呢?

UPDATE

更新

I accepted the answer that says "don't do this, stay on the rails." I agree with this recommendation, but YMMV.

我接受了这样的回答:“不要这么做,坚持下去。”我同意这个建议,但是YMMV。

2 个解决方案

#1


12  

I would suggest that one repo with multiple packages is a bad idea to start with for several reasons. You should be viewing a package as its own entity: independently built, tested, and deployed. All that to say, each package should live in its own repo.

我认为,一个带有多个包的repo开头不是个好主意,原因有以下几个。您应该将包视为它自己的实体:独立构建、测试和部署。话虽如此,每个包裹都应该有自己的“回购”。

That being said, I definitely understand the benefit of being able to do an npm install <package-group> of one "commons" package and have it grab all the packages you need in one shot. I would suggest looking at the grunt-contrib model for accomplishing this. In short, they have a bunch of grunt-contrib- packages (ex. grunt-contrib-coffee) each living in their own repositories. They then create a separate repository that defines the parent "grunt-contrib" package. All this parent package does is specify dependencies on all of the sub-packages. This allows you to do an npm install grunt-contrib-coffee (for example) and get just the grunt-contrib-coffee package; or you can do npm install grunt-contrib and get their entire suite all in one shot.

话虽如此,我绝对理解能够在一个“commons”包中执行npm安装 ,并让它一次性获取所需的所有包的好处。我建议大家看看“咕哝式设计”模式来实现这一目标。简而言之,他们有一群“咕哝-设计-包装”(例如,咕哝-设计-咖啡),每个人都住在自己的仓库里。然后,他们创建一个单独的存储库来定义父“grunt-悔过”包。父包所做的就是指定对所有子包的依赖关系。这样你就可以在npm上安装“咕哝-懊悔-咖啡”(例如),然后得到“咕哝-懊悔- -咖啡”;或者你也可以在npm上安装垃圾软件,让他们的整个套件一气呵成。

Hope this helps!

希望这可以帮助!

#2


1  

You could also set up your own local npm repository.

您还可以设置自己的本地npm存储库。

#1


12  

I would suggest that one repo with multiple packages is a bad idea to start with for several reasons. You should be viewing a package as its own entity: independently built, tested, and deployed. All that to say, each package should live in its own repo.

我认为,一个带有多个包的repo开头不是个好主意,原因有以下几个。您应该将包视为它自己的实体:独立构建、测试和部署。话虽如此,每个包裹都应该有自己的“回购”。

That being said, I definitely understand the benefit of being able to do an npm install <package-group> of one "commons" package and have it grab all the packages you need in one shot. I would suggest looking at the grunt-contrib model for accomplishing this. In short, they have a bunch of grunt-contrib- packages (ex. grunt-contrib-coffee) each living in their own repositories. They then create a separate repository that defines the parent "grunt-contrib" package. All this parent package does is specify dependencies on all of the sub-packages. This allows you to do an npm install grunt-contrib-coffee (for example) and get just the grunt-contrib-coffee package; or you can do npm install grunt-contrib and get their entire suite all in one shot.

话虽如此,我绝对理解能够在一个“commons”包中执行npm安装 ,并让它一次性获取所需的所有包的好处。我建议大家看看“咕哝式设计”模式来实现这一目标。简而言之,他们有一群“咕哝-设计-包装”(例如,咕哝-设计-咖啡),每个人都住在自己的仓库里。然后,他们创建一个单独的存储库来定义父“grunt-悔过”包。父包所做的就是指定对所有子包的依赖关系。这样你就可以在npm上安装“咕哝-懊悔-咖啡”(例如),然后得到“咕哝-懊悔- -咖啡”;或者你也可以在npm上安装垃圾软件,让他们的整个套件一气呵成。

Hope this helps!

希望这可以帮助!

#2


1  

You could also set up your own local npm repository.

您还可以设置自己的本地npm存储库。