Skip to content

Commit 410b73d

Browse files
authored
Merge pull request #581 from semantic-release/beta
2 parents 93f2f73 + fc6fd18 commit 410b73d

29 files changed

+11552
-19343
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# style: prettier (#437)
2+
a54c56cdc437d5a1bf4a2888a3d4dd03f58fbbf5

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ name: Release
66
- next
77
- beta
88
- "*.x"
9+
permissions:
10+
contents: read
911
jobs:
1012
release:
1113
name: release
1214
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
id-token: write
18+
issues: write
19+
pull-requests: write
1320
steps:
1421
- uses: actions/checkout@v3
1522
- uses: actions/setup-node@v3

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- 14.17
17-
- 16.0.0
18-
- 17.0.0
1916
- 18.0.0
17+
- 19
2018
os:
2119
- ubuntu-latest
2220
runs-on: "${{ matrix.os }}"
@@ -27,7 +25,7 @@ jobs:
2725
with:
2826
node-version: "${{ matrix.node-version }}"
2927
cache: npm
30-
- run: npm ci
28+
- run: npm clean-install
3129
- run: "npm run test:ci"
3230
test:
3331
runs-on: ubuntu-latest
@@ -36,7 +34,7 @@ jobs:
3634
- uses: actions/checkout@v3
3735
- uses: actions/setup-node@v3
3836
with:
39-
node-version: 'lts/*'
37+
node-version: "lts/*"
4038
cache: npm
4139
- run: npm ci
4240
- name: Ensure dependencies are compatible with the version of node

README.md

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
[![npm next version](https://img.shields.io/npm/v/@semantic-release/npm/next.svg)](https://www.npmjs.com/package/@semantic-release/npm)
77
[![npm beta version](https://img.shields.io/npm/v/@semantic-release/npm/beta.svg)](https://www.npmjs.com/package/@semantic-release/npm)
88

9-
| Step | Description |
10-
|--------------------|-------------|
9+
| Step | Description |
10+
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
1111
| `verifyConditions` | Verify the presence of the `NPM_TOKEN` environment variable, or an `.npmrc` file, and verify the authentication method is valid. |
12-
| `prepare` | Update the `package.json` version and [create](https://docs.npmjs.com/cli/pack) the npm package tarball. |
13-
| `addChannel` | [Add a release to a dist-tag](https://docs.npmjs.com/cli/dist-tag). |
14-
| `publish` | [Publish the npm package](https://docs.npmjs.com/cli/publish) to the registry. |
12+
| `prepare` | Update the `package.json` version and [create](https://docs.npmjs.com/cli/pack) the npm package tarball. |
13+
| `addChannel` | [Add a release to a dist-tag](https://docs.npmjs.com/cli/dist-tag). |
14+
| `publish` | [Publish the npm package](https://docs.npmjs.com/cli/publish) to the registry. |
1515

1616
## Install
1717

@@ -25,11 +25,7 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
2525

2626
```json
2727
{
28-
"plugins": [
29-
"@semantic-release/commit-analyzer",
30-
"@semantic-release/release-notes-generator",
31-
"@semantic-release/npm",
32-
]
28+
"plugins": ["@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/npm"]
3329
}
3430
```
3531

@@ -42,6 +38,7 @@ The npm authentication configuration is **required** and can be set via [environ
4238
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.
4339

4440
**Notes**:
41+
4542
- 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.
4643
- The presence of an `.npmrc` file will override any specified environment variables.
4744

@@ -50,20 +47,15 @@ Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and
5047
| Variable | Description |
5148
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
5249
| `NPM_TOKEN` | Npm token created via [npm token create](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) |
53-
| `NPM_USERNAME` | Npm username created via [npm adduser](https://docs.npmjs.com/cli/adduser) or on [npmjs.com](https://www.npmjs.com) |
54-
| `NPM_PASSWORD` | Password of the npm user. |
55-
| `NPM_EMAIL` | Email address associated with the npm user |
56-
| `NPM_CONFIG_USERCONFIG` | Path to non-default .npmrc file |
57-
58-
Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD` and `NPM_EMAIL` for legacy authentication
50+
| `NPM_CONFIG_USERCONFIG` | Path to non-default .npmrc file |
5951

6052
### Options
6153

62-
| Options | Description | Default |
63-
|--------------|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
64-
| `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. |
65-
| `pkgRoot` | Directory path to publish. | `.` |
66-
| `tarballDir` | Directory path in which to write the package tarball. If `false` the tarball is not be kept on the file system. | `false` |
54+
| Options | Description | Default |
55+
| ------------ | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
56+
| `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. |
57+
| `pkgRoot` | Directory path to publish. | `.` |
58+
| `tarballDir` | Directory path in which to write the package tarball. If `false` the tarball is not be kept on the file system. | `false` |
6759

6860
**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.
6961

@@ -76,6 +68,7 @@ The plugin uses the [`npm` CLI](https://github.com/npm/cli) which will read the
7668
The [`registry`](https://docs.npmjs.com/misc/registry) can be configured via the npm environment variable `NPM_CONFIG_REGISTRY` and will take precedence over the configuration in `.npmrc`.
7769

7870
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` and `NPM_CONFIG_REGISTRY`:
71+
7972
```json
8073
{
8174
"publishConfig": {
@@ -94,13 +87,19 @@ The `npmPublish` and `tarballDir` option can be used to skip the publishing to t
9487
"plugins": [
9588
"@semantic-release/commit-analyzer",
9689
"@semantic-release/release-notes-generator",
97-
["@semantic-release/npm", {
98-
"npmPublish": false,
99-
"tarballDir": "dist",
100-
}],
101-
["@semantic-release/github", {
102-
"assets": "dist/*.tgz"
103-
}]
90+
[
91+
"@semantic-release/npm",
92+
{
93+
"npmPublish": false,
94+
"tarballDir": "dist"
95+
}
96+
],
97+
[
98+
"@semantic-release/github",
99+
{
100+
"assets": "dist/*.tgz"
101+
}
102+
]
104103
]
105104
}
106105
```
@@ -112,15 +111,22 @@ When publishing from a sub-directory with the `pkgRoot` option, the `package.jso
112111
"plugins": [
113112
"@semantic-release/commit-analyzer",
114113
"@semantic-release/release-notes-generator",
115-
["@semantic-release/npm", {
116-
"pkgRoot": "dist",
117-
}],
118-
["@semantic-release/git", {
119-
"assets": ["package.json", "npm-shrinkwrap.json"]
120-
}]
114+
[
115+
"@semantic-release/npm",
116+
{
117+
"pkgRoot": "dist"
118+
}
119+
],
120+
[
121+
"@semantic-release/git",
122+
{
123+
"assets": ["package.json", "npm-shrinkwrap.json"]
124+
}
125+
]
121126
]
122127
}
123128
```
129+
124130
```json
125131
{
126132
"scripts": {

index.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
const {defaultTo, castArray} = require('lodash');
2-
const AggregateError = require('aggregate-error');
3-
const tempy = require('tempy');
4-
const setLegacyToken = require('./lib/set-legacy-token');
5-
const getPkg = require('./lib/get-pkg');
6-
const verifyNpmConfig = require('./lib/verify-config');
7-
const verifyNpmAuth = require('./lib/verify-auth');
8-
const addChannelNpm = require('./lib/add-channel');
9-
const prepareNpm = require('./lib/prepare');
10-
const publishNpm = require('./lib/publish');
1+
import { castArray, defaultTo } from "lodash-es";
2+
import AggregateError from "aggregate-error";
3+
import { temporaryFile } from "tempy";
4+
import getPkg from "./lib/get-pkg.js";
5+
import verifyNpmConfig from "./lib/verify-config.js";
6+
import verifyNpmAuth from "./lib/verify-auth.js";
7+
import addChannelNpm from "./lib/add-channel.js";
8+
import prepareNpm from "./lib/prepare.js";
9+
import publishNpm from "./lib/publish.js";
1110

1211
let verified;
1312
let prepared;
14-
const npmrc = tempy.file({name: '.npmrc'});
13+
const npmrc = temporaryFile({ name: ".npmrc" });
1514

16-
async function verifyConditions(pluginConfig, context) {
15+
export async function verifyConditions(pluginConfig, context) {
1716
// If the npm publish plugin is used and has `npmPublish`, `tarballDir` or `pkgRoot` configured, validate them now in order to prevent any release if the configuration is wrong
1817
if (context.options.publish) {
1918
const publishPlugin =
20-
castArray(context.options.publish).find((config) => config.path && config.path === '@semantic-release/npm') || {};
19+
castArray(context.options.publish).find((config) => config.path && config.path === "@semantic-release/npm") || {};
2120

2221
pluginConfig.npmPublish = defaultTo(pluginConfig.npmPublish, publishPlugin.npmPublish);
2322
pluginConfig.tarballDir = defaultTo(pluginConfig.tarballDir, publishPlugin.tarballDir);
@@ -26,8 +25,6 @@ async function verifyConditions(pluginConfig, context) {
2625

2726
const errors = verifyNpmConfig(pluginConfig);
2827

29-
setLegacyToken(context);
30-
3128
try {
3229
const pkg = await getPkg(pluginConfig, context);
3330

@@ -36,7 +33,7 @@ async function verifyConditions(pluginConfig, context) {
3633
await verifyNpmAuth(npmrc, pkg, context);
3734
}
3835
} catch (error) {
39-
errors.push(...error);
36+
errors.push(...error.errors);
4037
}
4138

4239
if (errors.length > 0) {
@@ -46,19 +43,17 @@ async function verifyConditions(pluginConfig, context) {
4643
verified = true;
4744
}
4845

49-
async function prepare(pluginConfig, context) {
46+
export async function prepare(pluginConfig, context) {
5047
const errors = verified ? [] : verifyNpmConfig(pluginConfig);
5148

52-
setLegacyToken(context);
53-
5449
try {
5550
// Reload package.json in case a previous external step updated it
5651
const pkg = await getPkg(pluginConfig, context);
5752
if (!verified && pluginConfig.npmPublish !== false && pkg.private !== true) {
5853
await verifyNpmAuth(npmrc, pkg, context);
5954
}
6055
} catch (error) {
61-
errors.push(...error);
56+
errors.push(...error.errors);
6257
}
6358

6459
if (errors.length > 0) {
@@ -69,20 +64,18 @@ async function prepare(pluginConfig, context) {
6964
prepared = true;
7065
}
7166

72-
async function publish(pluginConfig, context) {
67+
export async function publish(pluginConfig, context) {
7368
let pkg;
7469
const errors = verified ? [] : verifyNpmConfig(pluginConfig);
7570

76-
setLegacyToken(context);
77-
7871
try {
7972
// Reload package.json in case a previous external step updated it
8073
pkg = await getPkg(pluginConfig, context);
8174
if (!verified && pluginConfig.npmPublish !== false && pkg.private !== true) {
8275
await verifyNpmAuth(npmrc, pkg, context);
8376
}
8477
} catch (error) {
85-
errors.push(...error);
78+
errors.push(...error.errors);
8679
}
8780

8881
if (errors.length > 0) {
@@ -96,20 +89,18 @@ async function publish(pluginConfig, context) {
9689
return publishNpm(npmrc, pluginConfig, pkg, context);
9790
}
9891

99-
async function addChannel(pluginConfig, context) {
92+
export async function addChannel(pluginConfig, context) {
10093
let pkg;
10194
const errors = verified ? [] : verifyNpmConfig(pluginConfig);
10295

103-
setLegacyToken(context);
104-
10596
try {
10697
// Reload package.json in case a previous external step updated it
10798
pkg = await getPkg(pluginConfig, context);
10899
if (!verified && pluginConfig.npmPublish !== false && pkg.private !== true) {
109100
await verifyNpmAuth(npmrc, pkg, context);
110101
}
111102
} catch (error) {
112-
errors.push(...error);
103+
errors.push(...error.errors);
113104
}
114105

115106
if (errors.length > 0) {
@@ -118,5 +109,3 @@ async function addChannel(pluginConfig, context) {
118109

119110
return addChannelNpm(npmrc, pluginConfig, pkg, context);
120111
}
121-
122-
module.exports = {verifyConditions, prepare, publish, addChannel};

lib/add-channel.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const execa = require('execa');
2-
const getRegistry = require('./get-registry');
3-
const getChannel = require('./get-channel');
4-
const getReleaseInfo = require('./get-release-info');
1+
import { execa } from "execa";
2+
import getRegistry from "./get-registry.js";
3+
import getChannel from "./get-channel.js";
4+
import getReleaseInfo from "./get-release-info.js";
55

6-
module.exports = async (npmrc, {npmPublish}, pkg, context) => {
6+
export default async function (npmrc, { npmPublish }, pkg, context) {
77
const {
88
cwd,
99
env,
1010
stdout,
1111
stderr,
12-
nextRelease: {version, channel},
12+
nextRelease: { version, channel },
1313
logger,
1414
} = context;
1515

@@ -19,16 +19,16 @@ module.exports = async (npmrc, {npmPublish}, pkg, context) => {
1919

2020
logger.log(`Adding version ${version} to npm registry on dist-tag ${distTag}`);
2121
const result = execa(
22-
'npm',
23-
['dist-tag', 'add', `${pkg.name}@${version}`, distTag, '--userconfig', npmrc, '--registry', registry],
22+
"npm",
23+
["dist-tag", "add", `${pkg.name}@${version}`, distTag, "--userconfig", npmrc, "--registry", registry],
2424
{
2525
cwd,
2626
env,
2727
preferLocal: true,
2828
}
2929
);
30-
result.stdout.pipe(stdout, {end: false});
31-
result.stderr.pipe(stderr, {end: false});
30+
result.stdout.pipe(stdout, { end: false });
31+
result.stderr.pipe(stderr, { end: false });
3232
await result;
3333

3434
logger.log(`Added ${pkg.name}@${version} to dist-tag @${distTag} on ${registry}`);
@@ -37,10 +37,10 @@ module.exports = async (npmrc, {npmPublish}, pkg, context) => {
3737
}
3838

3939
logger.log(
40-
`Skip adding to npm channel as ${npmPublish === false ? 'npmPublish' : "package.json's private property"} is ${
40+
`Skip adding to npm channel as ${npmPublish === false ? "npmPublish" : "package.json's private property"} is ${
4141
npmPublish !== false
4242
}`
4343
);
4444

4545
return false;
46-
};
46+
}

0 commit comments

Comments
 (0)