Skip to content

Commit 61deec7

Browse files
committed
style: prettier
1 parent 0d198e8 commit 61deec7

25 files changed

+673
-656
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- uses: actions/checkout@v3
3535
- uses: actions/setup-node@v3
3636
with:
37-
node-version: 'lts/*'
37+
node-version: "lts/*"
3838
cache: npm
3939
- run: npm ci
4040
- name: Ensure dependencies are compatible with the version of node

README.md

Lines changed: 40 additions & 29 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

@@ -53,17 +50,17 @@ Both the [token](https://docs.npmjs.com/getting-started/working_with_tokens) and
5350
| `NPM_USERNAME` | Npm username created via [npm adduser](https://docs.npmjs.com/cli/adduser) or on [npmjs.com](https://www.npmjs.com) |
5451
| `NPM_PASSWORD` | Password of the npm user. |
5552
| `NPM_EMAIL` | Email address associated with the npm user |
56-
| `NPM_CONFIG_USERCONFIG` | Path to non-default .npmrc file |
53+
| `NPM_CONFIG_USERCONFIG` | Path to non-default .npmrc file |
5754

5855
Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD` and `NPM_EMAIL` for legacy authentication
5956

6057
### Options
6158

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` |
59+
| Options | Description | Default |
60+
| ------------ | ------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
61+
| `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. |
62+
| `pkgRoot` | Directory path to publish. | `.` |
63+
| `tarballDir` | Directory path in which to write the package tarball. If `false` the tarball is not be kept on the file system. | `false` |
6764

6865
**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.
6966

@@ -76,6 +73,7 @@ The plugin uses the [`npm` CLI](https://github.com/npm/cli) which will read the
7673
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`.
7774

7875
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`:
76+
7977
```json
8078
{
8179
"publishConfig": {
@@ -94,13 +92,19 @@ The `npmPublish` and `tarballDir` option can be used to skip the publishing to t
9492
"plugins": [
9593
"@semantic-release/commit-analyzer",
9694
"@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-
}]
95+
[
96+
"@semantic-release/npm",
97+
{
98+
"npmPublish": false,
99+
"tarballDir": "dist"
100+
}
101+
],
102+
[
103+
"@semantic-release/github",
104+
{
105+
"assets": "dist/*.tgz"
106+
}
107+
]
104108
]
105109
}
106110
```
@@ -112,15 +116,22 @@ When publishing from a sub-directory with the `pkgRoot` option, the `package.jso
112116
"plugins": [
113117
"@semantic-release/commit-analyzer",
114118
"@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-
}]
119+
[
120+
"@semantic-release/npm",
121+
{
122+
"pkgRoot": "dist"
123+
}
124+
],
125+
[
126+
"@semantic-release/git",
127+
{
128+
"assets": ["package.json", "npm-shrinkwrap.json"]
129+
}
130+
]
121131
]
122132
}
123133
```
134+
124135
```json
125136
{
126137
"scripts": {

index.js

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

1212
let verified;
1313
let prepared;
14-
const npmrc = temporaryFile({name: '.npmrc'});
14+
const npmrc = temporaryFile({ name: ".npmrc" });
1515

1616
export async function verifyConditions(pluginConfig, context) {
1717
// 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
1818
if (context.options.publish) {
1919
const publishPlugin =
20-
castArray(context.options.publish).find((config) => config.path && config.path === '@semantic-release/npm') || {};
20+
castArray(context.options.publish).find((config) => config.path && config.path === "@semantic-release/npm") || {};
2121

2222
pluginConfig.npmPublish = defaultTo(pluginConfig.npmPublish, publishPlugin.npmPublish);
2323
pluginConfig.tarballDir = defaultTo(pluginConfig.tarballDir, publishPlugin.tarballDir);

lib/add-channel.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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';
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-
export default async function (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 @@ export default async function (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,7 +37,7 @@ export default async function (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
);

lib/definitions/errors.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import {dirname, resolve} from 'node:path';
2-
import {fileURLToPath} from 'node:url';
3-
import {readPackageSync} from 'read-pkg';
1+
import { dirname, resolve } from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { readPackageSync } from "read-pkg";
44

55
const __dirname = dirname(fileURLToPath(import.meta.url));
6-
const pkg = readPackageSync({cwd: resolve(__dirname, '../../')});
7-
const [homepage] = pkg.homepage.split('#');
6+
const pkg = readPackageSync({ cwd: resolve(__dirname, "../../") });
7+
const [homepage] = pkg.homepage.split("#");
88
const linkify = (file) => `${homepage}/blob/master/${file}`;
99

1010
export function EINVALIDNPMPUBLISH({ npmPublish }) {
1111
return {
12-
message: 'Invalid `npmPublish` option.',
13-
details: `The [npmPublish option](${linkify('README.md#npmpublish')}) option, if defined, must be a \`Boolean\`.
12+
message: "Invalid `npmPublish` option.",
13+
details: `The [npmPublish option](${linkify("README.md#npmpublish")}) option, if defined, must be a \`Boolean\`.
1414
1515
Your configuration for the \`npmPublish\` option is \`${npmPublish}\`.`,
1616
};
1717
}
1818

1919
export function EINVALIDTARBALLDIR({ tarballDir }) {
2020
return {
21-
message: 'Invalid `tarballDir` option.',
22-
details: `The [tarballDir option](${linkify('README.md#tarballdir')}) option, if defined, must be a \`String\`.
21+
message: "Invalid `tarballDir` option.",
22+
details: `The [tarballDir option](${linkify("README.md#tarballdir")}) option, if defined, must be a \`String\`.
2323
2424
Your configuration for the \`tarballDir\` option is \`${tarballDir}\`.`,
2525
};
2626
}
2727

2828
export function EINVALIDPKGROOT({ pkgRoot }) {
2929
return {
30-
message: 'Invalid `pkgRoot` option.',
31-
details: `The [pkgRoot option](${linkify('README.md#pkgroot')}) option, if defined, must be a \`String\`.
30+
message: "Invalid `pkgRoot` option.",
31+
details: `The [pkgRoot option](${linkify("README.md#pkgroot")}) option, if defined, must be a \`String\`.
3232
3333
Your configuration for the \`pkgRoot\` option is \`${pkgRoot}\`.`,
3434
};
3535
}
3636

3737
export function ENONPMTOKEN({ registry }) {
3838
return {
39-
message: 'No npm token specified.',
39+
message: "No npm token specified.",
4040
details: `An [npm token](${linkify(
41-
'README.md#npm-registry-authentication'
41+
"README.md#npm-registry-authentication"
4242
)}) must be created and set in the \`NPM_TOKEN\` environment variable on your CI environment.
4343
4444
Please make sure to create an [npm token](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) and to set it in the \`NPM_TOKEN\` environment variable on your CI environment. The token must allow to publish to the registry \`${registry}\`.`,
@@ -47,9 +47,9 @@ Please make sure to create an [npm token](https://docs.npmjs.com/getting-started
4747

4848
export function EINVALIDNPMTOKEN({ registry }) {
4949
return {
50-
message: 'Invalid npm token.',
50+
message: "Invalid npm token.",
5151
details: `The [npm token](${linkify(
52-
'README.md#npm-registry-authentication'
52+
"README.md#npm-registry-authentication"
5353
)}) configured in the \`NPM_TOKEN\` environment variable must be a valid [token](https://docs.npmjs.com/getting-started/working_with_tokens) allowing to publish to the registry \`${registry}\`.
5454
5555
If you are using Two Factor Authentication for your account, set its level to ["Authorization only"](https://docs.npmjs.com/getting-started/using-two-factor-authentication#levels-of-authentication) in your account settings. **semantic-release** cannot publish with the default "
@@ -61,7 +61,7 @@ Please make sure to set the \`NPM_TOKEN\` environment variable in your CI with t
6161

6262
export function ENOPKGNAME() {
6363
return {
64-
message: 'Missing `name` property in `package.json`.',
64+
message: "Missing `name` property in `package.json`.",
6565
details: `The \`package.json\`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish a package to the npm registry.
6666
6767
Please make sure to add a valid \`name\` for your package in your \`package.json\`.`,
@@ -70,7 +70,7 @@ Please make sure to add a valid \`name\` for your package in your \`package.json
7070

7171
export function ENOPKG() {
7272
return {
73-
message: 'Missing `package.json` file.',
73+
message: "Missing `package.json` file.",
7474
details: `A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to release on npm.
7575
7676
Please follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid \`package.json\` file.`,

lib/get-channel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import semver from 'semver';
1+
import semver from "semver";
22

33
export default function (channel) {
4-
return channel ? (semver.validRange(channel) ? `release-${channel}` : channel) : 'latest';
4+
return channel ? (semver.validRange(channel) ? `release-${channel}` : channel) : "latest";
55
}

lib/get-error.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import SemanticReleaseError from '@semantic-release/error';
2-
import * as ERROR_DEFINITIONS from './definitions/errors.js';
1+
import SemanticReleaseError from "@semantic-release/error";
2+
import * as ERROR_DEFINITIONS from "./definitions/errors.js";
33

44
export default function (code, ctx = {}) {
5-
const {message, details} = ERROR_DEFINITIONS[code](ctx);
5+
const { message, details } = ERROR_DEFINITIONS[code](ctx);
66

77
return new SemanticReleaseError(message, code, details);
88
}

lib/get-pkg.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import path from 'path';
2-
import {readPackage} from 'read-pkg';
3-
import AggregateError from 'aggregate-error';
4-
import getError from './get-error.js';
1+
import path from "path";
2+
import { readPackage } from "read-pkg";
3+
import AggregateError from "aggregate-error";
4+
import getError from "./get-error.js";
55

6-
export default async function ({pkgRoot}, {cwd}) {
6+
export default async function ({ pkgRoot }, { cwd }) {
77
try {
8-
const pkg = await readPackage({cwd: pkgRoot ? path.resolve(cwd, String(pkgRoot)) : cwd});
8+
const pkg = await readPackage({ cwd: pkgRoot ? path.resolve(cwd, String(pkgRoot)) : cwd });
99

1010
if (!pkg.name) {
11-
throw getError('ENOPKGNAME');
11+
throw getError("ENOPKGNAME");
1212
}
1313

1414
return pkg;
1515
} catch (error) {
16-
if (error.code === 'ENOENT') {
17-
throw new AggregateError([getError('ENOPKG')]);
16+
if (error.code === "ENOENT") {
17+
throw new AggregateError([getError("ENOPKG")]);
1818
}
1919

2020
throw new AggregateError([error]);

lib/get-registry.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import path from 'path';
2-
import rc from 'rc';
3-
import getRegistryUrl from 'registry-auth-token/registry-url.js';
1+
import path from "path";
2+
import rc from "rc";
3+
import getRegistryUrl from "registry-auth-token/registry-url.js";
44

55
export default function ({ publishConfig: { registry } = {}, name }, { cwd, env }) {
6-
return registry ||
6+
return (
7+
registry ||
78
env.NPM_CONFIG_REGISTRY ||
89
getRegistryUrl(
9-
name.split('/')[0],
10+
name.split("/")[0],
1011
rc(
11-
'npm',
12-
{ registry: 'https://registry.npmjs.org/' },
13-
{ config: env.NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc') }
12+
"npm",
13+
{ registry: "https://registry.npmjs.org/" },
14+
{ config: env.NPM_CONFIG_USERCONFIG || path.resolve(cwd, ".npmrc") }
1415
)
15-
);
16+
)
17+
);
1618
}

0 commit comments

Comments
 (0)