@@ -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...` )
@@ -100,15 +107,18 @@ export class Releaser<P extends GenericProject = GenericProject> {
100107 this . logger . verbose ( 'commit' , `- ${ file } ` )
101108 } )
102109
103- this . logger . verbose ( 'commit' , `Commit message:\n\n${ params . message } ` )
110+ this . logger . verbose (
111+ 'commit' ,
112+ params . message . includes ( '\n' )
113+ ? `Commit message:\n\n${ params . message } `
114+ : `Commit message: ${ params . message } `
115+ )
104116
105117 if ( ! dryRun ) {
106118 await this . gitClient . add ( files )
107119 await this . gitClient . commit ( params )
108120 }
109121 } )
110-
111- return this
112122 }
113123
114124 /**
@@ -117,7 +127,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
117127 * @returns Project releaser instance for chaining.
118128 */
119129 tag ( options ?: ReleaserTagOptions ) {
120- this . queue . push ( async ( ) => {
130+ return this . enqueue ( async ( ) => {
121131 const { isMonorepo } = this
122132 const { dryRun } = this . options
123133
@@ -144,8 +154,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
144154 }
145155 }
146156 } )
147-
148- return this
149157 }
150158
151159 /**
@@ -154,7 +162,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
154162 * @returns Project releaser instance for chaining.
155163 */
156164 push ( branch ?: string ) {
157- this . queue . push ( async ( ) => {
165+ return this . enqueue ( async ( ) => {
158166 const { dryRun } = this . options
159167 const targetBranch = branch || await this . gitClient . getDefaultBranch ( )
160168
@@ -170,17 +178,15 @@ export class Releaser<P extends GenericProject = GenericProject> {
170178 } )
171179 }
172180 } )
173-
174- return this
175181 }
176182
177183 /**
178184 * Enqueue a task to publish the project.
179185 * @param options
180186 * @returns Project releaser instance for chaining.
181187 */
182- publish ( options ?: Omit < Parameters < P [ 'publish' ] > [ 0 ] , 'dryRun' | 'logger' > ) {
183- this . queue . push ( async ( ) => {
188+ publish ( options ?: Omit < GetParameter < P [ 'publish' ] > , 'dryRun' | 'logger' > ) {
189+ return this . enqueue ( async ( ) => {
184190 const { isMonorepo } = this
185191 const { dryRun } = this . options
186192 const logger = this . logger . createChild ( 'package' )
@@ -193,8 +199,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
193199 ...options
194200 } )
195201 } )
196-
197- return this
198202 }
199203
200204 /**
@@ -203,7 +207,7 @@ export class Releaser<P extends GenericProject = GenericProject> {
203207 * @returns Project releaser instance for chaining.
204208 */
205209 release ( releaseCreator : GenericReleaseCreator ) {
206- this . queue . push ( async ( ) => {
210+ return this . enqueue ( async ( ) => {
207211 const { isMonorepo } = this
208212 const { dryRun } = this . options
209213 const logger = this . logger . createChild ( 'release' )
@@ -216,8 +220,6 @@ export class Releaser<P extends GenericProject = GenericProject> {
216220 logger
217221 } )
218222 } )
219-
220- return this
221223 }
222224
223225 /**
0 commit comments