A plugin for semantic-release to support publishing packages to npm with yarn@berry and later. Inspired by @suin's package of a similar name.
Some benefits to using this yarn@berry
plugin include being able to change the package.json
version without
publishing the package to npm and being able to publish to different registries - including Azure DevOps by using
npmAuthIdent instead of npmAuthToken.
Step | Description |
---|---|
verifyConditions |
Verify the presence of the NPM_TOKEN environment variable and verify the authentication method is valid. |
prepare |
Update the package.json version and create the npm package tarball. |
publish |
Publish the npm package to the registry. |
$ yarn add -D @dmeents/semantic-release-yarn
Start by adding the plugin to the semantic-release configuration file:
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@dmeents/semantic-release-yarn"
]
}
Variable | Required (one of) | Description |
---|---|---|
NPM_TOKEN | ✅ | Required if the option useNpmToken is set to true. The npm token to use to publish to the registry. It must be created using two-factor authentication auth-only because semantic-release won't work with anything else |
NPM_AUTH_IDENT | ✅ | Required if the option useNpmAuthIdent is set to true. The npm token to use to publish to the registry. This is helpful if working with AzureDevOps for example where there is no npmAuthToken |
Packages will be published to the registry specified in the package.json file first, then fall back to the .yarnrc.yml file. If you're using semantic-release-yarn with a monorepo configuration, like semantic-release-monorepo, you must specify the registry in each packages package.json file.
Your repository must be using
yarn@berry
and have a.yarnrc.yml
file.
Option | Required | Default | Description |
---|---|---|---|
npmPublish | ❌ | true | Should the package be published to the registry provided in the package.json file. |
tarballDir | ❌ | . | The location and filename of where to output the tarball generated by Yarn. As an example, this can be used to include the tarball in the @semantic-release/github plugin. |
changeVersion | ❌ | true | Determines if the plugin should update the package.json file as part of the Prepare step. |
useNpmToken | ❌ | true | Determines if the plugin should use the NPM_TOKEN environment variable |
useNpmAuthIdent | ❌ | false | Determines if the plugin should use the NPM_AUTH_IDENT environment variable |
In this example we are using this plugin to simply generate the tarball with npm and releasing it with GitHub. We are
also not allowing the plugin to update the version in the package.json
.
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@dmeents/semantic-release-yarn",
{
"npmPublish": false,
"changeVersion": false,
"tarballDir": "dist"
}
],
[
"@semantic-release/github",
{
"assets": "dist/*.tgz"
}
]
]
}
When wanting to publish to a registry that requires npmAuthIdent
, for example to a private Azure DevOps feed, you need
to tell the plugin to useNpmAuthIdent
.
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@dmeents/semantic-release-yarn",
{
"npmPublish": true,
"useNpmToken": false,
"useNpmAuthIdent": true
}
]
]
}