Skip to content

Commit d392c82

Browse files
prisiscursoragent
andauthored
docs: add or update JSDoc comments (#172)
Co-authored-by: d.bannert <[email protected]> Co-authored-by: Cursor Agent <[email protected]>
1 parent c0e51bc commit d392c82

File tree

22 files changed

+360
-2
lines changed

22 files changed

+360
-2
lines changed

packages/rc/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ const getConfigFiles = (name: string, home: string, internalCwd: string, stopAt?
166166
return [...configFiles];
167167
};
168168

169+
/**
170+
* Aggregates configuration from multiple sources (defaults, configuration files, and environment variables)
171+
* into a single object, following the same resolution logic as the original `rc` npm package.
172+
*
173+
* The resolution order is (highest precedence last):
174+
* 1. `options.defaults` – default values supplied by the caller
175+
* 2. Configuration files discovered by {@link getConfigFiles}
176+
* 3. Environment variables that start with `${name}_` (nested via `__`)
177+
*
178+
* The function also returns the list of configuration file paths that were read while resolving the
179+
* configuration. No mutation is performed on any of the discovered files – they are only read.
180+
*
181+
* @param {string} name The base name of the application (used to derive env-var prefix and file names).
182+
* @param {object} [options] Optional behaviour switches.
183+
* @param {string} [options.config] Explicit path to a configuration file that should be merged last.
184+
* @param {string} [options.cwd] Working directory to start searching for local configuration files.
185+
* @param {object} [options.defaults] Default configuration values that act as the lowest precedence.
186+
* @param {string} [options.home] Home directory to look for user-level configuration files. Defaults to the current user home directory.
187+
* @param {string} [options.stopAt] Absolute path that acts as a boundary when traversing up the directory tree.
188+
*
189+
* @returns {{ config: Record<string, any>, files: string[] }}
190+
* An object containing the final merged `config` and the ordered list of `files` that were considered.
191+
*/
169192
// eslint-disable-next-line import/prefer-default-export
170193
export const rc = (
171194
name: string,

packages/semantic-release-clean-package-json/src/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ import type { CommonContext, PublishContext } from "./definitions/context";
99
import type { PluginConfig } from "./definitions/plugin-config";
1010
import getPackage from "./utils/get-pkg";
1111

12-
// eslint-disable-next-line sonarjs/cognitive-complexity
12+
/**
13+
* Clean the `package.json` that will be published by removing properties that are not relevant for the
14+
* published artifact. All properties defined in `defaultKeepProperties` plus any properties provided
15+
* via the `pluginConfig.keep` option are preserved. The original `package.json` is backed-up to
16+
* `package.json.back` before the clean-up starts so that it can be restored later in the `success`
17+
* step.
18+
*
19+
* @param {PluginConfig} pluginConfig Configuration object passed to the plugin.
20+
* @param {PublishContext} context Semantic-release publish context.
21+
*
22+
* @returns {Promise<void>} Resolves once the cleaned `package.json` has been written to disk.
23+
*/
1324
export const publish = async (pluginConfig: PluginConfig, context: PublishContext): Promise<void> => {
1425
const packageJson = await getPackage(pluginConfig, context);
1526
const cwd = pluginConfig.pkgRoot ? resolve(context.cwd, pluginConfig.pkgRoot) : context.cwd;
@@ -61,6 +72,16 @@ export const publish = async (pluginConfig: PluginConfig, context: PublishContex
6172
});
6273
};
6374

75+
/**
76+
* Restore the original `package.json` after a successful release. The backed-up version is read from
77+
* `package.json.back`, its version is replaced with the version that was just released and finally it
78+
* is written back to `package.json` (overwriting the temporary, cleaned version).
79+
*
80+
* @param {PluginConfig} pluginConfig Configuration object passed to the plugin.
81+
* @param {CommonContext} context Semantic-release success context.
82+
*
83+
* @returns {Promise<void>} Resolves once the original `package.json` has been restored.
84+
*/
6485
export const success = async (pluginConfig: PluginConfig, context: CommonContext): Promise<void> => {
6586
const cwd = pluginConfig.pkgRoot ? resolve(context.cwd, pluginConfig.pkgRoot) : context.cwd;
6687

packages/semantic-release-clean-package-json/src/utils/get-error.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import SemanticReleaseError from "@semantic-release/error";
33
import type { ErrorContext, ErrorDefinition } from "../definitions/errors";
44
import { errors } from "../definitions/errors";
55

6+
/**
7+
* Create a typed {@link SemanticReleaseError} instance from the predefined error catalogue.
8+
*
9+
* @typeParam T - A key of the {@link errors} map.
10+
*
11+
* @param {T} code Error code referencing the entry inside {@link errors}.
12+
* @param {ErrorContext} [context={}] Additional interpolation values used by the error factory.
13+
*
14+
* @returns {SemanticReleaseError} Fully initialised semantic-release error.
15+
*/
616
export default <T extends keyof typeof errors>(code: T, context: ErrorContext = {}): SemanticReleaseError => {
717
// eslint-disable-next-line security/detect-object-injection
818
const { details, message }: { details?: string; message: string } = (errors[code] as ErrorDefinition)(context);

packages/semantic-release-clean-package-json/src/utils/get-pkg.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import type { PackageJson } from "type-fest";
88
import type { CommonContext } from "../definitions/context";
99
import getError from "./get-error";
1010

11+
/**
12+
* Locate the closest `package.json` starting from the provided directory and return its parsed
13+
* contents together with the absolute file path.
14+
*
15+
* @private
16+
*
17+
* @param {string | URL | undefined} [cwd] Directory to start searching in. When omitted the current
18+
* working directory is used.
19+
*
20+
* @returns {Promise<{packageJson: PackageJson; path: string}>} Resolves with the parsed JSON object
21+
* and its path or rejects with {@link NotFoundError} if no file could be found.
22+
*/
1123
const findPackageJson = async (
1224
cwd?: URL | string,
1325
): Promise<{
@@ -34,6 +46,17 @@ const findPackageJson = async (
3446
};
3547
};
3648

49+
/**
50+
* Read and validate the `package.json` file for the current project (or a sub-path defined via
51+
* `pkgRoot`). A semantic-release compatible {@link AggregateError} is thrown when either the file is
52+
* missing or it does not contain a `name` field.
53+
*
54+
* @param {{ pkgRoot?: string }} options Plugin options containing an optional `pkgRoot` that
55+
* points to the publish sub-directory.
56+
* @param {{ cwd: string }} context Semantic-release context providing the base cwd.
57+
*
58+
* @returns {Promise<PackageJson>} The parsed package.json object.
59+
*/
3760
export default async (
3861
{
3962
pkgRoot,

packages/semantic-release-pnpm/src/add-channel.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import type { ReleaseInfo } from "./utils/get-release-info";
1010
import { getReleaseInfo } from "./utils/get-release-info";
1111
import { reasonToNotPublish, shouldPublish } from "./utils/should-publish";
1212

13+
/**
14+
* After a successful publish this step adds the newly released version to another npm distribution
15+
* tag (also known as a "channel") using `pnpm dist-tag add`.
16+
*
17+
* Typical use-case: publish a version on `next` first and, after manual verification, promote the
18+
* same version to the `latest` channel in a follow-up release.
19+
*
20+
* @param {PluginConfig} pluginConfig – Plugin configuration object.
21+
* @param {PackageJson} packageJson – The package manifest that has just been published.
22+
* @param {AddChannelContext} context – Semantic-release addChannel context.
23+
*
24+
* @returns {Promise<ReleaseInfo | false>} A release info object when the dist-tag was added or
25+
* `false` when the operation was skipped.
26+
*/
1327
export default async (pluginConfig: PluginConfig, packageJson: PackageJson, context: AddChannelContext): Promise<ReleaseInfo | false> => {
1428
const {
1529
cwd,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1+
/**
2+
* Public npm registry used as default when no custom registry is configured via `package.json`,
3+
* environment variables or `.npmrc`.
4+
*
5+
* @see https://registry.npmjs.org/
6+
*/
17
// eslint-disable-next-line import/prefer-default-export
28
export const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org/";

packages/semantic-release-pnpm/src/definitions/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import packageJson from "../../package.json";
22

3+
/**
4+
* Build an absolute URL to a file within the repository based on the `homepage` field of the plugin
5+
* package.json (which points to the GitHub repository).
6+
*
7+
* @param {string} file – Relative path within the repository.
8+
*
9+
* @returns {string} GitHub URL to the requested file on the `main` branch.
10+
*/
311
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
412
const linkify = (file: string) => packageJson.homepage + "/blob/main/" + file;
513

packages/semantic-release-pnpm/src/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ const PLUGIN_NAME = "semantic-release-pnpm";
1212
let verified: boolean;
1313
let prepared: boolean;
1414

15+
/**
16+
* Verify that the environment and plugin configuration are ready for a semantic-release run. This
17+
* step is executed during the `verifyConditions` phase.
18+
*
19+
* The function delegates the heavy lifting to the local `verify` helper and caches the verification
20+
* result so that subsequent life-cycle steps can skip running the checks again.
21+
*
22+
* @param {PluginConfig} pluginConfig Plugin configuration object.
23+
* @param {VerifyConditionsContext} context Semantic-release provided context.
24+
*
25+
* @returns {Promise<void>} Resolves once verification has finished.
26+
*/
1527
export const verifyConditions = async (pluginConfig: PluginConfig, context: VerifyConditionsContext): Promise<void> => {
1628
/**
1729
* If the plugin is used and has `npmPublish`, `tarballDir` or
@@ -40,6 +52,15 @@ export const verifyConditions = async (pluginConfig: PluginConfig, context: Veri
4052
verified = true;
4153
};
4254

55+
/**
56+
* Prepare the package for publication. On success the information is cached so that it is not
57+
* executed again during `publish` when running the single-package plugin flow.
58+
*
59+
* @param {PluginConfig} pluginConfig Plugin configuration object.
60+
* @param {PrepareContext} context Semantic-release provided context.
61+
*
62+
* @returns {Promise<void>} Resolves when preparation steps have completed.
63+
*/
4364
export const prepare = async (pluginConfig: PluginConfig, context: PrepareContext): Promise<void> => {
4465
if (!verified) {
4566
await verify(pluginConfig, context);
@@ -50,6 +71,16 @@ export const prepare = async (pluginConfig: PluginConfig, context: PrepareContex
5071
prepared = true;
5172
};
5273

74+
/**
75+
* Publish the package to the npm registry using `pnpm publish` if the plugin decides that the package
76+
* should indeed be published.
77+
*
78+
* @param {PluginConfig} pluginConfig Plugin configuration object.
79+
* @param {PublishContext} context Semantic-release provided context containing the upcoming release.
80+
*
81+
* @returns {Promise<ReleaseInfo | false>} Information about the published release or `false` when the
82+
* package was not published.
83+
*/
5384
export const publish = async (pluginConfig: PluginConfig, context: PublishContext): Promise<ReleaseInfo | false> => {
5485
const packageJson = await getPackage(pluginConfig, context);
5586

@@ -64,6 +95,16 @@ export const publish = async (pluginConfig: PluginConfig, context: PublishContex
6495
return await publishNpm(pluginConfig, packageJson, context);
6596
};
6697

98+
/**
99+
* Add the freshly published version to an additional npm distribution tag ("channel"). This step is
100+
* executed in the `addChannel` lifecycle phase.
101+
*
102+
* @param {PluginConfig} pluginConfig Plugin configuration object.
103+
* @param {AddChannelContext} context Semantic-release provided context containing the upcoming release.
104+
*
105+
* @returns {Promise<ReleaseInfo | false>} Information about the operation or `false` when nothing was
106+
* done.
107+
*/
67108
export const addChannel = async (pluginConfig: PluginConfig, context: AddChannelContext): Promise<ReleaseInfo | false> => {
68109
if (!verified) {
69110
await verify(pluginConfig, context);

packages/semantic-release-pnpm/src/prepare.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ import { execa } from "execa";
55
import type { PrepareContext } from "./definitions/context";
66
import type { PluginConfig } from "./definitions/plugin-config";
77

8+
/**
9+
* Prepare the package for publishing by
10+
* 1. writing the upcoming semantic-release version to the `package.json` with `pnpm version` (without
11+
* creating a git tag) and
12+
* 2. optionally creating a tarball via `pnpm pack` which is moved to the configured `tarballDir`.
13+
*
14+
* The function mirrors the behaviour of the official semantic-release `@semantic-release/npm` plugin
15+
* while using the `pnpm` CLI instead of `npm`.
16+
*
17+
* @param {PluginConfig} pluginConfig – Plugin configuration. Only `pkgRoot` and `tarballDir` are
18+
* relevant for this function.
19+
* @param {PrepareContext} context – Semantic-release prepare context containing IO streams,
20+
* logger, environment variables and release information.
21+
*
22+
* @returns {Promise<void>} A promise that resolves once the version has been written and the optional
23+
* tarball has been created (and moved).
24+
*/
825
export default async ({ pkgRoot, tarballDir }: PluginConfig, { cwd, env, logger, nextRelease: { version }, stderr, stdout }: PrepareContext): Promise<void> => {
926
const basePath = pkgRoot ? resolve(cwd, pkgRoot) : cwd;
1027

packages/semantic-release-pnpm/src/publish.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ import type { ReleaseInfo } from "./utils/get-release-info";
1010
import { getReleaseInfo } from "./utils/get-release-info";
1111
import { reasonToNotPublish, shouldPublish } from "./utils/should-publish";
1212

13+
/**
14+
* Publish the package to the npm registry using `pnpm publish` when the plugin configuration and
15+
* package manifest indicate that publishing should occur.
16+
*
17+
* The function calculates the correct distribution tag, resolves the registry URL, ensures the
18+
* package manager operates in the correct `pkgRoot` (if any) and finally executes the `pnpm` CLI.
19+
* It mirrors the behaviour of the official `@semantic-release/npm` plugin but utilises the `pnpm`
20+
* ecosystem.
21+
*
22+
* @param {PluginConfig} pluginConfig – Plugin configuration for the semantic-release run.
23+
* @param {PackageJson} packageJson – Parsed `package.json` of the project.
24+
* @param {PublishContext} context – Semantic-release publish context.
25+
*
26+
* @returns {Promise<ReleaseInfo | false>} Information about the published release (name, channel,
27+
* url) or `false` if the package was not published for any
28+
* reason (e.g. `npmPublish: false`).
29+
*/
1330
export default async (pluginConfig: PluginConfig, packageJson: PackageJson, context: PublishContext): Promise<ReleaseInfo | false> => {
1431
const {
1532
cwd,

0 commit comments

Comments
 (0)