npm git协议依赖项

时间:2013-02-18 13:25:17

标签: git npm

在工作中,我们支持HTTP代理,并且git协议(端口9418)被拒绝。 我的项目有NPM依赖项,其中一些依赖项具有使用git协议的依赖项,例如:

在我的package.json

"dependencies": {
    "jsdoc3" : "git+https://github.com/jsdoc3/jsdoc.git"
}

和jsdoc3的package.json

"dependencies": {
    "crypto-browserify": "git://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git://github.com/hegemonic/github-flavored-markdown.git"
}

如何获取这些依赖项,如何告诉NPM使用git+https://协议而不是git://协议或能够使用git协议?

为了简化我在Windows上的事情(在Linux上创建SSH隧道会更容易),我使用GIT-Bash。

谢谢

6 个答案:

答案 0 :(得分:32)

您可以使用以下命令告诉git使用https而不是git://:

git config --global url."https://".insteadOf git://

答案 1 :(得分:5)

最后,我发现了一个肮脏的解决方案,但这很好。我修改了NPM的代码,用git协议替换http协议(感谢开源)

npm v1.1.69 上,在文件npm/lib/cache.js中,我已将以下行添加到函数addRemoteGit

 // ssh paths that are scp-style urls don't need the ssh://
 if (parsed.pathname.match(/^\/?:/)) {
   u = u.replace(/^ssh:\/\//, "")
 }

 //begin trick
 if(/^git:/.test(u)){
     u = u.replace(/^git/, 'https');
 }
 //end trick

 log.verbose("addRemoteGit", [u, co])

答案 2 :(得分:3)

npm wiki中提出了两个git命令(参考:npm uses git:// and ssh+git:// only by default)。

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

答案 3 :(得分:1)

可以在依赖关系网址

中指定git+https://git+http://

我从

获取了以下package.json
{
  "name": "Sample package",
  "description": "Pacake for a Stackoverflow question",
  "author": "rk <rk@example.sampletld>",
  "dependencies": {
    "crypto-browserify": "git+https://github.com/dominictarr/crypto-browserify.git#95c5d505",
    "github-flavored-markdown": "git+https://github.com/hegemonic/github-flavored-markdown.git"
  },
  "engine": "node 0.4.1"
}

然后我运行npm installnode_modules包含以下

C:\Users\myself\node\node_modules>dir
 Volume in drive C is WINDOWS
 Volume Serial Number is 6E7A-96BE

 Directory of C:\Users\myself\node\node_modules

18/02/2013  13:57    <DIR>          .
18/02/2013  13:57    <DIR>          ..
18/02/2013  13:58    <DIR>          .bin
18/02/2013  13:57    <DIR>          crypto-browserify
18/02/2013  13:56    <DIR>          express
18/02/2013  13:57    <DIR>          github-flavored-markdown
18/02/2013  13:56    <DIR>          optimist
               0 File(s)              0 bytes
               7 Dir(s)  31,641,919,488 bytes free

C:\Users\myself\node\node_modules>

我尝试使用git + http和git + https两种协议,但两者都有效,但裸http无法产生错误。

答案 4 :(得分:1)

除了@Nowres建议外,我还必须执行以下操作才能使其正常工作

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

答案 5 :(得分:1)

npm ci 一直在尝试使用 ssh://,因此我必须执行以下操作:

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf ssh://
相关问题