Publish GitHub packages

How to publish packages on a github repository

Fri Jul 16 2021

In Github every repository can publish packages, which can be used as dependencies in other projects.

Naming rule

Name of the package should include organization/username and will look like

@organization/name_of_the_pacakage

So adjust name in package.json

Repository

Don' forget to publish the repository and add it to the package file as follows

"repository":{
  "url": "git://github.com/org_name/some_repo.git"
}

Access Token

We have to use the personal access token to authenticate, we can add the secret to the .npmrc file, so that need not authenticate manually.

.npmrc

This file can contain the registry information and authentication secrets, we need not expose this file to repository, so that add the file to the .gitignore

In the .npmrc include the registry information along with organization / owner .

@owner:registry=https://npm.pkg.github.com
npm.pkg.github.com/:_authToken=TOKEN

Replace the owner with user/org and TOKEN with personal token generated.

//.gitignore
​
.npmrc
node_modules

Publish

Let's jump into terminal issue the npm publish command and it will take few minutes to update. The package will list on the repository as well as on user/org profile page.

Update

How to update package ? Can't do that ! instead publish new version by change the version in package.json and publish new one.

Remove

For removing, there is dedicated delete button in relevant package.

Comments