Socket
Socket
Sign inDemoInstall

listr2

Package Overview
Dependencies
30
Maintainers
1
Versions
231
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0-beta.2 to 6.0.0-beta.3

66

dist/index.d.ts

@@ -97,2 +97,4 @@ import Enquirer from 'enquirer';

declare function splat(message: string, ...splat: any[]): string;
declare function parseTimestamp(): string;

@@ -138,2 +140,4 @@

declare class ProcessOutput {
private readonly stream;
constructor(stdout?: NodeJS.WriteStream, stderr?: NodeJS.WriteStream);
stdout(buffer: string): boolean;

@@ -182,2 +186,3 @@ stderr(buffer: string): boolean;

declare class Spinner {
private id?;
private readonly spinner;

@@ -187,2 +192,5 @@ private spinnerPosition;

fetch(): string;
isRunning(): boolean;
start(cb?: () => void): void;
stop(): void;
}

@@ -448,2 +456,9 @@

/**
* activate update through triggers from render hook
*
* @default true
* @global global option that can not be temperated with subtasks
*/
eager?: boolean;
/**
* removes empty lines from the data output

@@ -482,3 +497,2 @@ *

} & RendererPresetTimer;
private id?;
private bottomBar;

@@ -493,2 +507,4 @@ private promptBar;

getSelfOrParentOption<K extends keyof (typeof DefaultRenderer)['rendererOptions']>(task: Task<any, typeof DefaultRenderer>, key: K): (typeof DefaultRenderer)['rendererOptions'][K];
render(): void;
end(): void;
createRender(options?: {

@@ -499,6 +515,4 @@ tasks?: boolean;

}): string;
render(): void;
end(): void;
protected style(task: Task<ListrContext, typeof DefaultRenderer>, data?: boolean): string;
protected format(message: string, icon: string, level: number): string;
protected format(message: string, icon: string, level: number): string[];
private renderer;

@@ -544,2 +558,8 @@ private renderBottomBar;

declare enum ListrEnvironmentVariables {
DISABLE_COLOR = "LISTR_DISABLE_COLOR",
FORCE_UNICODE = "LISTR_FORCE_UNICODE",
FORCE_COLOR = "FORCE_COLOR"
}
/**

@@ -855,3 +875,3 @@ * ListrTask.

/**
* Forces TTY stdout eventhough it might not support it.
* Forces TTY stdout eventhough current terminal might not support it.
*

@@ -862,2 +882,8 @@ * @default false

/**
* Forces unicode eventhough current terminal might not support it.
*
* @default false
*/
forceUnicode?: boolean;
/**
* Inject data directly to TaskWrapper.

@@ -918,13 +944,13 @@ */

task: Task<Ctx, ListrRendererFactory>;
errors: ListrError<Ctx>[];
private options;
constructor(task: Task<Ctx, ListrRendererFactory>, errors: ListrError<Ctx>[], options: ListrBaseClassOptions<Ctx, any, any>);
private errors;
constructor(task: Task<Ctx, ListrRendererFactory>, options: ListrBaseClassOptions<Ctx, any, any>);
/** Get the title of the current task. */
get title(): string;
/** Change the title of the current task. */
set title(data: string);
set title(title: string | string[]);
/** Get the output from the output channel. */
get output(): string;
/** Send a output to the output channel. */
set output(data: string);
set output(output: string | string[]);
/** Create a new subtask with given renderer selection from the parent task. */

@@ -935,3 +961,3 @@ newListr<NewCtx = Ctx>(task: ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[] | ((parent: Omit<this, 'skip' | 'enabled'>) => ListrTask<NewCtx, Renderer> | ListrTask<NewCtx, Renderer>[]), options?: ListrSubClassOptions<NewCtx, Renderer>): Listr<NewCtx, any, any>;

/** Skip current task. */
skip(message?: string): void;
skip(message?: string, ...metadata: any[]): void;
/** Get the number of retrying, else returns false */

@@ -965,3 +991,3 @@ isRetrying(): Task<Ctx, Renderer>['retry'];

listr: Listr<Ctx, any, any>;
tasks: ListrTask<Ctx, any>;
task: ListrTask<Ctx, any>;
options: ListrOptions;

@@ -973,4 +999,2 @@ rendererOptions: ListrGetRendererOptions<Renderer>;

state: ListrTaskState;
/** The task object itself, to further utilize it. */
task: ListrTaskFn<Ctx, Renderer>;
/** Extend current task with multiple subtasks. */

@@ -981,3 +1005,3 @@ subtasks: Task<Ctx, Renderer>[];

/** Untouched unchanged title of the task */
initialTitle?: string;
readonly initialTitle?: string;
/** Output data from the task. */

@@ -997,4 +1021,7 @@ output?: string;

prompt: ListrTaskPrompt;
parent?: Task<Ctx, Renderer>;
private enabled;
constructor(listr: Listr<Ctx, any, any>, tasks: ListrTask<Ctx, any>, options: ListrOptions, rendererOptions: ListrGetRendererOptions<Renderer>);
/** The task object itself, to further utilize it. */
private taskFn;
constructor(listr: Listr<Ctx, any, any>, task: ListrTask<Ctx, any>, options: ListrOptions, rendererOptions: ListrGetRendererOptions<Renderer>);
set state$(state: ListrTaskState);

@@ -1012,2 +1039,3 @@ set output$(data: string);

hasFinalized(): boolean;
isPending(): boolean;
/** Returns whether this task is in progress. */

@@ -1059,9 +1087,9 @@ isStarted(): boolean;

parentTask?: Task<any, any>;
events: EventManager<ListrEventType, ListrEventMap>;
tasks: Task<Ctx, ListrGetRendererClassFromValue<Renderer>>[];
err: ListrError<Ctx>[];
errors: ListrError<Ctx>[];
ctx: Ctx;
events: EventManager<ListrEventType, ListrEventMap>;
path: string[];
rendererClass: ListrRendererFactory;
rendererClassOptions: ListrGetRendererOptions<ListrRendererFactory>;
path: string[];
private concurrency;

@@ -1093,2 +1121,2 @@ private renderer;

export { DefaultRenderer, Figures, Listr, ListrBaseClassOptions, ListrBaseRenderer, ListrContext, ListrDefaultNonTTYRendererOptions, ListrDefaultRenderer, ListrDefaultRendererOptions, ListrDefaultRendererValue, ListrError, ListrErrorTypes, ListrEventType, ListrFallbackRenderer, ListrFallbackRendererValue, ListrGetRendererClassFromValue, ListrGetRendererOptions, ListrGetRendererTaskOptions, ListrGetRendererValueFromClass, ListrLogger, ListrLoggerOptions, ListrOptions, ListrRenderer, ListrRendererFactory, ListrRendererOptions, ListrRendererValue, ListrSilentRenderer, ListrSilentRendererValue, ListrSimpleRenderer, ListrSimpleRendererValue, ListrSubClassOptions, ListrTask, ListrTaskEventType, ListrTaskFn, ListrTaskMessage, Task as ListrTaskObject, ListrTaskPrompt, ListrTaskResult, ListrTaskRetry, ListrTaskState, TaskWrapper as ListrTaskWrapper, ListrTestRenderer, ListrTestRendererValue, LogEntityOptions, LogLevels, LoggerField, LoggerFieldFn, LoggerFormat, LoggerRendererOptions, Manager, PresetTimer, PresetTimestamp, ProcessOutput, ProcessOutputRendererOptions, PromptError, PromptInstance, PromptOptions, PromptOptionsMap, PromptOptionsType, PromptSettings, PromptTypes, RENDERER_TIMER, RENDERER_TIMESTAMP, RendererPresetTimer, RendererPresetTimestamp, SilentRenderer, SimpleRenderer, Spinner, SupportedRenderer, TestRenderer, TestRendererEvent, Unionize, VerboseRenderer, assertFunctionOrSelf, cloneObject, color, createPrompt, destroyPrompt, figures, generateUUID, getRenderer, getRendererClass, indentString, isObservable, isUnicodeSupported, parseTaskTime, parseTimestamp };
export { DefaultRenderer, Figures, Listr, ListrBaseClassOptions, ListrBaseRenderer, ListrContext, ListrDefaultNonTTYRendererOptions, ListrDefaultRenderer, ListrDefaultRendererOptions, ListrDefaultRendererValue, ListrEnvironmentVariables, ListrError, ListrErrorTypes, ListrEventType, ListrFallbackRenderer, ListrFallbackRendererValue, ListrGetRendererClassFromValue, ListrGetRendererOptions, ListrGetRendererTaskOptions, ListrGetRendererValueFromClass, ListrLogger, ListrLoggerOptions, ListrOptions, ListrRenderer, ListrRendererFactory, ListrRendererOptions, ListrRendererValue, ListrSilentRenderer, ListrSilentRendererValue, ListrSimpleRenderer, ListrSimpleRendererValue, ListrSubClassOptions, ListrTask, ListrTaskEventType, ListrTaskFn, ListrTaskMessage, Task as ListrTaskObject, ListrTaskPrompt, ListrTaskResult, ListrTaskRetry, ListrTaskState, TaskWrapper as ListrTaskWrapper, ListrTestRenderer, ListrTestRendererValue, LogEntityOptions, LogLevels, LoggerField, LoggerFieldFn, LoggerFormat, LoggerRendererOptions, Manager, PresetTimer, PresetTimestamp, ProcessOutput, ProcessOutputRendererOptions, PromptError, PromptInstance, PromptOptions, PromptOptionsMap, PromptOptionsType, PromptSettings, PromptTypes, RENDERER_TIMER, RENDERER_TIMESTAMP, RendererPresetTimer, RendererPresetTimestamp, SilentRenderer, SimpleRenderer, Spinner, SupportedRenderer, TestRenderer, TestRendererEvent, Unionize, VerboseRenderer, assertFunctionOrSelf, cloneObject, color, createPrompt, destroyPrompt, figures, generateUUID, getRenderer, getRendererClass, indentString, isObservable, isUnicodeSupported, parseTaskTime, parseTimestamp, splat };

@@ -36,2 +36,3 @@ "use strict";

Listr: () => Listr,
ListrEnvironmentVariables: () => ListrEnvironmentVariables,
ListrError: () => ListrError,

@@ -68,3 +69,4 @@ ListrErrorTypes: () => ListrErrorTypes,

parseTaskTime: () => parseTaskTime,
parseTimestamp: () => parseTimestamp
parseTimestamp: () => parseTimestamp,
splat: () => splat
});

@@ -76,2 +78,10 @@ module.exports = __toCommonJS(src_exports);

// src/constants/environment-variables.constants.ts
var ListrEnvironmentVariables = /* @__PURE__ */ ((ListrEnvironmentVariables2) => {
ListrEnvironmentVariables2["DISABLE_COLOR"] = "LISTR_DISABLE_COLOR";
ListrEnvironmentVariables2["FORCE_UNICODE"] = "LISTR_FORCE_UNICODE";
ListrEnvironmentVariables2["FORCE_COLOR"] = "FORCE_COLOR";
return ListrEnvironmentVariables2;
})(ListrEnvironmentVariables || {});
// src/constants/state.constants.ts

@@ -90,2 +100,17 @@ var ListrTaskState = /* @__PURE__ */ ((ListrTaskState2) => {

// src/constants/event.constants.ts
var ListrEventType = /* @__PURE__ */ ((ListrEventType2) => {
ListrEventType2["SHOULD_REFRESH_RENDER"] = "SHOUD_REFRESH_RENDER";
return ListrEventType2;
})(ListrEventType || {});
var ListrTaskEventType = /* @__PURE__ */ ((ListrTaskEventType2) => {
ListrTaskEventType2["TITLE"] = "TITLE";
ListrTaskEventType2["STATE"] = "STATE";
ListrTaskEventType2["ENABLED"] = "ENABLED";
ListrTaskEventType2["SUBTASK"] = "SUBTASK";
ListrTaskEventType2["OUTPUT"] = "OUTPUT";
ListrTaskEventType2["MESSAGE"] = "MESSAGE";
return ListrTaskEventType2;
})(ListrTaskEventType || {});
// src/lib/event-manager.ts

@@ -112,17 +137,2 @@ var import_eventemitter3 = __toESM(require("eventemitter3"));

// src/constants/event.constants.ts
var ListrEventType = /* @__PURE__ */ ((ListrEventType2) => {
ListrEventType2["SHOULD_REFRESH_RENDER"] = "SHOUD_REFRESH_RENDER";
return ListrEventType2;
})(ListrEventType || {});
var ListrTaskEventType = /* @__PURE__ */ ((ListrTaskEventType2) => {
ListrTaskEventType2["TITLE"] = "TITLE";
ListrTaskEventType2["STATE"] = "STATE";
ListrTaskEventType2["ENABLED"] = "ENABLED";
ListrTaskEventType2["SUBTASK"] = "SUBTASK";
ListrTaskEventType2["OUTPUT"] = "OUTPUT";
ListrTaskEventType2["MESSAGE"] = "MESSAGE";
return ListrTaskEventType2;
})(ListrTaskEventType || {});
// src/utils/environment/is-observable.ts

@@ -136,6 +146,3 @@ function isObservable(obj) {

function isUnicodeSupported() {
if (process.platform !== "win32") {
return true;
}
return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
return !!process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] || process.platform !== "win32" || !!process.env.CI || !!process.env.WT_SESSION || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
}

@@ -146,4 +153,3 @@ __name(isUnicodeSupported, "isUnicodeSupported");

var import_colorette = require("colorette");
var _a;
var color = (0, import_colorette.createColors)({ useColor: ((_a = process.env) == null ? void 0 : _a.LISTR_DISABLE_COLOR) !== "1" });
var color = (0, import_colorette.createColors)({ useColor: !process.env["LISTR_DISABLE_COLOR" /* DISABLE_COLOR */] });

@@ -198,2 +204,9 @@ // src/utils/format/indent-string.ts

// src/utils/format/splat.ts
var import_util = require("util");
function splat(message, ...splat2) {
return (0, import_util.format)(message, ...splat2);
}
__name(splat, "splat");
// src/utils/format/timestamp.ts

@@ -309,6 +322,6 @@ function parseTimestamp() {

}
multiLineMessage = multiLineMessage.filter((msg) => msg && msg.trim() !== "").map((msg) => {
var _a2, _b, _c, _d;
multiLineMessage = multiLineMessage.filter((msg) => String(msg).trim() !== "").map((msg) => {
var _a, _b, _c, _d;
return this.applyToEntity(this.style(level, msg), {
prefix: [...((_b = (_a2 = this.options) == null ? void 0 : _a2.entityOptions) == null ? void 0 : _b.prefix) ?? [], ...Array.isArray(options == null ? void 0 : options.prefix) ? options.prefix : [options == null ? void 0 : options.prefix]],
prefix: [...((_b = (_a = this.options) == null ? void 0 : _a.entityOptions) == null ? void 0 : _b.prefix) ?? [], ...Array.isArray(options == null ? void 0 : options.prefix) ? options.prefix : [options == null ? void 0 : options.prefix]],
suffix: [...((_d = (_c = this.options) == null ? void 0 : _c.entityOptions) == null ? void 0 : _d.suffix) ?? [], ...Array.isArray(options == null ? void 0 : options.suffix) ? options.suffix : [options == null ? void 0 : options.suffix]]

@@ -321,3 +334,3 @@ });

style(level, message) {
var _a2, _b, _c, _d, _e, _f, _g, _h;
var _a, _b, _c, _d, _e, _f, _g, _h;
let icon;

@@ -329,3 +342,3 @@ let coloring = /* @__PURE__ */ __name((input) => {

case "FAILED" /* FAILED */:
if ((_a2 = this.options) == null ? void 0 : _a2.useIcons) {
if ((_a = this.options) == null ? void 0 : _a.useIcons) {
coloring = color.red;

@@ -401,7 +414,13 @@ icon = figures.cross;

var ProcessOutput = class {
constructor(stdout = process.stdout, stderr = process.stderr) {
this.stream = {
stdout,
stderr
};
}
stdout(buffer) {
return process.stdout.write(buffer + import_os2.EOL);
return this.stream.stdout.write(buffer + import_os2.EOL);
}
stderr(buffer) {
return process.stderr.write(buffer + import_os2.EOL);
return this.stream.stderr.write(buffer + import_os2.EOL);
}

@@ -423,2 +442,19 @@ };

}
isRunning() {
return !!this.id;
}
start(cb) {
this.id = setInterval(() => {
this.spin();
if (cb) {
cb();
}
}, 100);
}
stop() {
clearInterval(this.id);
if (this.id) {
this.id = void 0;
}
}
};

@@ -436,6 +472,6 @@ __name(Spinner, "Spinner");

var TaskWrapper = class {
constructor(task, errors, options) {
constructor(task, options) {
this.task = task;
this.errors = errors;
this.options = options;
this.errors = task.listr.errors;
}

@@ -447,4 +483,5 @@ /** Get the title of the current task. */

/** Change the title of the current task. */
set title(data) {
this.task.title$ = data;
set title(title) {
title = Array.isArray(title) ? title : [title];
this.task.title$ = splat(title.shift(), ...title);
}

@@ -456,4 +493,5 @@ /** Get the output from the output channel. */

/** Send a output to the output channel. */
set output(data) {
this.task.output$ = data;
set output(output) {
output = Array.isArray(output) ? output : [output];
this.task.output$ = splat(output.shift(), ...output);
}

@@ -472,14 +510,14 @@ /** Create a new subtask with given renderer selection from the parent task. */

report(error, type) {
var _a2;
var _a;
if (this.task.options.collectErrors !== false) {
this.errors.push(new ListrError(error, type, this.task));
}
this.task.message$ = { error: error.message ?? ((_a2 = this.task) == null ? void 0 : _a2.title) ?? "Task with no title." };
this.task.message$ = { error: error.message ?? ((_a = this.task) == null ? void 0 : _a.title) };
}
/** Skip current task. */
skip(message) {
var _a2;
skip(message, ...metadata) {
var _a;
this.task.state$ = "SKIPPED" /* SKIPPED */;
if (message) {
this.task.message$ = { skip: message ?? ((_a2 = this.task) == null ? void 0 : _a2.title) ?? "Task with no title." };
this.task.message$ = { skip: message ? splat(message, ...metadata) : (_a = this.task) == null ? void 0 : _a.title };
}

@@ -497,4 +535,4 @@ }

async prompt(options) {
var _a2;
return createPrompt.bind(this)(options, { ...(_a2 = this.options) == null ? void 0 : _a2.injectWrapper });
var _a;
return createPrompt.bind(this)(options, { ...(_a = this.options) == null ? void 0 : _a.injectWrapper });
}

@@ -635,5 +673,30 @@ /** Cancels the current prompt attach to this task. */

getSelfOrParentOption(task, key) {
var _a2, _b;
return ((_a2 = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a2[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
var _a, _b;
return ((_a = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
}
render() {
var _a, _b;
if (this.spinner.isRunning()) {
return;
}
const updateRender = /* @__PURE__ */ __name(() => (0, import_log_update.default)(this.createRender()), "updateRender");
if (!((_a = this.options) == null ? void 0 : _a.lazy)) {
this.spinner.start(() => {
updateRender();
});
}
if ((_b = this.options) == null ? void 0 : _b.eager) {
this.events.on("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */, () => {
updateRender();
});
}
}
end() {
this.spinner.stop();
import_log_update.default.clear();
import_log_update.default.done();
if (!this.options.clearOutput) {
this.logger.process.stdout(this.createRender({ prompt: false }));
}
}
createRender(options) {

@@ -650,43 +713,22 @@ options = {

const renderPrompt = this.renderPrompt();
if (options.tasks && (renderTasks == null ? void 0 : renderTasks.trim().length) > 0) {
render.push(renderTasks);
if (options.tasks && renderTasks.length > 0) {
render.push(...renderTasks);
}
if (options.bottomBar && (renderBottomBar == null ? void 0 : renderBottomBar.trim().length) > 0) {
render.push((render.length > 0 ? import_os3.EOL : "") + renderBottomBar);
if (options.bottomBar && renderBottomBar.length > 0) {
if (render.length > 0) {
render.push("");
}
render.push(...renderBottomBar);
}
if (options.prompt && (renderPrompt == null ? void 0 : renderPrompt.trim().length) > 0) {
render.push((render.length > 0 ? import_os3.EOL : "") + renderPrompt);
if (options.prompt && renderPrompt.length > 0) {
if (render.length > 0) {
render.push("");
}
render.push(...renderPrompt);
}
return render.length > 0 ? render.join(import_os3.EOL) : "";
return render.join(import_os3.EOL);
}
render() {
var _a2;
if (this.id) {
return;
}
const updateRender = /* @__PURE__ */ __name(() => (0, import_log_update.default)(this.createRender()), "updateRender");
if (!((_a2 = this.options) == null ? void 0 : _a2.lazy)) {
this.id = setInterval(() => {
this.spinner.spin();
updateRender();
}, 100);
}
this.events.on("SHOUD_REFRESH_RENDER" /* SHOULD_REFRESH_RENDER */, () => {
updateRender();
});
}
end() {
clearInterval(this.id);
if (this.id) {
this.id = void 0;
}
import_log_update.default.clear();
import_log_update.default.done();
if (!this.options.clearOutput) {
this.logger.process.stdout(this.createRender({ prompt: false }));
}
}
// eslint-disable-next-line complexity
style(task, data = false) {
var _a2, _b, _c;
var _a, _b, _c;
if (task.isSkipped() && (data || this.getSelfOrParentOption(task, "collapseSkips"))) {

@@ -699,3 +741,3 @@ return color.yellow(figures.arrowDown);

if (task.isStarted()) {
return ((_a2 = this.options) == null ? void 0 : _a2.lazy) || this.getSelfOrParentOption(task, "showSubtasks") !== false && task.hasSubtasks() && !task.subtasks.every((subtask) => !subtask.hasTitle()) ? color.yellow(figures.pointer) : color.yellowBright(this.spinner.fetch());
return ((_a = this.options) == null ? void 0 : _a.lazy) || this.getSelfOrParentOption(task, "showSubtasks") !== false && task.hasSubtasks() && !task.subtasks.every((subtask) => !subtask.hasTitle()) ? color.yellow(figures.pointer) : color.yellowBright(this.spinner.fetch());
} else if (task.isCompleted()) {

@@ -718,6 +760,6 @@ return task.hasSubtasks() && task.subtasks.some((subtask) => subtask.hasFailed()) ? color.yellow(figures.warning) : color.green(figures.tick);

if (message.trim() === "") {
return;
return [];
}
message = `${icon} ${message}`;
let parsedStr;
let parsed;
let columns = process.stdout.columns ? process.stdout.columns : 80;

@@ -727,3 +769,3 @@ columns = columns - level * this.options.indentation - 2;

case "truncate":
parsedStr = message.split(import_os3.EOL).map((s, i) => {
parsed = message.split(import_os3.EOL).map((s, i) => {
return (0, import_cli_truncate.default)(this.indent(s, i), columns);

@@ -733,3 +775,3 @@ });

case "wrap":
parsedStr = (0, import_wrap_ansi.default)(message, columns, { hard: true }).split(import_os3.EOL).map((s, i) => this.indent(s, i));
parsed = (0, import_wrap_ansi.default)(message, columns, { hard: true }).split(import_os3.EOL).map((s, i) => this.indent(s, i));
break;

@@ -740,144 +782,135 @@ default:

if (this.options.removeEmptyLines) {
parsedStr = parsedStr.filter(Boolean);
parsed = parsed.filter(Boolean);
}
return indentString(parsedStr.join(import_os3.EOL), level * this.options.indentation);
return parsed.map((str) => indentString(str, level * this.options.indentation));
}
// eslint-disable-next-line complexity
renderer(tasks, level = 0) {
var _a2, _b, _c;
let output = [];
for (const task of tasks) {
if (task.isEnabled()) {
if (task.hasTitle()) {
if (!(tasks.some((task2) => task2.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) {
if (task.hasFailed() && this.getSelfOrParentOption(task, "collapseErrors")) {
output = [
...output,
this.format(
!task.hasSubtasks() && task.message.error && this.getSelfOrParentOption(task, "showErrorMessage") ? task.message.error : task.title,
this.style(task),
level
)
];
} else if (task.isSkipped() && this.getSelfOrParentOption(task, "collapseSkips")) {
output = [
...output,
this.format(
this.logger.suffix(task.message.skip && this.getSelfOrParentOption(task, "showSkipMessage") ? task.message.skip : task.title, {
data: "SKIPPED" /* SKIPPED */,
condition: this.getSelfOrParentOption(task, "suffixSkips"),
format: color.dim
}),
this.style(task),
level
)
];
} else if (task.isRetrying() && this.getSelfOrParentOption(task, "suffixRetries")) {
output = [
...output,
this.format(
this.logger.suffix(task.title, {
data: `${"RETRY" /* RETRY */}:${task.message.retry.count}`,
format: color.yellow
}),
this.style(task),
level
)
];
} else if (task.isCompleted() && task.hasTitle() && assertFunctionOrSelf((_a2 = this.getSelfOrParentOption(task, "timer")) == null ? void 0 : _a2.condition, task.message.duration)) {
output = [
...output,
this.format(
this.logger.suffix(task == null ? void 0 : task.title, {
...this.getSelfOrParentOption(task, "timer"),
args: [task.message.duration]
}),
this.style(task),
level
)
];
} else {
output = [...output, this.format(task.title, this.style(task), level)];
}
return tasks.flatMap((task) => {
var _a, _b, _c;
const output = [];
if (!task.isEnabled()) {
return [];
}
if (task.hasTitle()) {
if (!(tasks.some((task2) => task2.hasFailed()) && !task.hasFailed() && task.options.exitOnError !== false && !(task.isCompleted() || task.isSkipped()))) {
if (task.hasFailed() && this.getSelfOrParentOption(task, "collapseErrors")) {
output.push(
...this.format(
!task.hasSubtasks() && task.message.error && this.getSelfOrParentOption(task, "showErrorMessage") ? task.message.error : task.title,
this.style(task),
level
)
);
} else if (task.isSkipped() && this.getSelfOrParentOption(task, "collapseSkips")) {
output.push(
...this.format(
this.logger.suffix(task.message.skip && this.getSelfOrParentOption(task, "showSkipMessage") ? task.message.skip : task.title, {
data: "SKIPPED" /* SKIPPED */,
condition: this.getSelfOrParentOption(task, "suffixSkips"),
format: color.dim
}),
this.style(task),
level
)
);
} else if (task.isRetrying() && this.getSelfOrParentOption(task, "suffixRetries")) {
output.push(
...this.format(
this.logger.suffix(task.title, {
data: `${"RETRY" /* RETRY */}:${task.message.retry.count}`,
format: color.yellow
}),
this.style(task),
level
)
);
} else if (task.isCompleted() && task.hasTitle() && assertFunctionOrSelf((_a = this.getSelfOrParentOption(task, "timer")) == null ? void 0 : _a.condition, task.message.duration)) {
output.push(
...this.format(
this.logger.suffix(task == null ? void 0 : task.title, {
...this.getSelfOrParentOption(task, "timer"),
args: [task.message.duration]
}),
this.style(task),
level
)
);
} else {
output = [...output, this.format(task.title, color.red(figures.squareSmallFilled), level)];
output.push(...this.format(task.title, this.style(task), level));
}
} else {
output.push(...this.format(task.title, color.red(figures.squareSmallFilled), level));
}
if (!task.hasSubtasks() || !this.getSelfOrParentOption(task, "showSubtasks")) {
if (task.hasFailed() && this.getSelfOrParentOption(task, "collapseErrors") === false && (this.getSelfOrParentOption(task, "showErrorMessage") || !this.getSelfOrParentOption(task, "showSubtasks"))) {
output = [...output, this.dump(task, level, "FAILED" /* FAILED */)];
} else if (task.isSkipped() && this.getSelfOrParentOption(task, "collapseSkips") === false && (this.getSelfOrParentOption(task, "showSkipMessage") || !this.getSelfOrParentOption(task, "showSubtasks"))) {
output = [...output, this.dump(task, level, "SKIPPED" /* SKIPPED */)];
}
}
if (!task.hasSubtasks() || !this.getSelfOrParentOption(task, "showSubtasks")) {
if (task.hasFailed() && this.getSelfOrParentOption(task, "collapseErrors") === false && (this.getSelfOrParentOption(task, "showErrorMessage") || !this.getSelfOrParentOption(task, "showSubtasks"))) {
output.push(...this.dump(task, level, "FAILED" /* FAILED */));
} else if (task.isSkipped() && this.getSelfOrParentOption(task, "collapseSkips") === false && (this.getSelfOrParentOption(task, "showSkipMessage") || !this.getSelfOrParentOption(task, "showSubtasks"))) {
output.push(...this.dump(task, level, "SKIPPED" /* SKIPPED */));
}
if (task == null ? void 0 : task.output) {
if ((task.isStarted() || task.isRetrying() || task.isRollingBack()) && task.isPrompt()) {
this.promptBar = task.output;
} else if (this.isBottomBar(task) || !task.hasTitle()) {
const data = [this.dump(task, -1)];
if (!this.bottomBar[task.id]) {
this.bottomBar[task.id] = {};
this.bottomBar[task.id].data = [];
const bottomBar = this.getTaskOptions(task).bottomBar;
if (typeof bottomBar === "boolean") {
this.bottomBar[task.id].items = 1;
} else {
this.bottomBar[task.id].items = bottomBar;
}
}
if (task == null ? void 0 : task.output) {
if (task.isPending() && task.isPrompt()) {
this.promptBar = task.output;
} else if (this.isBottomBar(task) || !task.hasTitle()) {
const data = this.dump(task, -1);
if (!this.bottomBar[task.id]) {
this.bottomBar[task.id] = {};
this.bottomBar[task.id].data = [];
const bottomBar = this.getTaskOptions(task).bottomBar;
if (typeof bottomBar === "boolean") {
this.bottomBar[task.id].items = 1;
} else {
this.bottomBar[task.id].items = bottomBar;
}
if (!((_c = (_b = this.bottomBar[task.id]) == null ? void 0 : _b.data) == null ? void 0 : _c.some((element) => data.includes(element))) && !task.isSkipped()) {
this.bottomBar[task.id].data = [...this.bottomBar[task.id].data, ...data];
}
} else if (task.isStarted() || task.isRetrying() || task.isRollingBack() || this.hasPersistentOutput(task)) {
output = [...output, this.dump(task, level)];
}
}
if (
// check if renderer option is on first
this.getSelfOrParentOption(task, "showSubtasks") !== false && // if it doesnt have subtasks no need to check
task.hasSubtasks() && (task.isStarted() || task.hasFailed() || task.isCompleted() && !task.hasTitle() || // have to be completed and have subtasks
task.isCompleted() && this.getSelfOrParentOption(task, "collapse") === false && !task.subtasks.some((subtask) => subtask.rendererOptions.collapse === true) || // if any of the subtasks have the collapse option of
task.subtasks.some((subtask) => subtask.rendererOptions.collapse === false) || // if any of the subtasks has failed
task.subtasks.some((subtask) => subtask.hasFailed()) || // if any of the subtasks rolled back
task.subtasks.some((subtask) => subtask.hasRolledBack()))
) {
const subtaskLevel = !task.hasTitle() ? level : level + 1;
const subtaskRender = this.renderer(task.subtasks, subtaskLevel);
if ((subtaskRender == null ? void 0 : subtaskRender.trim()) !== "") {
output = [...output, subtaskRender];
if (!((_c = (_b = this.bottomBar[task.id]) == null ? void 0 : _b.data) == null ? void 0 : _c.some((element) => data.includes(element))) && !task.isSkipped()) {
this.bottomBar[task.id].data.push(...data);
}
} else if (task.isPending() || this.hasPersistentOutput(task)) {
output.push(...this.dump(task, level));
}
if (task.hasFinalized()) {
this.promptBar = null;
if (!this.hasPersistentOutput(task)) {
delete this.bottomBar[task.id];
}
}
if (
// check if renderer option is on first
this.getSelfOrParentOption(task, "showSubtasks") !== false && // if it doesnt have subtasks no need to check
task.hasSubtasks() && (task.isPending() || task.hasFinalized() && !task.hasTitle() || // have to be completed and have subtasks
task.isCompleted() && this.getSelfOrParentOption(task, "collapse") === false && !task.subtasks.some((subtask) => subtask.rendererOptions.collapse === true) || // if any of the subtasks have the collapse option of
task.subtasks.some((subtask) => subtask.rendererOptions.collapse === false) || // if any of the subtasks has failed
task.subtasks.some((subtask) => subtask.hasFailed()) || // if any of the subtasks rolled back
task.subtasks.some((subtask) => subtask.hasRolledBack()))
) {
const subtaskLevel = !task.hasTitle() ? level : level + 1;
const subtaskRender = this.renderer(task.subtasks, subtaskLevel);
output.push(...subtaskRender);
}
if (task.hasFinalized()) {
this.promptBar = null;
if (!this.hasPersistentOutput(task)) {
delete this.bottomBar[task.id];
}
}
}
output = output.filter(Boolean);
if (output.length > 0) {
return output.join(import_os3.EOL);
} else {
return;
}
return output;
});
}
renderBottomBar() {
if (Object.keys(this.bottomBar).length > 0) {
this.bottomBar = Object.keys(this.bottomBar).reduce((o, key) => {
if (!(o == null ? void 0 : o[key])) {
o[key] = {};
}
o[key] = this.bottomBar[key];
this.bottomBar[key].data = this.bottomBar[key].data.slice(-this.bottomBar[key].items);
o[key].data = this.bottomBar[key].data;
return o;
}, {});
return Object.values(this.bottomBar).reduce((o, value) => o = [...o, ...value.data], []).filter(Boolean).join(import_os3.EOL);
if (Object.keys(this.bottomBar).length === 0) {
return [];
}
this.bottomBar = Object.keys(this.bottomBar).reduce((o, key) => {
if (!(o == null ? void 0 : o[key])) {
o[key] = {};
}
o[key] = this.bottomBar[key];
this.bottomBar[key].data = this.bottomBar[key].data.slice(-this.bottomBar[key].items);
o[key].data = this.bottomBar[key].data;
return o;
}, {});
return Object.values(this.bottomBar).reduce((o, value) => o = [...o, ...value.data], []);
}
renderPrompt() {
if (this.promptBar) {
return this.promptBar;
if (!this.promptBar) {
return [];
}
return [this.promptBar];
}

@@ -898,3 +931,3 @@ dump(task, level, source = "OUTPUT" /* OUTPUT */) {

if (task.hasTitle() && source === "FAILED" /* FAILED */ && data === task.title) {
return;
return [];
}

@@ -904,2 +937,3 @@ if (typeof data === "string") {

}
return [];
}

@@ -927,2 +961,3 @@ indent(str, i) {

lazy: false,
eager: true,
removeEmptyLines: true,

@@ -968,4 +1003,4 @@ formatOutput: "truncate"

getSelfOrParentOption(task, key) {
var _a2, _b;
return ((_a2 = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a2[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
var _a, _b;
return ((_a = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
}

@@ -978,3 +1013,3 @@ renderer(tasks) {

task.on("STATE" /* STATE */, (state) => {
var _a2;
var _a;
if (!task.hasTitle()) {

@@ -992,3 +1027,3 @@ return;

...timer,
condition: !!((_a2 = task.message) == null ? void 0 : _a2.duration) && timer.condition,
condition: !!((_a = task.message) == null ? void 0 : _a.duration) && timer.condition,
args: [task.message.duration]

@@ -1126,3 +1161,3 @@ }

toJson() {
var _a2, _b;
var _a, _b;
return JSON.stringify({

@@ -1132,3 +1167,3 @@ event: this.event,

task: {
title: (_a2 = this.task) == null ? void 0 : _a2.title,
title: (_a = this.task) == null ? void 0 : _a.title,
hasFinalized: (_b = this.task) == null ? void 0 : _b.hasFinalized()

@@ -1161,4 +1196,4 @@ }

getSelfOrParentOption(task, key) {
var _a2, _b;
return ((_a2 = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a2[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
var _a, _b;
return ((_a = task == null ? void 0 : task.rendererOptions) == null ? void 0 : _a[key]) ?? ((_b = this.options) == null ? void 0 : _b[key]);
}

@@ -1168,3 +1203,3 @@ // verbose renderer multi-level

return tasks == null ? void 0 : tasks.forEach((task) => {
var _a2;
var _a;
task.on("SUBTASK" /* SUBTASK */, (subtasks) => {

@@ -1174,3 +1209,3 @@ this.renderer(subtasks);

task.on("STATE" /* STATE */, (state) => {
var _a3;
var _a2;
if (!task.hasTitle()) {

@@ -1188,3 +1223,3 @@ return;

...timer,
condition: !!((_a3 = task.message) == null ? void 0 : _a3.duration) && timer.condition,
condition: !!((_a2 = task.message) == null ? void 0 : _a2.duration) && timer.condition,
args: [task.message.duration]

@@ -1199,3 +1234,3 @@ }

});
if (((_a2 = this.options) == null ? void 0 : _a2.logTitleChange) !== false) {
if (((_a = this.options) == null ? void 0 : _a.logTitleChange) !== false) {
task.on("TITLE" /* TITLE */, (title) => {

@@ -1322,7 +1357,7 @@ this.logger.title(title);

var Task = class extends EventManager {
constructor(listr, tasks, options, rendererOptions) {
var _a2, _b;
constructor(listr, task, options, rendererOptions) {
var _a, _b;
super();
this.listr = listr;
this.tasks = tasks;
this.task = task;
this.options = options;

@@ -1340,6 +1375,7 @@ this.rendererOptions = rendererOptions;

this.message = {};
this.title = (_a2 = this.tasks) == null ? void 0 : _a2.title;
this.initialTitle = (_b = this.tasks) == null ? void 0 : _b.title;
this.task = this.tasks.task;
this.rendererTaskOptions = this.tasks.options;
this.title = (_a = this.task) == null ? void 0 : _a.title;
this.initialTitle = (_b = this.task) == null ? void 0 : _b.title;
this.taskFn = this.task.task;
this.parent = this.listr.parentTask;
this.rendererTaskOptions = this.task.options;
}

@@ -1377,5 +1413,5 @@ set state$(state) {

async check(ctx) {
var _a2;
var _a;
if (this.state === "UNINITIALIZED" /* UNINITIALIZED */) {
this.enabled = await assertFunctionOrSelf(((_a2 = this.tasks) == null ? void 0 : _a2.enabled) ?? true, ctx);
this.enabled = await assertFunctionOrSelf(((_a = this.task) == null ? void 0 : _a.enabled) ?? true, ctx);
this.emit("ENABLED" /* ENABLED */, this.enabled);

@@ -1387,4 +1423,4 @@ this.emitShouldRefreshRender();

hasSubtasks() {
var _a2;
return ((_a2 = this.subtasks) == null ? void 0 : _a2.length) > 0;
var _a;
return ((_a = this.subtasks) == null ? void 0 : _a.length) > 0;
}

@@ -1395,2 +1431,5 @@ /** Returns whether this task is finalized in someform. */

}
isPending() {
return this.isStarted() || this.isRetrying() || this.isRollingBack();
}
/** Returns whether this task is in progress. */

@@ -1438,3 +1477,3 @@ isStarted() {

async run(context, wrapper) {
var _a2, _b, _c, _d, _e, _f;
var _a, _b, _c, _d, _e, _f;
const handleResult = /* @__PURE__ */ __name((result) => {

@@ -1445,3 +1484,3 @@ if (result instanceof Listr) {

this.subtasks = result.tasks;
result.err = this.listr.err;
result.errors = this.listr.errors;
this.emit("SUBTASK" /* SUBTASK */, this.subtasks);

@@ -1475,3 +1514,3 @@ result = result.run(context);

this.state$ = "STARTED" /* STARTED */;
const skipped = await assertFunctionOrSelf(((_a2 = this.tasks) == null ? void 0 : _a2.skip) ?? false, context);
const skipped = await assertFunctionOrSelf(((_a = this.task) == null ? void 0 : _a.skip) ?? false, context);
if (skipped) {

@@ -1489,6 +1528,6 @@ if (typeof skipped === "string") {

try {
const retryCount = ((_b = this.tasks) == null ? void 0 : _b.retry) && ((_c = this.tasks) == null ? void 0 : _c.retry) > 0 ? this.tasks.retry + 1 : 1;
const retryCount = ((_b = this.task) == null ? void 0 : _b.retry) && ((_c = this.task) == null ? void 0 : _c.retry) > 0 ? this.task.retry + 1 : 1;
for (let retries = 1; retries <= retryCount; retries++) {
try {
await handleResult(this.task(context, wrapper));
await handleResult(this.taskFn(context, wrapper));
break;

@@ -1516,7 +1555,7 @@ } catch (err) {

}
if ((_d = this.tasks) == null ? void 0 : _d.rollback) {
if ((_d = this.task) == null ? void 0 : _d.rollback) {
wrapper.report(error, "WILL_ROLLBACK" /* WILL_ROLLBACK */);
try {
this.state$ = "ROLLING_BACK" /* ROLLING_BACK */;
await this.tasks.rollback(context, wrapper);
await this.task.rollback(context, wrapper);
this.message$ = { rollback: this.title };

@@ -1534,3 +1573,3 @@ this.state$ = "ROLLED_BACK" /* ROLLED_BACK */;

this.state$ = "FAILED" /* FAILED */;
if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf((_f = this.tasks) == null ? void 0 : _f.exitOnError, context) !== false) {
if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf((_f = this.task) == null ? void 0 : _f.exitOnError, context) !== false) {
wrapper.report(error, "HAS_FAILED" /* HAS_FAILED */);

@@ -1559,5 +1598,5 @@ throw error;

this.tasks = [];
this.err = [];
this.errors = [];
this.path = [];
var _a2, _b, _c, _d, _e, _f;
var _a, _b, _c, _d, _e, _f, _g;
this.options = {

@@ -1580,3 +1619,7 @@ concurrent: false,

}
if (((_a2 = this.parentTask) == null ? void 0 : _a2.listr.events) instanceof EventManager) {
if (parentTask) {
this.path = [...parentTask.listr.path, parentTask.title];
this.errors = parentTask.listr.errors;
}
if (((_a = this.parentTask) == null ? void 0 : _a.listr.events) instanceof EventManager) {
this.events = this.parentTask.listr.events;

@@ -1594,9 +1637,6 @@ } else {

this.add(task ?? []);
if (parentTask) {
this.path = [...parentTask.listr.path, parentTask.title];
}
if (this.options.registerSignalListeners) {
process.once("SIGINT", () => {
this.tasks.forEach(async (task2) => {
if (task2.isStarted()) {
if (task2.isPending()) {
task2.state$ = "FAILED" /* FAILED */;

@@ -1610,5 +1650,5 @@ }

if ((_d = this.options) == null ? void 0 : _d.disableColor) {
process.env.LISTR_DISABLE_COLOR = "1";
process.env["LISTR_DISABLE_COLOR" /* DISABLE_COLOR */] = "1";
} else if ((_e = this.options) == null ? void 0 : _e.forceColor) {
process.env.FORCE_COLOR = "1";
process.env["FORCE_COLOR" /* FORCE_COLOR */] = "1";
}

@@ -1619,2 +1659,5 @@ if ((_f = this.options) == null ? void 0 : _f.forceTTY) {

}
if ((_g = this.options) == null ? void 0 : _g.forceUnicode) {
process.env["LISTR_FORCE_UNICODE" /* FORCE_UNICODE */] = "1";
}
}

@@ -1628,3 +1671,3 @@ add(task) {

async run(context) {
var _a2;
var _a;
if (!this.renderer) {

@@ -1634,3 +1677,3 @@ this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.events);

await this.renderer.render();
this.ctx = ((_a2 = this.options) == null ? void 0 : _a2.ctx) ?? context ?? {};
this.ctx = ((_a = this.options) == null ? void 0 : _a.ctx) ?? context ?? {};
await Promise.all(this.tasks.map((task) => task.check(this.ctx)));

@@ -1642,3 +1685,3 @@ try {

await task.check(this.ctx);
return this.runTask(task, this.ctx, this.err);
return this.runTask(task, this.ctx);
},

@@ -1656,7 +1699,7 @@ { concurrency: this.concurrency }

}
runTask(task, context, errors) {
runTask(task, context) {
if (!task.isEnabled()) {
return Promise.resolve();
}
return new TaskWrapper(task, errors, this.options).run(context);
return new TaskWrapper(task, this.options).run(context);
}

@@ -1709,3 +1752,3 @@ };

const ctx = await task.run();
this.err = task.err;
this.err = task.errors;
return ctx;

@@ -1733,2 +1776,3 @@ }

Listr,
ListrEnvironmentVariables,
ListrError,

@@ -1765,3 +1809,4 @@ ListrErrorTypes,

parseTaskTime,
parseTimestamp
parseTimestamp,
splat
});
{
"name": "listr2",
"version": "6.0.0-beta.2",
"version": "6.0.0-beta.3",
"description": "Terminal task list reborn! Create beautiful CLI interfaces via easy and logical to implement task lists that feel alive and interactive.",

@@ -82,6 +82,6 @@ "license": "MIT",

"@cenk1cenk2/cz-cc": "^1.5.9",
"@cenk1cenk2/eslint-config": "2.6.0",
"@cenk1cenk2/eslint-config": "2.6.1",
"@types/clone": "^2.1.1",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.15",
"@types/node": "^18.15.1",
"@types/through": "^0.0.30",

@@ -88,0 +88,0 @@ "@types/wrap-ansi": "^3.0.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc