krampstudio
krampstudio

Reputation: 3631

npm git protocol dependencies

At work we are behind an HTTP Proxy and the git protocol (port 9418) is denied. My project has NPM dependencies and some of these dependencies have dependencies that use the git protocol, for instance:

In my package.json

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

and the package.json of jsdoc3:

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

How can I get those dependencies, how to tell NPM to use git+https:// protocol instead of git:// protocol or to be able to use the git protocol?

To simplify things I'm on windows (it would be easier on Linux to create an SSH tunnel), and I use GIT-Bash.

Thanks

Upvotes: 17

Views: 11391

Answers (6)

Rafał Cieślak
Rafał Cieślak

Reputation: 1003

npm ci kept trying to use ssh://, so I had to do the following:

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

Upvotes: 2

Damilola
Damilola

Reputation: 1024

In addition to @Nowres suggestion, I had to do the following to get it to work

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

Upvotes: 2

Trent
Trent

Reputation: 335

There are two git commands that are suggested in the npm wiki (reference: npm uses git:// and ssh+git:// only by default).

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

Upvotes: 4

Nowres Rafed
Nowres Rafed

Reputation: 1138

You can tell git to use https instead of git:// with the following command:

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

Upvotes: 40

krampstudio
krampstudio

Reputation: 3631

Finally I found a dirty solution, but that works fine. I've modified the code of NPM to replace the git protocol by the http protocol (thanks to opened source)

On npm v1.1.69, into the file npm/lib/cache.js, I've added the following lines to the function 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])

Upvotes: 5

Rob Kielty
Rob Kielty

Reputation: 8172

It is possible to specify git+https:// or git+http:// in your dependency URLs

I took the following package.json from

{
  "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"
}

I then ran npm install and the node_modules contained the following

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>

I tried this with both protocols git+http and git+https and the both worked, but bare http failed to work producing errors.

Upvotes: 1

Related Questions