Skip to content

Commit 3731f10

Browse files
committed
refactor: replace "for...of" with "await Promise.all()"
1 parent 1c94c27 commit 3731f10

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

lib/runAll.js

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -142,52 +142,51 @@ export const runAll = async (
142142
}
143143

144144
for (const [index, files] of stagedFileChunks.entries()) {
145-
const chunkTasks = generateTasks({ config, cwd, files, relative })
146-
const chunkListrTasks = []
147-
148-
for (const task of chunkTasks) {
149-
const subTasks = await makeCmdTasks({
150-
commands: task.commands,
151-
cwd,
152-
files: task.fileList,
153-
gitDir,
154-
renderer: listrOptions.renderer,
155-
shell,
156-
verbose,
157-
})
158-
159-
// Add files from task to match set
160-
task.fileList.forEach((file) => {
161-
matchedFiles.add(file)
162-
})
163-
164-
hasDeprecatedGitAdd =
165-
hasDeprecatedGitAdd || subTasks.some((subTask) => subTask.command === 'git add')
166-
167-
const fileCount = task.fileList.length
168-
169-
chunkListrTasks.push({
170-
title: `${task.pattern}${dim(` — ${fileCount} ${fileCount > 1 ? 'files' : 'file'}`)}`,
171-
task: async () =>
172-
new Listr(subTasks, {
173-
// In sub-tasks we don't want to run concurrently
174-
// and we want to abort on errors
175-
...listrOptions,
176-
concurrent: false,
177-
exitOnError: true,
178-
}),
179-
skip: () => {
180-
// Skip task when no files matched
181-
if (fileCount === 0) {
182-
return `${task.pattern}${dim(' — no files')}`
183-
}
184-
return false
185-
},
186-
})
187-
}
188-
189145
const relativeConfig = normalize(path.relative(cwd, configPath))
190146

147+
const chunkListrTasks = await Promise.all(
148+
generateTasks({ config, cwd, files, relative }).map((task) =>
149+
makeCmdTasks({
150+
commands: task.commands,
151+
cwd,
152+
files: task.fileList,
153+
gitDir,
154+
renderer: listrOptions.renderer,
155+
shell,
156+
verbose,
157+
}).then((subTasks) => {
158+
// Add files from task to match set
159+
task.fileList.forEach((file) => {
160+
matchedFiles.add(file)
161+
})
162+
163+
hasDeprecatedGitAdd =
164+
hasDeprecatedGitAdd || subTasks.some((subTask) => subTask.command === 'git add')
165+
166+
const fileCount = task.fileList.length
167+
168+
return {
169+
title: `${task.pattern}${dim(` — ${fileCount} ${fileCount > 1 ? 'files' : 'file'}`)}`,
170+
task: async () =>
171+
new Listr(subTasks, {
172+
// In sub-tasks we don't want to run concurrently
173+
// and we want to abort on errors
174+
...listrOptions,
175+
concurrent: false,
176+
exitOnError: true,
177+
}),
178+
skip: () => {
179+
// Skip task when no files matched
180+
if (fileCount === 0) {
181+
return `${task.pattern}${dim(' — no files')}`
182+
}
183+
return false
184+
},
185+
}
186+
})
187+
)
188+
)
189+
191190
listrTasks.push({
192191
title:
193192
`${relativeConfig}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +

0 commit comments

Comments
 (0)