@@ -10,9 +10,13 @@ import {
1010import { type GenericReleaseCreator } from './release/index.js'
1111import { Logger } from './logger.js'
1212
13+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14+ type GetParameter < T extends ( ...args : any [ ] ) => any > = Exclude < Parameters < T > [ 0 ] , undefined >
15+
1316export interface ReleaserOptions {
1417 dryRun ?: boolean
1518 silent ?: boolean
19+ verbose ?: boolean
1620 logger ?: Logger
1721}
1822
@@ -27,13 +31,13 @@ export class Releaser<P extends GenericProject = GenericProject> {
2731 /**
2832 * The git client used to interact with the repository.
2933 */
30- gitClient : ConventionalGitClient
34+ readonly gitClient : ConventionalGitClient
3135 /**
3236 * The logger used to log messages during the release process.
3337 */
34- logger : Logger
38+ readonly logger : Logger
39+ readonly isMonorepo : boolean
3540 private readonly queue : ( ( ) => Promise < unknown > ) [ ] = [ ]
36- private readonly isMonorepo : boolean
3741
3842 /**
3943 * Creates a project releaser.
@@ -49,13 +53,18 @@ export class Releaser<P extends GenericProject = GenericProject> {
4953 this . isMonorepo = project instanceof GenericMonorepoProject
5054 }
5155
56+ enqueue ( fn : ( ) => Promise < void > ) {
57+ this . queue . push ( fn )
58+ return this
59+ }
60+
5261 /**
5362 * Enqueue a task to bump the version of the project.
5463 * @param options
5564 * @returns Project releaser instance for chaining.
5665 */
57- bump ( options ?: Omit < Parameters < P [ 'bump' ] > [ 0 ] , 'dryRun' | 'logger' > ) {
58- this . queue . push ( async ( ) => {
66+ bump ( options ?: Omit < GetParameter < P [ 'bump' ] > , 'dryRun' | 'logger' > ) {
67+ return this . enqueue ( async ( ) => {
5968 const { isMonorepo } = this
6069 const { dryRun } = this . options
6170 const logger = this . logger . createChild ( 'bump' )
@@ -72,8 +81,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
7281 logger . info ( `No version${ isMonorepo ? 's' : '' } changes detected.` )
7382 }
7483 } )
75-
76- return this
7784 }
7885
7986 /**
@@ -82,7 +89,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
8289 * @returns Project releaser instance for chaining.
8390 */
8491 commit ( options ?: ReleaserCommitOptions ) {
85- this . queue . push ( async ( ) => {
92+ return this . enqueue ( async ( ) => {
8693 const { dryRun } = this . options
8794
8895 this . logger . info ( 'commit' , `Committing changes...` )
@@ -107,8 +114,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
107114 await this . gitClient . commit ( params )
108115 }
109116 } )
110-
111- return this
112117 }
113118
114119 /**
@@ -117,7 +122,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
117122 * @returns Project releaser instance for chaining.
118123 */
119124 tag ( options ?: ReleaserTagOptions ) {
120- this . queue . push ( async ( ) => {
125+ return this . enqueue ( async ( ) => {
121126 const { isMonorepo } = this
122127 const { dryRun } = this . options
123128
@@ -144,8 +149,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
144149 }
145150 }
146151 } )
147-
148- return this
149152 }
150153
151154 /**
@@ -154,7 +157,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
154157 * @returns Project releaser instance for chaining.
155158 */
156159 push ( branch ?: string ) {
157- this . queue . push ( async ( ) => {
160+ return this . enqueue ( async ( ) => {
158161 const { dryRun } = this . options
159162 const targetBranch = branch || await this . gitClient . getDefaultBranch ( )
160163
@@ -170,17 +173,15 @@ export class Releaser<P extends GenericProject = GenericProject> {
170173 } )
171174 }
172175 } )
173-
174- return this
175176 }
176177
177178 /**
178179 * Enqueue a task to publish the project.
179180 * @param options
180181 * @returns Project releaser instance for chaining.
181182 */
182- publish ( options ?: Omit < Parameters < P [ 'publish' ] > [ 0 ] , 'dryRun' | 'logger' > ) {
183- this . queue . push ( async ( ) => {
183+ publish ( options ?: Omit < GetParameter < P [ 'publish' ] > , 'dryRun' | 'logger' > ) {
184+ return this . enqueue ( async ( ) => {
184185 const { isMonorepo } = this
185186 const { dryRun } = this . options
186187 const logger = this . logger . createChild ( 'package' )
@@ -193,8 +194,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
193194 ...options
194195 } )
195196 } )
196-
197- return this
198197 }
199198
200199 /**
@@ -203,7 +202,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
203202 * @returns Project releaser instance for chaining.
204203 */
205204 release ( releaseCreator : GenericReleaseCreator ) {
206- this . queue . push ( async ( ) => {
205+ return this . enqueue ( async ( ) => {
207206 const { isMonorepo } = this
208207 const { dryRun } = this . options
209208 const logger = this . logger . createChild ( 'release' )
@@ -216,8 +215,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
216215 logger
217216 } )
218217 } )
219-
220- return this
221218 }
222219
223220 /**
0 commit comments