Skip to content

Commit 49e3a99

Browse files
author
keindev
committed
improve: add noProcessExit to Tree.start options
assign: #1052
1 parent a7ef481 commit 49e3a99

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/TaskTree.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export enum ExitCode {
1111
export interface ITaskTreeOptions {
1212
/** Removes all subtasks and bars from the main task */
1313
autoClear?: boolean;
14+
/** Throws an exception on error instead of calling `process.exit()` */
15+
noProcessExit?: boolean;
1416
/** Disable task tree rendering */
1517
silent?: boolean;
1618
}
@@ -23,6 +25,7 @@ export class TaskTree {
2325
#autoClear = false;
2426
#handle: NodeJS.Timeout | undefined;
2527
readonly #manager: UpdateManager;
28+
#noProcessExit = false;
2629
#offset = 0;
2730
#paused = false;
2831
#silent = false;
@@ -107,12 +110,15 @@ export class TaskTree {
107110
return task;
108111
}
109112

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+
*/
111117
exit(code: ExitCode = ExitCode.Success, error?: string | Error | unknown): void | never {
112118
if (this.#started) {
113119
this.stop();
114120

115-
if (this.#silent) {
121+
if (this.#silent || this.#noProcessExit) {
116122
if (code === ExitCode.Error) throw this.getError(error);
117123
} else {
118124
// eslint-disable-next-line no-process-exit
@@ -180,9 +186,13 @@ export class TaskTree {
180186
return output;
181187
}
182188

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 {
185194
this.#silent = !!silent;
195+
this.#noProcessExit = !!noProcessExit;
186196
this.#autoClear = !!autoClear;
187197
this.#tasks = [];
188198
this.#offset = 0;

0 commit comments

Comments
 (0)