如何使用私有Github存储库作为npm依赖项

node.js Node.js

阿飞

2020-03-23

我如何列出一个私有的Github仓库作为"dependency"in package.json我尝试了npm的Github URL语法,例如ryanve/example,但是npm install在package文件夹中这样做会导致私有依赖项出现“无法安装”错误。是否有特殊的语法(或其他机制)用于依赖私有存储库?

第3005篇《如何使用私有Github存储库作为npm依赖项》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

3个回答
Harry猴子A 2020.03.23

使用git有一个https格式

https://github.com/equivalent/we_demand_serverless_ruby.git

此格式接受用户+密码

https://bot-user:xxxxxxxxxxxxxxxxxxxxxxxxxxx@github.com/equivalent/we_demand_serverless_ruby.git

因此,您可以做的是创建一个新用户,将其用作机器人,仅添加足够的权限,使其可以读取要加载到NPM模块中的存储库,然后直接将其存储在您的NPM模块中。 packages.json

 Github > Click on Profile > Settings > Developer settings > Personal access tokens > Generate new token

在“选择作用域”部分中,检查on repo:完全控制私有存储库

这样令牌可以访问用户可以看到的私有仓库

Now create new group in your organization, add this user to the group and add only repositories that you expect to be pulled this way (READ ONLY permission !)

You need to be sure to push this config only to private repo

Then you can add this to your / packages.json (bot-user is name of user, xxxxxxxxx is the generated personal token)

// packages.json


{
  // ....
    "name_of_my_lib": "https://bot-user:xxxxxxxxxxxxxxxxxxxxxxxxxxx@github.com/ghuser/name_of_my_lib.git"
  // ...
}

https://blog.eq8.eu/til/pull-git-private-repo-from-github-from-npm-modules-or-bundler.html

番长樱梅 2020.03.23

如果有人在为Git Lab寻找其他选项,而以上选项不起作用,那么我们还有另一个选项。对于本地安装的Git Lab服务器,我们发现下面的方法允许我们包括软件包依赖关系。我们生成并使用了访问令牌来做到这一点。

$ npm install --save-dev https://git.yourdomain.com/userOrGroup/gitLabProjectName/repository/archive.tar.gz?private_token=InsertYourAccessTokenHere

当然,如果以这种方式使用访问密钥,则它应具有一组有限的权限。

祝好运!

卡卡西 2020.03.23

可以通过https和oauth ssh完成。

https和oauth: 创建具有“回购”范围的访问令牌然后使用以下语法

"package-name": "git+https://<github_token>:x-oauth-basic@github.com/<user>/<repo>.git"

要么

ssh: 设置ssh,然后使用以下语法:

"package-name": "git+ssh://git@github.com:<user>/<repo>.git"

(请注意在用户之前使用冒号而不是斜杠)

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android