npm: How to install npm GitHub repositories with specific ssh keys?

Viewed 402

I have a package.json with two private GitHub repositories. They both have to use a different SSH deploy key. For Git repositories without npm, this can be handled with a host in .ssh/config, for example:

Host repo1.github.com
    HostName github.com
    IdentityFile ~/.ssh/repo1

Host repo2.github.com
    HostName github.com
    IdentityFile ~/.ssh/repo2

Then in .git/config of repo1, I would have:

[remote "origin"]
    url = git@repo1.github.com:org/repo1.git

Now, I thought I could just use the same trick for npm dependencies:

npm install "git+ssh://git@repo1.github.com/org/repo1.git#commit-hash" --save

Unfortunately, this will give me:

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "ssh:": ssh://git@repo1.github.com/org/repo1.git#commit-hash

If I use instead and the ssh right key is loaded:

npm install "git+ssh://git@github.com/org/repo1.git#commit-hash" --save

Then it works as expected. However, this is not a solution since I want to be able to run npm install and then it will have to use two different keys.

How can this be solved?

0 Answers
Related