@@ -237,19 +237,25 @@ export class Logger {
237237 * Nested groups are not supported.
238238 *
239239 * @example
240- * await logger.group('Running plugin "ESLint"', async () => {
240+ * const eslintResult = await logger.group('Running plugin "ESLint"', async () => {
241241 * logger.debug('ESLint version is 9.16.0');
242- * await logger.command('npx eslint . --format=json', () => {
242+ * const result = await logger.command('npx eslint . --format=json', () => {
243243 * // ...
244244 * })
245245 * logger.info('Found 42 lint errors.');
246- * return 'Completed "ESLint" plugin execution';
246+ * return {
247+ * message: 'Completed "ESLint" plugin execution',
248+ * result,
249+ * };
247250 * });
248251 *
249252 * @param title Display title for the group.
250253 * @param worker Asynchronous implementation. Returned promise determines group status and ending message. Inner logs are attached to the group.
251254 */
252- async group ( title : string , worker : ( ) => Promise < string > ) : Promise < void > {
255+ async group < T = undefined > (
256+ title : string ,
257+ worker : ( ) => Promise < string | { message : string ; result : T } > ,
258+ ) : Promise < T > {
253259 if ( this . #groupColor) {
254260 throw new Error (
255261 'Internal Logger error - nested groups are not supported' ,
@@ -277,10 +283,12 @@ export class Logger {
277283 const end = performance . now ( ) ;
278284
279285 if ( result . status === 'fulfilled' ) {
286+ const message =
287+ typeof result . value === 'string' ? result . value : result . value . message ;
280288 console . log (
281289 [
282290 this . #colorize( this . #groupSymbols. end , this . #groupColor) ,
283- this . #colorize( result . value , 'green' ) ,
291+ this . #colorize( message , 'green' ) ,
284292 this . #formatDurationSuffix( { start, end } ) ,
285293 ] . join ( ' ' ) ,
286294 ) ;
@@ -306,6 +314,11 @@ export class Logger {
306314 if ( result . status === 'rejected' ) {
307315 throw result . reason ;
308316 }
317+
318+ if ( typeof result . value === 'object' ) {
319+ return result . value . result ;
320+ }
321+ return undefined as T ;
309322 }
310323
311324 #createGroupMarkers( ) : {
0 commit comments