@@ -6,6 +6,7 @@ import { renderTaskList } from './components/renderTaskList';
66import { loadNpmWorkspaceScripts } from './npmUtils' ;
77import { statusIcons } from './statusIcons' ;
88import { Task , task } from './task' ;
9+ import { trackLinearOutput } from './trackLinearOutput' ;
910import { formatTime , indent } from './util' ;
1011import wildcardMatch from './wildcardMatch' ;
1112
@@ -58,9 +59,12 @@ export interface RunpCommandRaw extends Omit<Partial<RunpCommand>, 'args' | 'dep
5859 dependsOn ?: string | number | Array < string | number > ;
5960}
6061
61- export interface RunpOptions extends RunpCommonOptions {
62+ type Commands = ( string | [ cmd : string , ...args : string [ ] ] | RunpCommandRaw | false | undefined | null ) [ ] ;
63+ export type RunpResult = { result : 'success' ; output : string } | { result : 'error' ; output : string } ;
64+
65+ export interface RunpOptions < TCommands extends Commands = Commands > extends RunpCommonOptions {
6266 /** A list of command to execute in parallel */
63- commands : ( string | [ cmd : string , ... args : string [ ] ] | RunpCommandRaw | false | undefined | null ) [ ] ;
67+ commands : TCommands ;
6468 /** Maximum number of parallel tasks */
6569 parallelTasks ?: number ;
6670 target ?: RenderOptions [ 'target' ] ;
@@ -72,7 +76,9 @@ export const RUNP_TASK_DELEGATE = `__runp_task__${RUNP_TASK_V}__`;
7276
7377const switchRegexp = / s | p | f ( = ( t r u e | f a l s e ) ) ? | k ( = ( t r u e | f a l s e ) ) ? | n = \d + / g;
7478
75- export async function runp ( options : RunpOptions ) {
79+ export async function runp < const TCommands extends Commands = Commands > (
80+ options : RunpOptions < TCommands > ,
81+ ) : Promise < { [ K in keyof TCommands ] : RunpResult } > {
7682 const resolvedCommands = await resolveCommands ( options ) ;
7783
7884 if ( process . env . RUNP === RUNP_TASK_V ) {
@@ -98,32 +104,12 @@ export async function runp(options: RunpOptions) {
98104 if ( process . stdout . isTTY || options . target ) {
99105 stop = renderTTY ( tasks , options . target ) ;
100106 } else {
101- await renderNonTTY ( tasks ) ;
107+ stop = await renderNonTTY ( tasks ) ;
102108 }
103109
104- const results = await Promise . all (
105- tasks . map ( ( task ) =>
106- task . result
107- . then (
108- ( output ) =>
109- ( {
110- result : 'success' ,
111- output,
112- } ) as const ,
113- )
114- . catch (
115- ( output : string ) =>
116- ( {
117- result : 'error' ,
118- output,
119- } ) as const ,
120- ) ,
121- ) ,
122- ) ;
123-
110+ const results = await Promise . all ( tasks . map ( ( task ) => task . result ) ) ;
124111 stop ?.( ) ;
125-
126- return results ;
112+ return results as { [ K in keyof TCommands ] : RunpResult } ;
127113}
128114
129115export async function resolveCommands ( options : RunpOptions ) {
@@ -324,15 +310,14 @@ function renderTTY(tasks: ReturnType<typeof task>[], target?: RenderOptions['tar
324310}
325311
326312async function renderNonTTY ( tasks : ReturnType < typeof task > [ ] , margin = 0 ) {
327- for ( const {
328- command : { keepOutput, displayTimeOver = - Infinity } ,
329- result,
330- state,
331- } of tasks ) {
332- await result . catch ( ( ) => undefined ) ;
313+ trackLinearOutput ( tasks , ( line : string ) => console . log ( line ) ) ;
314+
315+ for ( const { command, result, state } of tasks ) {
316+ const { linearOutput, keepOutput, displayTimeOver = - Infinity } = command ;
317+ await result ;
333318 const { status, statusString = statusIcons [ status ] , title, subTasks, time } = state . get ( ) ;
334319 const output = state . get ( ) . output . trim ( ) ;
335- const showOutput = ( status === 'error' || keepOutput ) && output . length > 0 ;
320+ const showOutput = ! linearOutput && ( status === 'error' || keepOutput ) && output . length > 0 ;
336321 const timeString = time !== undefined && time >= displayTimeOver ? ` [${ formatTime ( time ) } ]` : '' ;
337322
338323 console . info ( indent ( `${ statusString } ${ title } ${ timeString } ` , margin ) ) ;
0 commit comments