Skip to content

Commit 34abf7c

Browse files
authored
feat: parallelize runHook (#253)
1 parent 49356a6 commit 34abf7c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/config/config.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ export class Config implements IConfig {
225225
})
226226
}
227227

228-
const successes = []
229-
const failures = []
230-
231-
for (const p of this.plugins) {
228+
const final = {
229+
successes: [],
230+
failures: [],
231+
} as Hook.Result<Hooks[T]['return']>
232+
const promises = this.plugins.map(async p => {
232233
const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'))
233234
const context: Hook.Context = {
234235
config: this,
@@ -259,18 +260,21 @@ export class Config implements IConfig {
259260
const result = timeout ?
260261
await withTimeout(timeout, search(module).call(context, {...opts as any, config: this})) :
261262
await search(module).call(context, {...opts as any, config: this})
262-
successes.push({plugin: p, result})
263+
final.successes.push({plugin: p, result})
263264

264265
debug('done')
265266
} catch (error) {
266-
failures.push({plugin: p, error: error as Error})
267-
if (error && error.oclif && error.oclif.exit !== undefined) throw error
267+
final.failures.push({plugin: p, error: error as Error})
268+
debug(error)
268269
}
269270
}
270-
}
271+
})
272+
273+
await Promise.all(promises)
271274

272275
debug('%s hook done', event)
273-
return {successes, failures}
276+
277+
return final
274278
}
275279

276280
async runCommand<T = unknown>(id: string, argv: string[] = [], cachedCommand?: Command.Plugin): Promise<T> {

0 commit comments

Comments
 (0)