Skip to content

Commit

Permalink
feat: return results from runHook (#187)
Browse files Browse the repository at this point in the history
* feat: return results from runHook

* build: remove windows build for now
  • Loading branch information
mdonnalley authored Jun 28, 2021
1 parent 857c8f3 commit 5355203
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workflows:
parameters:
os:
- linux
- windows
# - windows
node_version:
- latest
- lts
Expand Down
10 changes: 5 additions & 5 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,14 @@ export class Config implements IConfig {
}
}

async runHook<T>(event: string, opts: T) {
async runHook<T>(event: string, opts: T): Promise<any> {
debug('start %s hook', event)

const search = (m: any): Hook<T> => {
if (typeof m === 'function') return m
if (m.default && typeof m.default === 'function') return m.default
return Object.values(m).find((m: any) => typeof m === 'function') as Hook<T>
}

const results = []
for (const p of this.plugins) {
const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'))
const context: Hook.Context = {
Expand Down Expand Up @@ -242,8 +241,8 @@ export class Config implements IConfig {

debug('start', isESM ? '(import)' : '(require)', filePath)

await search(module).call(context, {...opts as any, config: this})
/* eslint-enable no-await-in-loop */
const result = await search(module).call(context, {...opts as any, config: this})
results.push(result)

debug('done')
} catch (error) {
Expand All @@ -254,6 +253,7 @@ export class Config implements IConfig {
}

debug('%s hook done', event)
return results
}

async runCommand<T = unknown>(id: string, argv: string[] = [], cachedCommand?: Command.Plugin): Promise<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface Config {

runCommand<T = unknown>(id: string, argv?: string[]): Promise<T>;
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Plugin): Promise<T>;
runHook<T extends Hooks, K extends Extract<keyof T, string>>(event: K, opts: T[K]): Promise<void>;
runHook<T extends Hooks, K extends Extract<keyof T, string>>(event: K, opts: T[K]): Promise<any>;
findCommand(id: string, opts: { must: true }): Command.Plugin;
findCommand(id: string, opts?: { must: boolean }): Command.Plugin | undefined;
findTopic(id: string, opts: { must: true }): Topic;
Expand Down

0 comments on commit 5355203

Please sign in to comment.