2013-02-18 122 views
12

在工作中,我们在HTTP代理之后,并且git协议(端口9418)被拒绝。 我的项目有NPM的依赖关系和其中的一些依赖有使用Git协议,比如依赖性: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。

感谢

回答

28

通知Git使用https代替的git://使用下面的命令:

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

它可以指定你所依赖的网址git+https://git+http://

我采取了以下的package.json从

{ 
    "name": "Sample package", 
    "description": "Pacake for a Stackoverflow question", 
    "author": "rk <[email protected]>", 
    "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未能工作产生错误。

+0

我没有对依赖项的package.json文件的控制。在我的package.json中,我所有的依赖都使用'git + https'方案,但问题在于传递依赖(依赖关系)。 – krampstudio 2013-02-18 14:15:59

+0

啊我明白了;在Windows环境下建立一个SSH隧道应该不是不可能的,有工具可以做到这一点。否则你可能会破解你的直接依赖关系来使用+ http变体。虽然肯定是可怕的黑客攻击。最后,可以选择为项目制作商业案例,并将其呈现给网络管理员以允许git流量。 – 2013-02-18 14:19:33

5

最后我发现了一个肮脏的解决方案,但工作正常。我已经修改NPM的代码由http协议来代替git协议(由于打开源)

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

我也发现这个http:// stackoverflow。com/questions/4891527/git-protocol-blocked-by-company-how-can-i-get-around-that/10729634#10729634 – krampstudio 2013-02-20 12:39:00

+0

谢谢,我的工作代理服务器不支持url重写,但是这样做。 – 2013-10-21 11:13:56

+0

我不得不在这个文件里把'git:'改成'https:':'npm/node_modules/github-url-from-username-repo/index.js',但你让我在正确的轨道上修复同样的问题。谢谢! – quornian 2014-05-20 19:47:07

1

除了@Nowres sugge Stion的,我必须做到以下几点,以得到它的工作

git config --global url."https://github.com/".insteadOf [email protected]: 
git config --global url."https://".insteadOf git://