[英]npm install private github repositories by dependency in package.json
I'm trying to install github private repository by npm that includes other private github repositories as dependency.我正在尝试通过 npm 安装 github 私有存储库,其中包括其他私有 github 存储库作为依赖项。
Have tried a lot of ways and posts but none is working.尝试了很多方法和帖子,但没有一个有效。 Here is what i'm doing :
这是我正在做的事情:
npm install git+https://github.com/myusername/mygitrepository.git
Try this:尝试这个:
"dependencies" : {
"name1" : "git://github.com/user/project.git#commit-ish",
"name2" : "git://github.com/user/project.git#commit-ish"
}
You could also try this, where visionmedia/express is name/repo:你也可以试试这个,其中 visionmedia/express 是名称/仓库:
"dependencies" : {
"express" : "visionmedia/express"
}
Or (if the npm package module exists):或者(如果 npm 包模块存在):
"dependencies" : {
"name": "*"
}
The following worked just fine in all scenarios i needed :以下在我需要的所有场景中都运行良好:
"dependencies": {
"GitRepo": "git+https://<token-from-github>:x-oauth-basic@github.com/<user>/<GitRepo>.git"
}
For those of you who came here for public directories, from the npm docs: https://docs.npmjs.com/files/package.json#git-urls-as-dependencies对于那些来到这里获取公共目录的人,来自 npm 文档: https ://docs.npmjs.com/files/package.json#git-urls-as-dependencies
Git urls can be of the form: Git 网址可以采用以下形式:
git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish
The commit-ish can be any tag, sha, or branch which can be supplied as an argument to git checkout. commit-ish 可以是任何可以作为参数提供给 git checkout 的标签、sha 或分支。 The default is master.
默认是主。
The accepted answer works, but I don't like much the idea to paste secure tokens into the package.json
接受的答案有效,但我不太喜欢将安全令牌粘贴到
package.json
的想法
I have found it elsewhere, just run this one-time command as documented in the git-config manpage .我在其他地方找到了它,只需按照 git-config 手册页中的说明运行这个一次性命令。
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf git@github.com:
GITHUB_TOKEN
may be setup as environmnet variable or pasted directly GITHUB_TOKEN
可以设置为环境变量或直接粘贴
and then I install private github repos like: npm install user/repo --save
然后我安装私有 github 存储库,如:
npm install user/repo --save
works also in Heroku, just setup the above git config ...
command as heroku-prebuild
script in package.json
and setup GITHUB_TOKEN
as Heroku config variable.也适用于 Heroku,只需将上面的
git config ...
命令设置为package.json
heroku-prebuild
脚本,并将GITHUB_TOKEN
设置为 Heroku 配置变量。
There are multiple ways to do it as people point out, but the shortest versions are:正如人们指出的那样,有多种方法可以做到,但最短的版本是:
// from master
"depName": "user/repo",
// specific branch
"depName": "user/repo#branch",
// specific commit
"depName": "user/repo#commit",
// private repo
"depName": "git+https://[TOKEN]:x-oauth-basic@github.com/user/repo.git"
eg例如
"dependencies" : {
"hexo-renderer-marked": "amejiarosario/dsa.jsd#book",
"hexo-renderer-marked": "amejiarosario/dsa.js#8ea61ce",
"hexo-renderer-marked": "amejiarosario/dsa.js",
}
"dependencies": {
"some-package": "github:github_username/some-package"
}
or just要不就
"dependencies": {
"some-package": "github_username/some-package"
}
https://docs.npmjs.com/files/package.json#github-urls https://docs.npmjs.com/files/package.json#github-urls
Since Git uses curl
under the hood, you can use ~/.netrc
file with the credentials.由于 Git 在幕后使用
curl
,您可以使用~/.netrc
文件和凭据。 For GitHub it would look something like this:对于 GitHub,它看起来像这样:
machine github.com
login <github username>
password <password OR github access token>
If you choose to use access tokens
, it can be generated from:如果您选择使用
access tokens
,则可以从以下位置生成:
Settings -> Developer settings -> Personal access tokens
设置 -> 开发者设置 -> 个人访问令牌
This should also work if you are using Github Enterprise in your own corporation.如果您在自己的公司中使用 Github Enterprise,这也应该有效。 just put your enterprise github url in the
machine
field.只需将您的企业 github url 放在
machine
字段中。
Here is a more detailed version of how to use the Github token without publishing in the package.json
file.这里有一个更详细的版本,说明如何使用 Github 令牌而不在
package.json
文件中发布。
git config --global url."https://<TOKEN HERE>:x-oauth-basic@github.com/".insteadOf https://x-oauth-basic@github.com/
npm install --loglevel verbose --save git+https://x-oauth-basic@github.com/<USERNAME HERE>/<REPOSITORY HERE>.git#v0.1.27
In case access to Github fails, try running the git ls-remote ...
command that the npm install will print
如果访问 Github 失败,请尝试运行
npm install will print
的git ls-remote ...
命令
Further, in order to make key's access secure此外,为了使密钥的访问安全
Package.json
包.json
"dependencies": { ... "my-private-github-repo": "git+https://${ENV.PERSONAL_ACCESS_TOKEN}@github.com/USER/abcd-repo-3.4.0.git", ... }
"dependencies": { ... "my-private-github-repo": "git+https://${ENV.PERSONAL_ACCESS_TOKEN}@github.com/USER/abcd-repo-3.4.0.git", . .. }
There are other ways using 'DOTENV' npm package, but it could not do much when we are trying to resolve "Github" package dependency.还有其他使用“DOTENV”npm 包的方法,但是当我们尝试解决“Github”包依赖性时,它无能为力。 Above seems to be straight forward solution.
以上似乎是直接的解决方案。
For my private repository reference I didn't want to include a secure token, and none of the other simple (ie specifying only in package.json) worked.对于我的私有存储库引用,我不想包含安全令牌,其他简单的(即仅在 package.json 中指定)都不起作用。 Here's what did work:
这是有效的:
There's also SSH Key - Still asking for password and passphrase还有SSH 密钥 - 仍然要求输入密码和密码
Using ssh-add ~/.ssh/id_rsa
without a local keychain.在没有本地钥匙串的情况下使用
ssh-add ~/.ssh/id_rsa
。
This avoids having to mess with tokens.这避免了必须弄乱令牌。
If you want to add the dependency that is not anchored to master nor to a particular commit, you can do it by using semver.如果要添加既不锚定到 master 也不锚定到特定提交的依赖项,可以使用 semver 来完成。 Like that:
像那样:
"dependencies": {
"some-package": "github:github_username/some-package#semver:^1.0.0"
}
请注意,您尝试作为依赖项添加到 package.json 文件的 github 存储库需要定义自己的 package.json 文件。
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.