UNPKG

20.7 kBTypeScriptView Raw
1declare interface AggregateError extends Error {
2 errors: any[];
3}
4
5declare module "semantic-release" {
6 import { Signale } from "signale";
7 export interface EnvCi {
8 /**
9 * Boolean, true if the environment is a CI environment
10 */
11 isCi: boolean;
12
13 /**
14 * Commit hash
15 */
16 commit: string;
17
18 /**
19 * Current branch name
20 */
21 branch: string;
22 }
23
24 /**
25 * Base context used in every semantic release step.
26 */
27 export interface BaseContext {
28 /**
29 * stdout for semantic-release process
30 */
31 stdout: NodeJS.WriteStream;
32
33 /**
34 * stderr for semantic-release process
35 */
36 stderr: NodeJS.WriteStream;
37
38 /**
39 * Signale console loger instance.
40 *
41 * Has error, log, warn and success methods.
42 */
43 logger: Signale<"error" | "log" | "success" | "warn">;
44 }
45
46 /**
47 * Context used for the verify conditions step.
48 */
49 export interface VerifyConditionsContext extends BaseContext {
50 /**
51 * The current working directory to use. It should be configured to
52 * the root of the Git repository to release from.
53 *
54 * It allows to run semantic-release from a specific path without
55 * having to change the local process cwd with process.chdir().
56 *
57 * @default process.cwd
58 */
59 cwd?: string | undefined;
60
61 /**
62 * The environment variables to use.
63 *
64 * It allows to run semantic-release with specific environment
65 * variables without having to modify the local process.env.
66 *
67 * @default process.env
68 */
69 env: Record<string, string>;
70
71 /**
72 * Information about the CI environment.
73 */
74 envCi: EnvCi;
75
76 /**
77 * Information of the current branch
78 */
79 branch: BranchObject;
80
81 /**
82 * Information on branches
83 */
84 branches: ReadonlyArray<BranchObject>;
85 }
86
87 /**
88 * Context used for the analyze commits step.
89 */
90 export interface AnalyzeCommitsContext extends VerifyConditionsContext {
91 /**
92 * List of commits taken into account when determining the new version.
93 */
94 commits: ReadonlyArray<Commit>;
95
96 /**
97 * List of releases
98 */
99 releases: ReadonlyArray<Release>;
100
101 /**
102 * Last release
103 */
104 lastRelease: LastRelease;
105 }
106
107 /**
108 * Context used for the verify release step.
109 */
110 export interface VerifyReleaseContext extends AnalyzeCommitsContext {
111 /**
112 * The next release.
113 */
114 nextRelease: NextRelease;
115 }
116
117 /**
118 * Context used for the generate notes step.
119 */
120 export type GenerateNotesContext = VerifyReleaseContext;
121
122 /**
123 * Context used for the add channel step.
124 */
125 export type AddChannelContext = VerifyReleaseContext;
126
127 /**
128 * Context used for the prepare step.
129 */
130 export type PrepareContext = VerifyReleaseContext;
131
132 /**
133 * Context used for the publish step.
134 */
135 export type PublishContext = VerifyReleaseContext;
136
137 /**
138 * Context used for the success step.
139 */
140 export type SuccessContext = VerifyReleaseContext;
141
142 export interface FailContext extends BaseContext {
143 /**
144 * Errors that occurred during the release process.
145 */
146 errors: AggregateError;
147 }
148
149 export interface Commit {
150 /**
151 * The commit abbreviated and full hash.
152 */
153 commit: {
154 /**
155 * The commit hash.
156 */
157 long: string;
158
159 /**
160 * The commit abbreviated hash.
161 */
162 short: string;
163 };
164
165 /**
166 * The commit abbreviated and full tree hash.
167 */
168 tree: {
169 /**
170 * The commit tree hash.
171 */
172 long: string;
173
174 /**
175 * The commit abbreviated tree hash.
176 */
177 short: string;
178 };
179
180 /**
181 * The commit author information.
182 */
183 author: {
184 /**
185 * The commit author name.
186 */
187 name: string;
188
189 /**
190 * The commit author email.
191 */
192 email: string;
193
194 /**
195 * The commit author date.
196 */
197 short: string;
198 };
199
200 /**
201 * The committer information.
202 */
203 committer: {
204 /**
205 * The committer name.
206 */
207 name: string;
208
209 /**
210 * The committer email.
211 */
212 email: string;
213
214 /**
215 * The committer date.
216 */
217 short: string;
218 };
219
220 /**
221 * The commit subject.
222 */
223 subject: string;
224
225 /**
226 * The commit body.
227 */
228 body: string;
229
230 /**
231 * The commit full message (subject and body).
232 */
233 message: string;
234
235 /**
236 * The commit hash.
237 */
238 hash: string;
239
240 /**
241 * The committer date.
242 */
243 committerDate: string;
244 }
245
246 export interface BranchObject {
247 /**
248 * The name of git branch.
249 *
250 * A `name` is required for all types of branch. It can be defined as a
251 * [glob](https://github.com/micromatch/micromatch#matching-features)
252 * in which case the definition will be expanded to one per matching
253 * branch existing in the repository.
254 *
255 * If `name` doesn't match any branch existing in the repository, the
256 * definition will be ignored. For example, the default configuration
257 * includes the definition `next` and `next-major` which will become
258 * active only when the branches `next` and/or `next-major` are
259 * created in the repository.
260 */
261 name: string;
262
263 /**
264 * The distribution channel on which to publish releases from this
265 * branch.
266 *
267 * If this field is set to `false`, then the branch will be released
268 * on the default distribution channel (for example the `@latest`
269 * [dist-tag](https://docs.npmjs.com/cli/dist-tag) for npm). This is
270 * also the default behavior for the first
271 * [release branch](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#release-branches)
272 * if the channel property is not set.
273 *
274 * For all other branches, if the channel property is not set, then the
275 * channel name will be the same as the branch name.
276 *
277 * The value of `channel`, if defined as a string, is generated with
278 * [Lodash template](https://lodash.com/docs#template) with the
279 * variable `name` set to the branch name.
280 *
281 * For example `{name: 'next', channel: 'channel-${name}'}` will be
282 * expanded to `{name: 'next', channel: 'channel-next'}`.
283 */
284 channel?: string | false | undefined;
285
286 /**
287 * The range of [semantic versions](https://semver.org/) to support on
288 * this branch.
289 *
290 * A `range` only applies to maintenance branches and must be formatted
291 * like `N.N.x` or `N.x` (`N` is a number). If no range is specified
292 * but the `name` is formatted as a range, then the branch will be
293 * considered a maintenance branch and the `name` value will be used
294 * for the `range`.
295 *
296 * Required for maintenance branches, unless `name` is formatted like
297 * `N.N.x` or `N.x` (`N` is a number).
298 */
299 range?: string | undefined;
300
301 /**
302 * The pre-release identifier to append to [semantic versions](https://semver.org/)
303 * released from this branch.
304 *
305 * A `prerelease` property applies only to pre-release branches and
306 * the `prerelease` value must be valid per the [Semantic Versioning
307 * Specification](https://semver.org/#spec-item-9). It will determine
308 * the name of versions. For example if `prerelease` is set to
309 * `"beta"`, the version will be formatted like `2.0.0-beta.1`,
310 * `2.0.0-beta.2`, etc.
311 *
312 * The value of `prerelease`, if defined as a string, is generated with
313 * [Lodash template](https://lodash.com/docs#template) with the
314 * variable `name` set to the name of the branch.
315 *
316 * If the `prerelease property is set to `true` then the name of the
317 * branch is used as the pre-release identifier.
318 *
319 * Required for pre-release branches.
320 */
321 prerelease?: string | boolean | undefined;
322 }
323
324 /**
325 * Specifies a git branch holding commits to analyze and code to release.
326 *
327 * Each branch may be defined either by a string or an object. Specifying
328 * a string is a shortcut for specifying that string as the `name` field,
329 * for example `"master"` expands to `{name: "master"}`.
330 */
331 export type BranchSpec = string | BranchObject;
332
333 /**
334 * A semver release type.
335 * See https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-types.js
336 */
337 export type ReleaseType = "prerelease" | "prepatch" | "patch" | "preminor" | "minor" | "premajor" | "major";
338
339 /**
340 * Details of a release published by a publish plugin.
341 */
342 export interface Release {
343 /**
344 * The release name, only if set by the corresponding publish plugin.
345 */
346 name?: string | undefined;
347
348 /**
349 * The release URL, only if set by the corresponding publish plugin.
350 */
351 url?: string | undefined;
352
353 /**
354 * The semver export type of the release.
355 */
356 type: ReleaseType;
357
358 /**
359 * The version of the release.
360 */
361 version: string;
362
363 /**
364 * The sha of the last commit being part of the release.
365 */
366 gitHead: string;
367
368 /**
369 * The Git tag associated with the release.
370 */
371 gitTag: string;
372
373 /**
374 * The release notes for the release.
375 */
376 notes: string;
377
378 /**
379 * The name of the plugin that published the release.
380 */
381 pluginName: string;
382 }
383
384 export interface LastRelease {
385 /**
386 * The version name of the release.
387 */
388 version: string;
389
390 /**
391 * The Git tag of the release.
392 */
393 gitTag: string;
394
395 /**
396 * List of channels the release was published to.
397 */
398 channels: string[];
399
400 /**
401 * The Git checksum of the last commit of the release.
402 */
403 gitHead: string;
404
405 /**
406 * The Release name
407 */
408 name: string;
409 }
410
411 export interface NextRelease extends Omit<LastRelease, "channels"> {
412 /**
413 * The semver export type of the release.
414 */
415 type: ReleaseType;
416
417 /**
418 * The release channel of the release.
419 */
420 channel: string;
421
422 /**
423 * The release notes of the next release.
424 */
425 notes?: string | undefined;
426 }
427
428 /**
429 * Specifies a plugin to use.
430 *
431 * The plugin is specified by its module name.
432 *
433 * To pass options to a plugin, specify an array containing the plugin module
434 * name and an options object.
435 */
436 export type PluginSpec<T = any> = string | [string, T];
437
438 /**
439 * semantic-release options, after normalization and defaults have been
440 * applied.
441 */
442 export interface GlobalConfig extends Options {
443 /**
444 * The branches on which releases should happen. By default
445 * **semantic-release** will release:
446 *
447 * * regular releases to the default distribution channel from the
448 * branch `master` / `main`
449 * * regular releases to a distribution channel matching the branch
450 * name from any existing branch with a name matching a maintenance
451 * release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a
452 * number)
453 * * regular releases to the `next` distribution channel from the
454 * branch `next` if it exists
455 * * regular releases to the `next-major` distribution channel from
456 * the branch `next-major` if it exists.
457 * * prereleases to the `beta` distribution channel from the branch
458 * `beta` if it exists
459 * * prereleases to the `alpha` distribution channel from the branch
460 * `alpha` if it exists
461 *
462 * **Note**: If your repository does not have a release branch, then
463 * **semantic-release** will fail with an `ERELEASEBRANCHES` error
464 * message. If you are using the default configuration, you can fix
465 * this error by pushing a `master`/`main branch.
466 *
467 * **Note**: Once **semantic-release** is configured, any user with the
468 * permission to push commits on one of those branches will be able to
469 * publish a release. It is recommended to protect those branches, for
470 * example with [GitHub protected branches](https://help.github.com/articles/about-protected-branches).
471 *
472 * See [Workflow configuration](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#workflow-configuration)
473 * for more details.
474 */
475 branches: ReadonlyArray<BranchSpec> | BranchSpec;
476
477 /**
478 * The git repository URL.
479 *
480 * Any valid git url format is supported (see
481 * [git protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols))
482 *
483 * Default: `repository` property in `package.json`, or git origin url.
484 */
485 repositoryUrl: string;
486
487 /**
488 * The git tag format used by **semantic-release** to identify
489 * releases. The tag name is generated with [Lodash template](https://lodash.com/docs#template)
490 * and will be compiled with the `version` variable.
491 *
492 * **Note**: The `tagFormat` must contain the `version` variable
493 * exactly once and compile to a
494 * [valid git reference](https://git-scm.com/docs/git-check-ref-format#_description).
495 */
496 tagFormat: string;
497
498 /**
499 * Define the list of plugins to use. Plugins will run in series, in
500 * the order defined, for each [step](https://semantic-release.gitbook.io/semantic-release/#release-steps)
501 * if they implement it.
502 *
503 * Plugins configuration can be defined by wrapping the name and an
504 * options object in an array.
505 *
506 * See [Plugins configuration](https://semantic-release.gitbook.io/semantic-release/usage/plugins#plugins)
507 * for more details.
508 *
509 * Default: `[
510 * "@semantic-release/commit-analyzer",
511 * "@semantic-release/release-notes-generator",
512 * "@semantic-release/npm",
513 * "@semantic-release/github"
514 * ]`
515 */
516 plugins: ReadonlyArray<PluginSpec>;
517 }
518
519 /** semantic-release configuration specific for API usage. */
520 export interface Config {
521 /**
522 * The current working directory to use. It should be configured to
523 * the root of the Git repository to release from.
524 *
525 * It allows to run semantic-release from a specific path without
526 * having to change the local process cwd with process.chdir().
527 *
528 * @default process.cwd
529 */
530 cwd?: string | undefined;
531
532 /**
533 * The environment variables to use.
534 *
535 * It allows to run semantic-release with specific environment
536 * variables without having to modify the local process.env.
537 *
538 * @default process.env
539 */
540 env?: Record<string, any> | undefined;
541
542 /**
543 * The writable stream used to log information.
544 *
545 * It allows to configure semantic-release to write logs to a specific
546 * stream rather than the local process.stdout.
547 *
548 * @default process.stdout
549 */
550 stdout?: NodeJS.WriteStream | undefined;
551
552 /**
553 * The writable stream used to log errors.
554 *
555 * It allows to configure semantic-release to write errors to a
556 * specific stream rather than the local process.stderr.
557 *
558 * @default process.stderr
559 */
560 stderr?: NodeJS.WriteStream | undefined;
561 }
562
563 /**
564 * semantic-release options.
565 *
566 * Can be used to set any core option or plugin options.
567 * Each option will take precedence over options configured in the
568 * configuration file and shareable configurations.
569 */
570 export interface Options {
571 /**
572 * List of modules or file paths containing a
573 * [shareable configuration](https://semantic-release.gitbook.io/semantic-release/usage/shareable-configurations).
574 * If multiple shareable configurations are set, they will be imported
575 * in the order defined with each configuration option taking
576 * precedence over the options defined in a previous shareable
577 * configuration.
578 *
579 * **Note**: Options defined via CLI arguments or in the configuration
580 * file will take precedence over the ones defined in any shareable
581 * configuration.
582 */
583 extends?: ReadonlyArray<string> | string | undefined;
584
585 /**
586 * The branches on which releases should happen. By default
587 * **semantic-release** will release:
588 *
589 * * regular releases to the default distribution channel from the
590 * branch `master`/`main
591 * * regular releases to a distribution channel matching the branch
592 * name from any existing branch with a name matching a maintenance
593 * release range (`N.N.x` or `N.x.x` or `N.x` with `N` being a
594 * number)
595 * * regular releases to the `next` distribution channel from the
596 * branch `next` if it exists
597 * * regular releases to the `next-major` distribution channel from
598 * the branch `next-major` if it exists.
599 * * prereleases to the `beta` distribution channel from the branch
600 * `beta` if it exists
601 * * prereleases to the `alpha` distribution channel from the branch
602 * `alpha` if it exists
603 *
604 * **Note**: If your repository does not have a release branch, then
605 * **semantic-release** will fail with an `ERELEASEBRANCHES` error
606 * message. If you are using the default configuration, you can fix
607 * this error by pushing a `master`/`main` branch.
608 *
609 * **Note**: Once **semantic-release** is configured, any user with the
610 * permission to push commits on one of those branches will be able to
611 * publish a release. It is recommended to protect those branches, for
612 * example with [GitHub protected branches](https://help.github.com/articles/about-protected-branches).
613 *
614 * See [Workflow configuration](https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#workflow-configuration)
615 * for more details.
616 */
617 branches?: ReadonlyArray<BranchSpec> | BranchSpec | undefined;
618
619 /**
620 * The git repository URL.
621 *
622 * Any valid git url format is supported (see
623 * [git protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols))
624 *
625 * Default: `repository` property in `package.json`, or git origin url.
626 */
627 repositoryUrl?: string | undefined;
628
629 /**
630 * The git tag format used by **semantic-release** to identify
631 * releases. The tag name is generated with [Lodash template](https://lodash.com/docs#template)
632 * and will be compiled with the `version` variable.
633 *
634 * **Note**: The `tagFormat` must contain the `version` variable
635 * exactly once and compile to a
636 * [valid git reference](https://git-scm.com/docs/git-check-ref-format#_description).
637 */
638 tagFormat?: string | undefined;
639
640 /**
641 * Define the list of plugins to use. Plugins will run in series, in
642 * the order defined, for each [step](https://semantic-release.gitbook.io/semantic-release/#release-steps)
643 * if they implement it.
644 *
645 * Plugins configuration can be defined by wrapping the name and an
646 * options object in an array.
647 *
648 * See [Plugins configuration](https://semantic-release.gitbook.io/semantic-release/usage/plugins#plugins)
649 * for more details.
650 *
651 * Default: `[
652 * "@semantic-release/commit-analyzer",
653 * "@semantic-release/release-notes-generator",
654 * "@semantic-release/npm",
655 * "@semantic-release/github"
656 * ]`
657 */
658 plugins?: ReadonlyArray<PluginSpec> | undefined;
659
660 /**
661 * Dry-run mode, skip publishing, print next version and release notes.
662 */
663 dryRun?: boolean | undefined;
664
665 /**
666 * Set to false to skip Continuous Integration environment verifications.
667 * This allows for making releases from a local machine.
668 */
669 ci?: boolean | undefined;
670
671 /**
672 * Any other options supported by plugins.
673 */
674 [name: string]: any;
675 }
676
677 /**
678 * An object with details of the release if a release was published, or
679 * false if no release was published.
680 */
681 export type Result =
682 | false
683 | {
684 /**
685 * Information related to the last release found.
686 */
687 lastRelease: LastRelease;
688
689 /**
690 * The list of commits included in the new release.
691 */
692 commits: Commit[];
693
694 /**
695 * Information related to the newly published release.
696 */
697 nextRelease: NextRelease;
698
699 /**
700 * The list of releases published, one release per publish plugin.
701 */
702 releases: Release[];
703 };
704
705 /**
706 * Run semantic-release and returns a Promise that resolves to a Result
707 * object.
708 * @async
709 */
710 export default function (options: Options, environment?: Config): Promise<Result>;
711}