Skip to main content

Working with NPM

Publish NPM Package

  1. Configure your scope to use OneDev registry:

    $ npm config set @<scope>:registry<project path>/~npm/
    <scope>scope of your package
    <project path>path of a project with package management enabled
  2. Configure auth token of the registry:

    $ npm config set -- '//<project path>/~npm/:_authToken' "<onedev_access_token>"
    <project path>same as above
    <ondev_access_token>OneDev access token with package write permission over the project
  3. Publish the image:

    $ npm publish
  4. For CI/CD job, run below to publish package via command step:

    # Use @@ to reference scope in job commands to avoid being interpreted as variable
    npm config set @@<scope>:registry<project path>/~npm/

    # Use job token to tell OneDev the build publishing the package
    # Job secret 'access-token' should be defined in project build setting as an access token with package write permission
    npm config set -- '//<project path>/~npm/:_authToken' "@job_token@:@secret:access-token@"

    npm publish
    <scope>same as above
    <project path>same as above

Consume Published NPM Package

The package detail page contains instructions on how to consume published image.