Skip to content

Publish NPM packages

The DTaaS monorepo contains several npm packages.

Default npm registry

The default registry for npm packages is npmjs. Public packages are published to npmjs.

GitHub Actions publish the library microservice (lib-ms.yml), the runner (runner.yml), the logger microservice (logger-ms.yml) and the @into-cps-association/dt-automation library (dt-automation.yml). Each workflow calls the reusable .github/workflows/publish-npm.yml workflow.

A package can also be published by hand:

1
2
3
4
5
npm login --registry="https://registry.npmjs.org"
cat ~/.npmrc  #shows the auth token for the registry
//registry.npmjs.org/:_authToken=xxxxxxxxxx
yarn publish --registry="https://registry.npmjs.org" \
  --no-git-tag-version --access public

At least one version of the runner package is published to this registry for each release of the DTaaS platform.

GitHub npm registry

The GitHub Actions of the project also publish the packages to the GitHub npm registry. Installing from this registry requires a personal access token from GitHub.

Private Registry

Setup private npm registry

Publishing to npmjs is public and cannot be undone, so set up a private npm registry for local development. A private registry lets you publish and unpublish packages freely.

Verdaccio is the recommended registry. The following commands create a working private npm registry for development.

1
2
3
4
5
6
docker run -d --name verdaccio -p 4873:4873 verdaccio/verdaccio
npm adduser --registry http://localhost:4873 #create a user on the verdaccio registry
npm set registry http://localhost:4873/
yarn config set registry "http://localhost:4873"
yarn login --registry "http://localhost:4873" #login with the credentials for yarn utility
npm login #login with the credentials for npm utility

Open http://localhost:4873 in a browser and log in with the user credentials to see the published packages.

Publish to private npm registry

To publish a package to the local registry, run:

1
2
3
4
yarn install
yarn build #the dist/ directory is needed for publishing step
yarn publish --no-git-tag-version #increments version in package.json, publishes to registry
yarn publish #increments version in package.json, publishes to registry and adds a git tag

The package version in package.json is updated accordingly. See the verdaccio docs for more information.

To unpublish a package, for example @into-cps-association/runner@0.0.2, run:

npm unpublish --registry http://localhost:4873/ \
  @into-cps-association/runner@0.0.2

To install or uninstall this utility for all users, run:

1
2
3
4
sudo npm install --registry http://localhost:4873 \
  -g @into-cps-association/runner
sudo npm list -g # should list @into-cps-association/runner in the packages
sudo npm remove --global @into-cps-association/runner

Use the packages

Packages in the private npm registry are used like regular packages installed from npmjs.

For example, to use the @into-cps-association/runner@0.0.2 package, run:

1
2
3
sudo npm install --registry http://localhost:4873 \
  -g @into-cps-association/runner
runner # launch the digital twin runner