Comparing version 5.0.1 to 5.0.2
@@ -48,7 +48,7 @@ // src/listr.ts | ||
this.path = [...task.listr.path ?? [], task.title].join(" > "); | ||
if (task?.options.collectErrors === "full") { | ||
if ((task == null ? void 0 : task.options.collectErrors) === "full") { | ||
this.task = cloneObject(task); | ||
this.ctx = cloneObject(task.listr.ctx); | ||
} | ||
this.stack = error?.stack; | ||
this.stack = error == null ? void 0 : error.stack; | ||
} | ||
@@ -88,3 +88,4 @@ }; | ||
import { createColors } from "colorette"; | ||
var colorette_default = createColors({ useColor: process.env?.LISTR_DISABLE_COLOR !== "1" }); | ||
var _a; | ||
var colorette_default = createColors({ useColor: ((_a = process.env) == null ? void 0 : _a.LISTR_DISABLE_COLOR) !== "1" }); | ||
@@ -170,3 +171,4 @@ // src/utils/is-unicode-supported.ts | ||
getSelfOrParentOption(task, key) { | ||
return task?.rendererOptions?.[key] ?? this.options?.[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]); | ||
} | ||
@@ -189,9 +191,9 @@ getTaskTime(task) { | ||
const renderPrompt = this.renderPrompt(); | ||
if (options.tasks && renderTasks?.trim().length > 0) { | ||
if (options.tasks && (renderTasks == null ? void 0 : renderTasks.trim().length) > 0) { | ||
render.push(renderTasks); | ||
} | ||
if (options.bottomBar && renderBottomBar?.trim().length > 0) { | ||
if (options.bottomBar && (renderBottomBar == null ? void 0 : renderBottomBar.trim().length) > 0) { | ||
render.push((render.length > 0 ? EOL : "") + renderBottomBar); | ||
} | ||
if (options.prompt && renderPrompt?.trim().length > 0) { | ||
if (options.prompt && (renderPrompt == null ? void 0 : renderPrompt.trim().length) > 0) { | ||
render.push((render.length > 0 ? EOL : "") + renderPrompt); | ||
@@ -202,2 +204,3 @@ } | ||
render() { | ||
var _a2; | ||
if (this.id) { | ||
@@ -207,3 +210,3 @@ return; | ||
const updateRender = () => logUpdate(this.createRender()); | ||
if (!this.options?.lazy) { | ||
if (!((_a2 = this.options) == null ? void 0 : _a2.lazy)) { | ||
this.id = setInterval(() => { | ||
@@ -230,2 +233,3 @@ this.spinnerPosition = ++this.spinnerPosition % this.spinner.length; | ||
multiLineRenderer(tasks, level = 0) { | ||
var _a2, _b; | ||
let output = []; | ||
@@ -261,3 +265,3 @@ for (const task of tasks) { | ||
} else if (task.isCompleted() && task.hasTitle() && (this.getSelfOrParentOption(task, "showTimer") || this.hasTimer(task))) { | ||
output = [...output, this.formatString(`${task?.title} ${this.getTaskTime(task)}`, this.getSymbol(task), level)]; | ||
output = [...output, this.formatString(`${task == null ? void 0 : task.title} ${this.getTaskTime(task)}`, this.getSymbol(task), level)]; | ||
} else { | ||
@@ -277,3 +281,3 @@ output = [...output, this.formatString(task.title, this.getSymbol(task), level)]; | ||
} | ||
if (task?.output) { | ||
if (task == null ? void 0 : task.output) { | ||
if ((task.isPending() || task.isRetrying() || task.isRollingBack()) && task.isPrompt()) { | ||
@@ -293,3 +297,3 @@ this.promptBar = task.output; | ||
} | ||
if (!this.bottomBar[task.id]?.data?.some((element) => data.includes(element)) && !task.isSkipped()) { | ||
if (!((_b = (_a2 = this.bottomBar[task.id]) == null ? void 0 : _a2.data) == null ? void 0 : _b.some((element) => data.includes(element))) && !task.isSkipped()) { | ||
this.bottomBar[task.id].data = [...this.bottomBar[task.id].data, ...data]; | ||
@@ -304,3 +308,3 @@ } | ||
const subtaskRender = this.multiLineRenderer(task.subtasks, subtaskLevel); | ||
if (subtaskRender?.trim() !== "" && !task.subtasks.every((subtask) => !subtask.hasTitle())) { | ||
if ((subtaskRender == null ? void 0 : subtaskRender.trim()) !== "" && !task.subtasks.every((subtask) => !subtask.hasTitle())) { | ||
output = [...output, subtaskRender]; | ||
@@ -327,3 +331,3 @@ } | ||
this.bottomBar = Object.keys(this.bottomBar).reduce((o, key) => { | ||
if (!o?.[key]) { | ||
if (!(o == null ? void 0 : o[key])) { | ||
o[key] = {}; | ||
@@ -393,10 +397,11 @@ } | ||
getSymbol(task, data = false) { | ||
var _a2, _b, _c; | ||
if (task.isPending() && !data) { | ||
return this.options?.lazy || this.getSelfOrParentOption(task, "showSubtasks") !== false && task.hasSubtasks() && !task.subtasks.every((subtask) => !subtask.hasTitle()) ? colorette_default.yellow(figures.pointer) : colorette_default.yellowBright(this.spinner[this.spinnerPosition]); | ||
return ((_a2 = this.options) == null ? void 0 : _a2.lazy) || this.getSelfOrParentOption(task, "showSubtasks") !== false && task.hasSubtasks() && !task.subtasks.every((subtask) => !subtask.hasTitle()) ? colorette_default.yellow(figures.pointer) : colorette_default.yellowBright(this.spinner[this.spinnerPosition]); | ||
} else if (task.isCompleted() && !data) { | ||
return task.hasSubtasks() && task.subtasks.some((subtask) => subtask.hasFailed()) ? colorette_default.yellow(figures.warning) : colorette_default.green(figures.tick); | ||
} else if (task.isRetrying() && !data) { | ||
return this.options?.lazy ? colorette_default.yellow(figures.warning) : colorette_default.yellow(this.spinner[this.spinnerPosition]); | ||
return ((_b = this.options) == null ? void 0 : _b.lazy) ? colorette_default.yellow(figures.warning) : colorette_default.yellow(this.spinner[this.spinnerPosition]); | ||
} else if (task.isRollingBack() && !data) { | ||
return this.options?.lazy ? colorette_default.red(figures.warning) : colorette_default.red(this.spinner[this.spinnerPosition]); | ||
return ((_c = this.options) == null ? void 0 : _c.lazy) ? colorette_default.red(figures.warning) : colorette_default.red(this.spinner[this.spinnerPosition]); | ||
} else if (task.hasRolledBack() && !data) { | ||
@@ -500,3 +505,3 @@ return colorette_default.red(figures.arrowLeft); | ||
static formatTitle(task) { | ||
return task?.title ? ` ${task.title}` : ""; | ||
return (task == null ? void 0 : task.title) ? ` ${task.title}` : ""; | ||
} | ||
@@ -518,6 +523,7 @@ log(output) { | ||
render(tasks) { | ||
if (tasks?.length) { | ||
if (tasks == null ? void 0 : tasks.length) { | ||
tasks.forEach((task) => { | ||
task.subscribe((event) => { | ||
this.eventTypeRendererMap[event.type]?.(task, event); | ||
var _a2, _b; | ||
(_b = (_a2 = this.eventTypeRendererMap)[event.type]) == null ? void 0 : _b.call(_a2, task, event); | ||
}, this.log); | ||
@@ -602,2 +608,3 @@ }); | ||
logColoring({ level, message }) { | ||
var _a2, _b, _c, _d, _e, _f, _g, _h; | ||
let icon; | ||
@@ -609,3 +616,3 @@ let coloring = (input) => { | ||
case "FAILED" /* FAILED */: | ||
if (this.options?.useIcons) { | ||
if ((_a2 = this.options) == null ? void 0 : _a2.useIcons) { | ||
coloring = colorette_default.red; | ||
@@ -618,3 +625,3 @@ icon = figures.cross; | ||
case "SKIPPED" /* SKIPPED */: | ||
if (this.options?.useIcons) { | ||
if ((_b = this.options) == null ? void 0 : _b.useIcons) { | ||
coloring = colorette_default.yellow; | ||
@@ -627,3 +634,3 @@ icon = figures.arrowDown; | ||
case "SUCCESS" /* SUCCESS */: | ||
if (this.options?.useIcons) { | ||
if ((_c = this.options) == null ? void 0 : _c.useIcons) { | ||
coloring = colorette_default.green; | ||
@@ -636,3 +643,3 @@ icon = figures.tick; | ||
case "DATA" /* DATA */: | ||
if (this.options?.useIcons) { | ||
if ((_d = this.options) == null ? void 0 : _d.useIcons) { | ||
icon = figures.arrowRight; | ||
@@ -644,3 +651,3 @@ } else { | ||
case "STARTED" /* STARTED */: | ||
if (this.options?.useIcons) { | ||
if ((_e = this.options) == null ? void 0 : _e.useIcons) { | ||
icon = figures.pointer; | ||
@@ -652,3 +659,3 @@ } else { | ||
case "TITLE" /* TITLE */: | ||
if (this.options?.useIcons) { | ||
if ((_f = this.options) == null ? void 0 : _f.useIcons) { | ||
icon = figures.checkboxOn; | ||
@@ -660,3 +667,3 @@ } else { | ||
case "RETRY" /* RETRY */: | ||
if (this.options?.useIcons) { | ||
if ((_g = this.options) == null ? void 0 : _g.useIcons) { | ||
coloring = colorette_default.yellow; | ||
@@ -669,3 +676,3 @@ icon = figures.pointer; | ||
case "ROLLBACK" /* ROLLBACK */: | ||
if (this.options?.useIcons) { | ||
if ((_h = this.options) == null ? void 0 : _h.useIcons) { | ||
coloring = colorette_default.red; | ||
@@ -690,8 +697,9 @@ icon = figures.arrowLeft; | ||
this.options = options; | ||
if (this.options?.logger && this.options?.options) { | ||
var _a2, _b, _c, _d; | ||
if (((_a2 = this.options) == null ? void 0 : _a2.logger) && ((_b = this.options) == null ? void 0 : _b.options)) { | ||
this.logger = new this.options.logger(this.options.options); | ||
} else if (this.options?.logger) { | ||
} else if ((_c = this.options) == null ? void 0 : _c.logger) { | ||
this.logger = new this.options.logger(); | ||
} else { | ||
this.logger = new Logger({ useIcons: this.options?.useIcons }); | ||
this.logger = new Logger({ useIcons: (_d = this.options) == null ? void 0 : _d.useIcons }); | ||
} | ||
@@ -706,5 +714,6 @@ this.options = { ..._VerboseRenderer.rendererOptions, ...this.options }; | ||
verboseRenderer(tasks) { | ||
return tasks?.forEach((task) => { | ||
return tasks == null ? void 0 : tasks.forEach((task) => { | ||
task.subscribe( | ||
(event) => { | ||
var _a2, _b, _c, _d, _e, _f, _g, _h; | ||
if (task.isEnabled()) { | ||
@@ -715,7 +724,7 @@ const taskTitle = task.hasTitle() ? task.title : "Task without title."; | ||
} else if (event.type === "STATE" /* STATE */) { | ||
if (this.options?.logEmptyTitle !== false || task.hasTitle()) { | ||
if (((_a2 = this.options) == null ? void 0 : _a2.logEmptyTitle) !== false || task.hasTitle()) { | ||
if (task.isPending()) { | ||
this.logger.start(taskTitle); | ||
} else if (task.isCompleted()) { | ||
this.logger.success(taskTitle + (this.options?.showTimer && task.message?.duration ? ` [${parseTaskTime(task.message.duration)}]` : "")); | ||
this.logger.success(taskTitle + (((_b = this.options) == null ? void 0 : _b.showTimer) && ((_c = task.message) == null ? void 0 : _c.duration) ? ` [${parseTaskTime(task.message.duration)}]` : "")); | ||
} | ||
@@ -726,13 +735,13 @@ } | ||
} else if (event.type === "TITLE" /* TITLE */) { | ||
if (this.options?.logTitleChange !== false) { | ||
if (((_d = this.options) == null ? void 0 : _d.logTitleChange) !== false) { | ||
this.logger.title(String(event.data)); | ||
} | ||
} else if (event.type === "MESSAGE" /* MESSAGE */) { | ||
if (event.data?.error) { | ||
if ((_e = event.data) == null ? void 0 : _e.error) { | ||
this.logger.fail(String(event.data.error)); | ||
} else if (event.data?.skip) { | ||
} else if ((_f = event.data) == null ? void 0 : _f.skip) { | ||
this.logger.skip(String(event.data.skip)); | ||
} else if (event.data?.rollback) { | ||
} else if ((_g = event.data) == null ? void 0 : _g.rollback) { | ||
this.logger.rollback(String(event.data.rollback)); | ||
} else if (event.data?.retry) { | ||
} else if ((_h = event.data) == null ? void 0 : _h.retry) { | ||
this.logger.retry(`[${event.data.retry.count}] ` + String(taskTitle)); | ||
@@ -802,2 +811,3 @@ } | ||
constructor(listr, tasks, options, rendererOptions) { | ||
var _a2, _b, _c, _d; | ||
super(); | ||
@@ -810,7 +820,7 @@ this.listr = listr; | ||
this.id = generateUUID(); | ||
this.title = this.tasks?.title; | ||
this.initialTitle = this.tasks?.title; | ||
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.skip = this.tasks?.skip ?? false; | ||
this.enabledFn = this.tasks?.enabled ?? true; | ||
this.skip = ((_c = this.tasks) == null ? void 0 : _c.skip) ?? false; | ||
this.enabledFn = ((_d = this.tasks) == null ? void 0 : _d.enabled) ?? true; | ||
this.rendererTaskOptions = this.tasks.options; | ||
@@ -867,3 +877,4 @@ this.renderHook$ = this.listr.renderHook$; | ||
hasSubtasks() { | ||
return this.subtasks?.length > 0; | ||
var _a2; | ||
return ((_a2 = this.subtasks) == null ? void 0 : _a2.length) > 0; | ||
} | ||
@@ -895,3 +906,3 @@ isPending() { | ||
hasTitle() { | ||
return typeof this?.title === "string"; | ||
return typeof (this == null ? void 0 : this.title) === "string"; | ||
} | ||
@@ -902,2 +913,3 @@ isPrompt() { | ||
async run(context, wrapper) { | ||
var _a2, _b, _c, _d, _e; | ||
const handleResult = (result) => { | ||
@@ -953,3 +965,3 @@ if (result instanceof Listr) { | ||
try { | ||
const retryCount = this.tasks?.retry && this.tasks?.retry > 0 ? this.tasks.retry + 1 : 1; | ||
const retryCount = ((_a2 = this.tasks) == null ? void 0 : _a2.retry) && ((_b = this.tasks) == null ? void 0 : _b.retry) > 0 ? this.tasks.retry + 1 : 1; | ||
for (let retries = 1; retries <= retryCount; retries++) { | ||
@@ -980,3 +992,3 @@ try { | ||
} | ||
if (this.tasks?.rollback) { | ||
if ((_c = this.tasks) == null ? void 0 : _c.rollback) { | ||
wrapper.report(error, "WILL_ROLLBACK" /* WILL_ROLLBACK */); | ||
@@ -993,3 +1005,3 @@ try { | ||
} | ||
if (this.listr.options?.exitAfterRollback !== false) { | ||
if (((_d = this.listr.options) == null ? void 0 : _d.exitAfterRollback) !== false) { | ||
throw new Error(this.title); | ||
@@ -999,3 +1011,3 @@ } | ||
this.state$ = "FAILED" /* FAILED */; | ||
if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf(this.tasks?.exitOnError, context) !== false) { | ||
if (this.listr.options.exitOnError !== false && await assertFunctionOrSelf((_e = this.tasks) == null ? void 0 : _e.exitOnError, context) !== false) { | ||
wrapper.report(error, "HAS_FAILED" /* HAS_FAILED */); | ||
@@ -1025,3 +1037,3 @@ throw error; | ||
this.task.prompt = new PromptError(errorMsg); | ||
} else if (settings?.error !== false) { | ||
} else if ((settings == null ? void 0 : settings.error) !== false) { | ||
throw new Error(errorMsg); | ||
@@ -1034,3 +1046,3 @@ } else { | ||
let cancelCallback; | ||
if (settings?.cancelCallback) { | ||
if (settings == null ? void 0 : settings.cancelCallback) { | ||
cancelCallback = settings.cancelCallback; | ||
@@ -1051,3 +1063,3 @@ } else { | ||
Object.assign(option, { | ||
stdout: this instanceof TaskWrapper ? settings?.stdout ?? this.stdout() : process.stdout, | ||
stdout: this instanceof TaskWrapper ? (settings == null ? void 0 : settings.stdout) ?? this.stdout() : process.stdout, | ||
onCancel: cancelCallback.bind(this, settings) | ||
@@ -1058,3 +1070,3 @@ }) | ||
let enquirer; | ||
if (settings?.enquirer) { | ||
if (settings == null ? void 0 : settings.enquirer) { | ||
enquirer = settings.enquirer; | ||
@@ -1127,11 +1139,13 @@ } else { | ||
report(error, type) { | ||
var _a2; | ||
if (this.task.options.collectErrors !== false) { | ||
this.errors.push(new ListrError(error, type, this.task)); | ||
} | ||
this.task.message$ = { error: error.message ?? this.task?.title ?? "Task with no title." }; | ||
this.task.message$ = { error: error.message ?? ((_a2 = this.task) == null ? void 0 : _a2.title) ?? "Task with no title." }; | ||
} | ||
skip(message) { | ||
var _a2; | ||
this.task.state$ = "SKIPPED" /* SKIPPED */; | ||
if (message) { | ||
this.task.message$ = { skip: message ?? this.task?.title ?? "Task with no title." }; | ||
this.task.message$ = { skip: message ?? ((_a2 = this.task) == null ? void 0 : _a2.title) ?? "Task with no title." }; | ||
} | ||
@@ -1143,3 +1157,4 @@ } | ||
async prompt(options) { | ||
return createPrompt.bind(this)(options, { ...this.options?.injectWrapper }); | ||
var _a2; | ||
return createPrompt.bind(this)(options, { ...(_a2 = this.options) == null ? void 0 : _a2.injectWrapper }); | ||
} | ||
@@ -1174,2 +1189,3 @@ cancelPrompt(throwError = false) { | ||
this.path = []; | ||
var _a2, _b, _c; | ||
this.options = { | ||
@@ -1194,3 +1210,3 @@ ...{ | ||
} | ||
const renderer = getRenderer(this.options.renderer, this.options.nonTTYRenderer, this.options?.rendererFallback, this.options?.rendererSilent); | ||
const renderer = getRenderer(this.options.renderer, this.options.nonTTYRenderer, (_a2 = this.options) == null ? void 0 : _a2.rendererFallback, (_b = this.options) == null ? void 0 : _b.rendererSilent); | ||
this.rendererClass = renderer.renderer; | ||
@@ -1217,3 +1233,3 @@ if (!renderer.nonTTY) { | ||
} | ||
if (this.options?.disableColor) { | ||
if ((_c = this.options) == null ? void 0 : _c.disableColor) { | ||
process.env.LISTR_DISABLE_COLOR = "1"; | ||
@@ -1229,2 +1245,3 @@ } | ||
async run(context) { | ||
var _a2; | ||
if (!this.renderer) { | ||
@@ -1234,3 +1251,3 @@ this.renderer = new this.rendererClass(this.tasks, this.rendererClassOptions, this.renderHook$); | ||
this.renderer.render(); | ||
this.ctx = this.options?.ctx ?? context ?? {}; | ||
this.ctx = ((_a2 = this.options) == null ? void 0 : _a2.ctx) ?? context ?? {}; | ||
await this.checkAll(this.ctx); | ||
@@ -1237,0 +1254,0 @@ try { |
{ | ||
"name": "listr2", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Terminal task list reborn! Create beautiful CLI interfaces via easy and logical to implement task lists that feel alive and interactive.", | ||
@@ -91,3 +91,3 @@ "license": "MIT", | ||
"enquirer": "^2.3.6", | ||
"eslint": "^8.20.0", | ||
"eslint": "^8.21.0", | ||
"jest": "^28.1.3", | ||
@@ -102,4 +102,4 @@ "jest-mock-process": "^2.0.0", | ||
"tsconfig-paths": "^4.0.0", | ||
"tsup": "6.2.0", | ||
"typedoc": "^0.23.9", | ||
"tsup": "6.2.1", | ||
"typedoc": "^0.23.10", | ||
"typedoc-plugin-markdown": "^3.13.4", | ||
@@ -106,0 +106,0 @@ "typescript": "^4.7.4" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
135641
3527