|
| 1 | +# @simple-release/npm |
| 2 | + |
| 3 | +[![ESM-only package][package]][package-url] |
| 4 | +[![NPM version][npm]][npm-url] |
| 5 | +[![Node version][node]][node-url] |
| 6 | +[![Dependencies status][deps]][deps-url] |
| 7 | +[![Install size][size]][size-url] |
| 8 | +[![Build status][build]][build-url] |
| 9 | +[![Coverage status][coverage]][coverage-url] |
| 10 | + |
| 11 | +[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg |
| 12 | +[package-url]: https://nodejs.org/api/esm.html |
| 13 | + |
| 14 | +[npm]: https://img.shields.io/npm/v/@simple-release/npm.svg |
| 15 | +[npm-url]: https://www.npmjs.com/package/@simple-release/npm |
| 16 | + |
| 17 | +[node]: https://img.shields.io/node/v/@simple-release/npm.svg |
| 18 | +[node-url]: https://nodejs.org |
| 19 | + |
| 20 | +[deps]: https://img.shields.io/librariesio/release/npm/@simple-release/npm |
| 21 | +[deps-url]: https://libraries.io/npm/@simple-release%2Fcore/tree |
| 22 | + |
| 23 | +[size]: https://packagephobia.com/badge?p=@simple-release/npm |
| 24 | +[size-url]: https://packagephobia.com/result?p=@simple-release/npm |
| 25 | + |
| 26 | +[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/simple-release-tools/tests.yml?branch=main |
| 27 | +[build-url]: https://github.com/TrigenSoftware/simple-release-tools/actions |
| 28 | + |
| 29 | +[coverage]: https://coveralls.io/repos/github/TrigenSoftware/simple-release-tools/badge.svg?branch=main |
| 30 | +[coverage-url]: https://coveralls.io/github/TrigenSoftware/simple-release-tools?branch=main |
| 31 | + |
| 32 | +A npm addon for simple-release. |
| 33 | + |
| 34 | +## Install |
| 35 | + |
| 36 | +```bash |
| 37 | +# pnpm |
| 38 | +pnpm add @simple-release/npm |
| 39 | +# yarn |
| 40 | +yarn add @simple-release/npm |
| 41 | +# npm |
| 42 | +npm i @simple-release/npm |
| 43 | +``` |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +```js |
| 48 | +import { Releaser } from '@simple-release/core' |
| 49 | +import { NpmProject } from '@simple-release/npm' |
| 50 | + |
| 51 | +const project = new NpmProject() |
| 52 | + |
| 53 | +await new Releaser(project) |
| 54 | + .bump() |
| 55 | + .commit() |
| 56 | + .tag() |
| 57 | + .push() |
| 58 | + .publish() |
| 59 | + .run() |
| 60 | +``` |
| 61 | + |
| 62 | +Workspaces example: |
| 63 | + |
| 64 | +```js |
| 65 | +import { Releaser } from '@simple-release/core' |
| 66 | +import { NpmWorkspacesProject } from '@simple-release/npm' |
| 67 | + |
| 68 | +const project = new NpmWorkspacesProject({ |
| 69 | + mode: 'independent' |
| 70 | +}) |
| 71 | + |
| 72 | +await new Releaser(project) |
| 73 | + .bump() |
| 74 | + .commit() |
| 75 | + .tag() |
| 76 | + .push() |
| 77 | + .publish() |
| 78 | + .run() |
| 79 | +``` |
| 80 | + |
| 81 | +`NpmWorkspacesProject` will read workspaces from the `package.json` in the root of the project. |
| 82 | + |
| 83 | +## Options |
| 84 | + |
| 85 | +### NpmProject |
| 86 | + |
| 87 | +#### `path` |
| 88 | + |
| 89 | +Path to the `package.json` manifest file. Defaults to `'package.json'`. |
| 90 | + |
| 91 | +#### `changelogFile` |
| 92 | + |
| 93 | +Path to the changelog file. Defaults to `'CHANGELOG.md'`. |
| 94 | + |
| 95 | +#### `compose` |
| 96 | + |
| 97 | +Function to compose the main manifest with secondaries. It can be needed if you have some secondary manifests where version also should be updated. Optional. |
| 98 | + |
| 99 | +```js |
| 100 | +import { ComposedProjectManifest } from '@simple-release/core' |
| 101 | +import { NpmProject } from '@simple-release/npm' |
| 102 | + |
| 103 | +new NpmProject({ |
| 104 | + compose: main => new ComposedProjectManifest(main, [ |
| 105 | + new SomeManifest(/* ... */) |
| 106 | + ]) |
| 107 | +}) |
| 108 | +``` |
| 109 | + |
| 110 | +### NpmWorkspacesProject |
| 111 | + |
| 112 | +#### `mode` |
| 113 | + |
| 114 | +Mode to determine how to bump versions in the monorepo. Required. |
| 115 | + |
| 116 | +- `independent` - each package can have its own version. |
| 117 | +- `fixed` - all packages have the same version. |
| 118 | + |
| 119 | +#### `root` |
| 120 | + |
| 121 | +Path to the monorepo root. Defaults to the current working directory. |
| 122 | + |
| 123 | +#### `changelogFile` |
| 124 | + |
| 125 | +Path to the changelog file. Defaults to `'CHANGELOG.md'`. |
| 126 | + |
| 127 | +#### `compose` |
| 128 | + |
| 129 | +Function to compose the main manifest with secondaries. It can be needed if you have some secondary manifests where version also should be updated. Will be called for each manifest in monorepo. Optional. |
| 130 | + |
| 131 | +```js |
| 132 | +import { ComposedProjectManifest } from '@simple-release/core' |
| 133 | +import { NpmProject } from '@simple-release/npm' |
| 134 | + |
| 135 | +new NpmProject({ |
| 136 | + compose: (main, isRoot) => ( |
| 137 | + isRoot |
| 138 | + ? main |
| 139 | + : new ComposedProjectManifest(main, [ |
| 140 | + new SomeManifest(/* ... */) |
| 141 | + ]) |
| 142 | + ) |
| 143 | +}) |
| 144 | +``` |
| 145 | + |
| 146 | +#### `scope` |
| 147 | + |
| 148 | +Function to format scope name from the package name. By default, scope part of the package name will dropped (`@scope/pkg-name` -> `pkg-name`). |
| 149 | + |
| 150 | +#### `tagPrefix` |
| 151 | + |
| 152 | +Function to format tag prefix from scope name. By default, tag prefix will be the scope name with `@` sign (`pkg-name` -> `pkg-name@`) for independent mode and empty string for fixed mode. |
| 153 | + |
| 154 | +### publish |
| 155 | + |
| 156 | +Publish options for `NpmProject` and `NpmWorkspacesProject`. |
| 157 | + |
| 158 | +#### `access` |
| 159 | + |
| 160 | +Access level for the package. Optional. |
| 161 | + |
| 162 | +#### `tag` |
| 163 | + |
| 164 | +String or function to format tag name. Function accepts version string and prerelease versions. Optional. |
| 165 | + |
| 166 | +#### `otp` |
| 167 | + |
| 168 | +One-time password for publishing. Optional. |
| 169 | + |
| 170 | +#### `env` |
| 171 | + |
| 172 | +Environment variables to set before publishing. Defaults to `process.env`. |
0 commit comments