Skip to content

NPM package development

Luis Beu edited this page Aug 27, 2023 · 1 revision

Public NPM packages

Workflow

  1. Create a new branch.
  2. Code the feature.
  3. Make sure to update the version and the changelog.
  4. Push the feature branch.
  5. Check all qa checks and comments.
  6. Test the package with the GitHub registry where the feature versions are stored. See Using the GitHub package registry for feature testing.
  7. Merge.
  8. Test the package with the next dist tag. See Usage of dist-tag with npm
  9. Create a release.

Using the GitHub package registry for feature testing

GitHub actions will publish a 'feature' version of every created pull request to the GitHub package registry. This is done to enable full and easy testing for inside docker containers and alike.

To enable this you need to follow NPM registry authenticating-with-a-personal-access-token.

You can add a function in your .bashrc to easily switch between the default npm registry and the GitHub one:

npmDev(){ echo "Using develop registry"; npm config set @beuluis:registry https://npm.pkg.github.com; npm "$@"; npm config set @beuluis:registry http://registry.npmjs.org }

This script will temporary alter the npm registry for @beuluis scoped packages.

To install a 'feature' version of a package during development you can run this command:

npmDev i @beuluis/{packageName}@{featureBranch}

Usage of dist-tag with npm

https://docs.npmjs.com/cli/v9/commands/npm-dist-tag

To make use of other tags as latest just use:

npm i @beuluis@{distTag}

Creating a release

  1. Go on the release page of the repository and click Draft a new release.
  2. Click on Choose a tag and input the version you specified in the package.json.
  3. Click Create new tag: *.
  4. Click on Generate release notes.
  5. Make changes if needed.
  6. Publish release.