Github has come up with their own package registry solution. https://github.com/features/packages similar to npm package the packages are hosted in github, I use git mostly so it makes sense for me to host packages there also provides mechanism for private packages.
Let's dive into the usage for github packages. We publish packages under a owner's scope. Say my github username is karkipy so the scope is @karkipy , and the package name will be the combination of your scope and the repo name itself such as @karkipy /randomPackage.
Now to publish this package into github registry we can specify it in the package.json file about which registry it should refer to such as
"publishConfig": {
"registry":"https://npm.pkg.github.com"
}
To publish :
npm publish
should do the trick, now installing packages both from npm and github can be tricky as we have to specify from which we are installing packages, if only github is mentioned then the conflict will arise as many fundamental packages may not have been hosted by github package registry or if only npm is mentioned then the package from github will not be installed. So we need to specify packages to be installed from multiple organization.
Create an .npmrc for this particular configuration, make sure it is in root. Configuration for the file should be something as :
//npm.pkg.github.com/:_authToken=GITPERSONALACCESSTOKEN
@karkipy:registry=https://npm.pkg.github.com/
//registry.npmjs.org/:_authToken=NPM_TOKEN
Personal access token should be granted for the private packages that you publish in github similar to that NPM_TOKEN does the same.
NPM_TOKEN: https://docs.npmjs.com/creating-and-viewing-access-tokens
GITPERSONALACCESSTOKEN: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
Top comments (0)