1 | # @semantic-release/npm
|
2 |
|
3 | Set of [semantic-release](https://github.com/semantic-release/semantic-release) plugins for publishing to a [npm](https://www.npmjs.com/) registry.
|
4 |
|
5 | [![Travis](https://img.shields.io/travis/semantic-release/npm.svg)](https://travis-ci.org/semantic-release/npm)
|
6 | [![Codecov](https://img.shields.io/codecov/c/github/semantic-release/npm.svg)](https://codecov.io/gh/semantic-release/npm)
|
7 | [![Greenkeeper badge](https://badges.greenkeeper.io/semantic-release/npm.svg)](https://greenkeeper.io/)
|
8 |
|
9 | [![npm latest version](https://img.shields.io/npm/v/@semantic-release/npm/latest.svg)](https://www.npmjs.com/package/@semantic-release/npm)
|
10 | [![npm next version](https://img.shields.io/npm/v/@semantic-release/npm/next.svg)](https://www.npmjs.com/package/@semantic-release/npm)
|
11 |
|
12 | ## verifyConditions
|
13 |
|
14 | Verify the presence of the `NPM_TOKEN` environment variable, create or update the `.npmrc` file with the token and verify the token is valid.
|
15 |
|
16 | ## prepare
|
17 |
|
18 | Update the `package.json` version and [create](https://docs.npmjs.com/cli/pack) the `npm` package tarball.
|
19 |
|
20 | ## publish
|
21 | [Publish](https://docs.npmjs.com/cli/publish) to the `npm` registry.
|
22 |
|
23 | ## Configuration
|
24 |
|
25 | ### Npm registry authentication
|
26 |
|
27 | The `npm` authentication configuration is **required** and can be set via [environment variables](#environment-variables).
|
28 |
|
29 | Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and the legacy (`username`, `password` and `email`) authentication are supported. It is recommended to use the [token](https://docs.npmjs.com/getting-started/working_with_tokens) authentication. The legacy authentication is supported as the alternative npm registries [Artifactory](https://www.jfrog.com/open-source/#os-arti) and [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp) only supports that form of authentication at this point.
|
30 |
|
31 | **Note**: Only the `auth-only` [level of npm two-factor authentication](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) is supported, semantic-release will not work with the default `auth-and-writes` level.
|
32 |
|
33 | ### Environment variables
|
34 |
|
35 | | Variable | Description |
|
36 | | -------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
37 | | `NPM_TOKEN` | Npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) |
|
38 | | `NPM_USERNAME` | Npm username created via [npm adduser](https://docs.npmjs.com/cli/adduser) or on [npmjs.com](https://www.npmjs.com) |
|
39 | | `NPM_PASSWORD` | Password of the npm user. |
|
40 | | `NPM_EMAIL` | Email address associated with the npm user |
|
41 |
|
42 | Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD` and `NPM_EMAIL` for legacy authentication
|
43 |
|
44 | ### Options
|
45 |
|
46 | | Options | Description | Default |
|
47 | |--------------|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
|
48 | | `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](https://docs.npmjs.com/files/package.json#private) property is `true`, `true` otherwise. |
|
49 | | `pkgRoot` | Directory path to publish. | `.` |
|
50 | | `tarballDir` | Directory path in which to write the the package tarball. If `false` the tarball is not be kept on the file system. | `false` |
|
51 |
|
52 | **Note**: The `pkgRoot` directory must contains a `package.json`. The version will be updated only in the `package.json` and `npm-shrinkwrap.json` within the `pkgRoot` directory.
|
53 |
|
54 | **Note**: If you use a [shareable configuration](https://github.com/semantic-release/semantic-release/blob/caribou/docs/usage/shareable-configurations.md#shareable-configurations) that defines one of these options you can set it to `false` in your [**semantic-release** configuration](https://github.com/semantic-release/semantic-release/blob/caribou/docs/usage/configuration.md#configuration) in order to use the default value.
|
55 |
|
56 | ### Npm configuration
|
57 |
|
58 | The plugins are based on `npm` and will use the configuration from [`.npmrc`](https://docs.npmjs.com/files/npmrc). See [npm config](https://docs.npmjs.com/misc/config) for the option list.
|
59 |
|
60 | The [`registry`](https://docs.npmjs.com/misc/registry) and [`dist-tag`](https://docs.npmjs.com/cli/dist-tag) can be configured in the `package.json` and will take precedence over the configuration in `.npmrc`:
|
61 | ```json
|
62 | {
|
63 | "publishConfig": {
|
64 | "registry": "https://registry.npmjs.org/",
|
65 | "tag": "latest"
|
66 | }
|
67 | }
|
68 | ```
|
69 |
|
70 | ### Usage
|
71 |
|
72 | The plugins are used by default by [semantic-release](https://github.com/semantic-release/semantic-release) so no specific configuration is required to use them.
|
73 |
|
74 | Each individual plugin can be disabled, replaced or used with other plugins in the `package.json`:
|
75 |
|
76 | ```json
|
77 | {
|
78 | "release": {
|
79 | "verifyConditions": ["@semantic-release/npm", "verify-other-condition"],
|
80 | "prepare": ["@semantic-release/npm", "custom-prepare"],
|
81 | "publish": ["@semantic-release/npm", "custom-publish"]
|
82 | }
|
83 | }
|
84 | ```
|
85 |
|
86 | 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 [github](https://github.com/semantic-release/github) plugin:
|
87 |
|
88 | ```json
|
89 | {
|
90 | "release": {
|
91 | "verifyConditions": ["@semantic-release/npm", "@semantic-release/git", "@semantic-release/github"],
|
92 | "prepare": ["@semantic-release/npm"],
|
93 | "publish": ["@semantic-release/npm", "@semantic-release/github"],
|
94 | "npmPublish": false,
|
95 | "tarballDir": "dist",
|
96 | "assets": "dist/*.tgz"
|
97 | }
|
98 | }
|
99 | ```
|
100 |
|
101 | 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 `postpublish` [npm script](https://docs.npmjs.com/misc/scripts). For example with the [git](https://github.com/semantic-release/git) plugin:
|
102 |
|
103 | ```json
|
104 | {
|
105 | "release": {
|
106 | "verifyConditions": ["@semantic-release/npm", "@semantic-release/git"],
|
107 | "prepare": ["@semantic-release/npm", "@semantic-release/git"],
|
108 | "publish": ["@semantic-release/npm"],
|
109 | "pkgRoot": "dist",
|
110 | "assets": ["package.json", "npm-shrinkwrap.json"]
|
111 | },
|
112 | "scripts": {
|
113 | "postpublish": "cp -r dist/package.json . && cp -r dist/npm-shrinkwrap.json ."
|
114 | }
|
115 | }
|
116 | ```
|