@@ -11,6 +11,8 @@ export enum ExitCode {
11
11
export interface ITaskTreeOptions {
12
12
/** Removes all subtasks and bars from the main task */
13
13
autoClear ?: boolean ;
14
+ /** Throws an exception on error instead of calling `process.exit()` */
15
+ noProcessExit ?: boolean ;
14
16
/** Disable task tree rendering */
15
17
silent ?: boolean ;
16
18
}
@@ -23,6 +25,7 @@ export class TaskTree {
23
25
#autoClear = false ;
24
26
#handle: NodeJS . Timeout | undefined ;
25
27
readonly #manager: UpdateManager ;
28
+ #noProcessExit = false ;
26
29
#offset = 0 ;
27
30
#paused = false ;
28
31
#silent = false ;
@@ -107,12 +110,15 @@ export class TaskTree {
107
110
return task ;
108
111
}
109
112
110
- /** Force the process to exit (see process.exit). Do nothing in "silent mode" */
113
+ /**
114
+ * Force the process to exit (see process.exit).
115
+ * Throw exception if "silent" or "noProcessExit" is true.
116
+ */
111
117
exit ( code : ExitCode = ExitCode . Success , error ?: string | Error | unknown ) : void | never {
112
118
if ( this . #started) {
113
119
this . stop ( ) ;
114
120
115
- if ( this . #silent) {
121
+ if ( this . #silent || this . #noProcessExit ) {
116
122
if ( code === ExitCode . Error ) throw this . getError ( error ) ;
117
123
} else {
118
124
// eslint-disable-next-line no-process-exit
@@ -180,9 +186,13 @@ export class TaskTree {
180
186
return output ;
181
187
}
182
188
183
- /** Starts output a task tree in a terminal at a defined interval. In “silent mode” - the task tree only collects tasks and is not output it in a terminal */
184
- start ( { silent, autoClear } : ITaskTreeOptions = { } ) : TaskTree {
189
+ /**
190
+ * Starts output a task tree in a terminal at a defined interval.
191
+ * In “silent mode” - the task tree only collects tasks and is not output it in a terminal
192
+ */
193
+ start ( { silent, autoClear, noProcessExit } : ITaskTreeOptions = { } ) : TaskTree {
185
194
this . #silent = ! ! silent ;
195
+ this . #noProcessExit = ! ! noProcessExit ;
186
196
this . #autoClear = ! ! autoClear ;
187
197
this . #tasks = [ ] ;
188
198
this . #offset = 0 ;
0 commit comments