spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / sec-default / tests / fixtures / caught / handlers-registered.ts
30 lines · 805 BRaw
1import Hooks from '../../../hooks'
2
3/**
4 * What the plugin registers, read off its own `register`: each event's
5 * hook and its `.catch`, as the engine would call them.
6 *
7 * @returns `(event, part) => function`; it throws where there is none
8 */
9export function handlersRegistered() {
10 const registered = new Map<string, unknown>()
11
12 Hooks.register((event: string, ...rest: unknown[]) => {
13 registered.set(`${event} hook`, rest.at(-1))
14
15 return {
16 catch: (handler: unknown) =>
17 void registered.set(`${event} catch`, handler),
18 }
19 })
20
21 return (event: string, part: 'hook' | 'catch' = 'catch') => {
22 const handler = registered.get(`${event} ${part}`)
23
24 if (typeof handler !== 'function') {
25 throw new Error(`${event} carries no ${part}`)
26 }
27
28 return handler
29 }
30}