How to set up an NPM dependency from a GitHub URL in a package.json for SSH and HTTPS.
2019-10-26
I often find myself wanting to use changes that I've made for an NPM dependency in a personal fork.
NPM (and yarn) have a useful convention for pointing to a git repository instead in a project's package.json
dependencies
by pointing to the fork and optionally using a specific branch instead of giving it a version number.
Here's how to set that up in a package.json
for SSH and HTTPS. This example uses the isomorphic-fetch
package.
Convention for a basic configuration for a package using git:
git+{protocol}://{user}@{hostname}:{project owner}/{project}.git#{branch name}
ssh
or https
.git
. Usually the user is git
, especially for github.com and gitlab.comFollowing the example, a basic version composition for SSH looks like this:
git+ssh://git@github.com:matthew-andrews/isomorphic-fetch.git
By branch:
git+ssh://git@github.com:matthew-andrews/isomorphic-fetch.git#some-branch
Following the example, a basic version composition for HTTPS looks like this:
git+https://git@github.com:matthew-andrews/isomorphic-fetch.git
By branch:
git+https://git@github.com:matthew-andrews/isomorphic-fetch.git#some-branch
This is what the JSON would look like for dependencies
in package.json
:
{
"dependencies": {
"isomorphic-fetch": "git@github.com:matthew-andrews/isomorphic-fetch.git"
}
}
Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.
Subscribe to my Newsletter
Every other week I publish the Curiously Crafted newsletter.
In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.