• Stars
    star
    242
  • Rank 167,048 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🚒 semantic-release plugin to publish a npm package

@semantic-release/npm

semantic-release plugin to publish a npm package.

Build Status npm latest version npm next version npm beta version

Step Description
verifyConditions Verify the presence of the NPM_TOKEN environment variable, or an .npmrc file, and verify the authentication method is valid.
prepare Update the package.json version and create the npm package tarball.
addChannel Add a release to a dist-tag.
publish Publish the npm package to the registry.

Install

$ npm install @semantic-release/npm -D

Usage

The plugin can be configured in the semantic-release configuration file:

{
  "plugins": ["@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/npm"]
}

Configuration

npm registry authentication

The npm token authentication configuration is required and can be set via environment variables.

Automation tokens are recommended since they can be used for an automated workflow, even when your account is configured to use the auth-and-writes level of 2FA.

npm provenance

If you are publishing to the official registry and your pipeline is on a provider that is supported by npm for provenance, npm can be configured to publish with provenance.

Since semantic-release wraps the npm publish command, configuring provenance is not exposed directly. Instead, provenance can be configured through the other configuration options exposed by npm. Provenance applies specifically to publishing, so our recommendation is to configure under publishConfig within the package.json.

npm provenance on GitHub Actions

For package provenance to be signed on the GitHub Actions CI the following permission is required to be enabled on the job:

permissions:
  id-token: write # to enable use of OIDC for npm provenance

It's worth noting that if you are using semantic-release to its fullest with a GitHub release, GitHub comments, and other features, then more permissions are required to be enabled on this job:

permissions:
  contents: write # to be able to publish a GitHub release
  issues: write # to be able to comment on released issues
  pull-requests: write # to be able to comment on released pull requests
  id-token: write # to enable use of OIDC for npm provenance

Refer to the GitHub Actions recipe for npm package provenance for the full CI job's YAML code example.

Environment variables

Variable Description
NPM_TOKEN Npm token created via npm token create

Options

Options Description Default
npmPublish Whether to publish the npm package to the registry. If false the package.json version will still be updated. false if the package.json private property is true, true otherwise.
pkgRoot Directory path to publish. .
tarballDir Directory path in which to write the package tarball. If false the tarball is not be kept on the file system. false

Note: The pkgRoot directory must contain a package.json. The version will be updated only in the package.json and npm-shrinkwrap.json within the pkgRoot directory.

Note: If you use a shareable configuration that defines one of these options you can set it to false in your semantic-release configuration in order to use the default value.

npm configuration

The plugin uses the npm CLI which will read the configuration from .npmrc. See npm config for the option list.

The registry can be configured via the npm environment variable NPM_CONFIG_REGISTRY and will take precedence over the configuration in .npmrc.

The registry and dist-tag can be configured under publishConfig in the package.json:

{
  "publishConfig": {
    "registry": "https://registry.npmjs.org/",
    "tag": "latest"
  }
}

Notes:

  • The presence of an .npmrc file will override any specified environment variables.
  • The presence of registry or dist-tag under publishConfig in the package.json will take precedence over the configuration in .npmrc and NPM_CONFIG_REGISTRY

Examples

The npmPublish and tarballDir option can be used to skip the publishing to the npm registry and instead, release the package tarball with another plugin. For example with the @semantic-release/github plugin:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/npm",
      {
        "npmPublish": false,
        "tarballDir": "dist"
      }
    ],
    [
      "@semantic-release/github",
      {
        "assets": "dist/*.tgz"
      }
    ]
  ]
}

When publishing from a sub-directory with the pkgRoot option, the package.json and npm-shrinkwrap.json updated with the new version can be moved to another directory with a postversion. For example with the @semantic-release/git plugin:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/npm",
      {
        "pkgRoot": "dist"
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": ["package.json", "npm-shrinkwrap.json"]
      }
    ]
  ]
}
{
  "scripts": {
    "postversion": "cp -r package.json .. && cp -r npm-shrinkwrap.json .."
  }
}

More Repositories

1

semantic-release

πŸ“¦πŸš€ Fully automated version management and package publishing
JavaScript
18,874
star
2

github

:octocat: semantic-release plugin to publish a GitHub release and comment on released Pull Requests/Issues
JavaScript
401
star
3

commit-analyzer

πŸ’‘ semantic-release plugin to analyze commits with conventional-changelog
JavaScript
361
star
4

cli

πŸ†‘πŸ“ Setup automated semver compliant package publishing
JavaScript
359
star
5

release-notes-generator

πŸ“‹ semantic-release plugin to generate changelog content with conventional-changelog
JavaScript
306
star
6

changelog

πŸ“˜ semantic-release plugin to create or update a changelog file
JavaScript
253
star
7

git

πŸ”€ semantic-release plugin to commit release assets to the project's git repository
JavaScript
252
star
8

gitlab

🦊 semantic-release plugin to publish a GitLab release
JavaScript
233
star
9

env-ci

Get environment variables exposed by CI services
JavaScript
228
star
10

cracks

πŸ’’πŸ” breaking change detection
JavaScript
111
star
11

gitlab-config

🦊 Semantic-release shareable config for GitLab
JavaScript
39
star
12

travis-deploy-once

🚫Test multiple node versions on Travis. Deploy once. If all of them pass.
JavaScript
34
star
13

issue-parser

Parser for Github, GitLab and Bitbucket issues actions, references and mentions
JavaScript
22
star
14

release-notes-generator-v3

β›” This repository has been archived
JavaScript
11
star
15

twitter-together

Submit tweets for https://twitter.com/SemanticRelease using pull requests
11
star
16

condition-travis

🚫 semantic-release plugin to check Travis CI environment before publishing.
JavaScript
9
star
17

error

πŸ’₯ πŸ’¬ errors but with error code
JavaScript
9
star
18

evolution

Proposals for changes to semantic-release
8
star
19

apm-config

:atom: semantic-release shareable config to publish Atom packages with apm
JavaScript
7
star
20

wordpress

🐢 Semantic Release plugin for packaging up WordPress plugins / themes
TypeScript
7
star
21

commit-analyzer-v2

🚫 This repository has been archived
JavaScript
4
star
22

npm-registry-docker

🚒 CouchDB Docker image running npm-registry-couchapp
Shell
3
star
23

.github

Common configuration for the semantic-release organization
3
star
24

last-release-git-tag

🚫 Determine the version of the last release with git tags
JavaScript
2
star
25

last-release-npm

🚫 determine the version of the last release via the npm registry
JavaScript
2
star
26

condition-codeship

🚫 make sure the right builds on codeship get published
JavaScript
1
star
27

condition-nsp

JavaScript
1
star
28

semantic-release.github.io

Project Website
CSS
1
star
29

welcome

πŸ“¦πŸ€— Welcome to the semantic-release community
1
star