This is rei (example) node package, it's companion to the Node Packages - Unit Tests and Github Actions blog issue to demonstrate using and publishing npm packages to github. But these techniques can be used for other package registries with some changes.
$ npm install @nakamorg/rei-node-package
const rei = require("@nakamorg/rei-node-package");
rei();
//=> "You have succesfull installed and ran nakamorg's rei package"
- Create a personal github token with following permissions:
repo
,write:packages
- Do
npm login
using your github username as username and personal access token as password.wherenpm login --scope=@<SCOPE> --registry=https://npm.pkg.github.com
SCOPE
would be your github org name or username. - Create a new repo for your package
<package-name>
. It is recommended to have same name for repo and package. Make your repo private if you want to keep your package private. - Copy over all the files from here to your repo and edit files as necessary. You should, at least, update your
package.json
file with your package's info - publish your package (CI -- GH Actions should handle publishing, but you can test as follow)
# run tests -- we are using jest npm test # update major, minor or patch version npm version major # publish it -- should automatically be done using GH action once you push to master npm publish
- Login to github packages or add corresponding entries in your
.npmrc
file .npmrc
should include line(s) specifying github package URL(s) like:@nakamorg:registry=https://npm.pkg.github.com
- npm install @nakamorg/rei-node-package # or your package.json file
You can use nvm to install and manage multiple versions of node and npm. Install nvm
using instruction from their github repo. Afterwards, installing and managing node and npm is as easy as this
nvm install 16.0.0 # Install a specific version number
nvm use 16.0 # Use the latest available 8.0.x release
nvm install node # Install the latest available version
nvm use node # Use the latest version
jest testing framework is used for this rei (example) package. And, we encourage you to use the same for your packages and libraries.