Skip to content

Commit 4384114

Browse files
committed
refactor: reuse Listr stuff better
1 parent f27f1d4 commit 4384114

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/runAll.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,12 @@ export const runAll = async (
206206
title: `${task.pattern}${dim(
207207
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
208208
)}`,
209-
task: async () =>
210-
new Listr(subTasks, {
211-
// In sub-tasks we don't want to run concurrently
212-
// and we want to abort on errors
213-
...listrOptions,
214-
concurrent: false,
215-
exitOnError: true,
216-
}),
209+
task: async (ctx, task) =>
210+
task.newListr(
211+
subTasks,
212+
// Subtasks should not run in parallel, and should exit on error
213+
{ concurrent: false, exitOnError: true }
214+
),
217215
skip: () => {
218216
// Skip task when no files matched
219217
if (fileCount === 0) {
@@ -230,7 +228,7 @@ export const runAll = async (
230228
title:
231229
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
232230
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
233-
task: () => new Listr(chunkListrTasks, { ...listrOptions, concurrent, exitOnError: true }),
231+
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
234232
skip: () => {
235233
// Skip if the first step (backup) failed
236234
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
@@ -279,7 +277,7 @@ export const runAll = async (
279277
},
280278
{
281279
title: `Running tasks for staged files...`,
282-
task: () => new Listr(listrTasks, { ...listrOptions, concurrent }),
280+
task: (ctx, task) => task.newListr(listrTasks, { concurrent }),
283281
skip: () => listrTasks.every((task) => task.skip()),
284282
},
285283
{

test/runAll.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ describe('runAll', () => {
234234
LOG [STARTED] echo \\"sample\\"
235235
ERROR [FAILED] echo \\"sample\\" [1]
236236
ERROR [FAILED] echo \\"sample\\" [1]
237-
LOG [SUCCESS] Running tasks for staged files...
237+
ERROR [FAILED] echo \\"sample\\" [1]
238238
LOG [STARTED] Applying modifications from tasks...
239239
INFO [SKIPPED] Skipped because of errors from tasks.
240240
LOG [STARTED] Reverting to original state because of errors...
@@ -273,7 +273,7 @@ describe('runAll', () => {
273273
LOG [STARTED] echo \\"sample\\"
274274
ERROR [FAILED] echo \\"sample\\" [KILLED]
275275
ERROR [FAILED] echo \\"sample\\" [KILLED]
276-
LOG [SUCCESS] Running tasks for staged files...
276+
ERROR [FAILED] echo \\"sample\\" [KILLED]
277277
LOG [STARTED] Applying modifications from tasks...
278278
INFO [SKIPPED] Skipped because of errors from tasks.
279279
LOG [STARTED] Reverting to original state because of errors...

0 commit comments

Comments
 (0)