Skip to content
/ npm-github Public template

Template for GitHub hosted NPM packages

Notifications You must be signed in to change notification settings

thomashagstrom/npm-github

Repository files navigation

npm-github

Table of contents generated with markdown-toc

Github hosted NPM package. Only a template for writing NPM packages on GitHub and there's no reason to install it more than to show how to consume a privately scoped package.

Prettier

Based on this guide and the official documentation:

drawing

https://levelup.gitconnected.com/private-npm-packages-in-github-package-registry-fbfda43acab3

Creating a package

  1. Init a package using npx tsdx create mylib (TypeScript) or npm init.
  2. Set .npmrc to the package scope (owner) @thomashagstrom:registry=https://npm.pkg.github.com
  3. Add GitHub actions workflow using the "Publish node.js package" template or this npm-publish.yml (excluding npmjs).
  4. Tag, set version and push.

Publish a new version

  1. Up version in package.json
  2. Tag and push
  3. Draft a new Release from that tag
  4. GitHub Action builds and publishes

Consume package

These details are valid if the package is private scoped.

  1. Open the lib where u want to consume the private NPM package
  2. Create a personal access token with write:packages scope
  3. Config .npmrc to use the token (below)
  4. Install the scoped package, e.g. yarn add https://github.com/thomashagstrom/npm-github

Example npmrc config for consuming thomashagstrom org scoped packages:

@thomashagstrom:registry=https://npm.pkg.github.com/thomashagstrom
//npm.pkg.github.com/:_authToken=MyTopSecretTokenWithPackageScope