xinyuehtx/dsh-plugin-hooks-ordering ↗★ 0
@tengxiaohtx/dsh-plugin-hooks-ordering
Deterministic before/after ordering for Cordis waterfall hooks, contributed across independent plugins
AI 분석
核心用途是解决多插件场景下的钩子执行冲突与竞争问题。适合 DSH 插件开发者,用于确保特定生命周期钩子(如请求组装)按预期顺序执行。
설치
검증된 bundle이 없거나 호환성 검사에 실패했습니다. 먼저 저장소 설명을 읽어 주세요. 전체 README 읽기 ↗
Usage
import HookOrdering from '@tengxiaohtx/dsh-plugin-hooks-ordering'
ctx.plugin(HookOrdering)
// The hook owner (or app composition) takes control ONCE. This installs the
// single bracket listener; controlling twice throws, so the prepend race
// cannot come back.
ctx.hooksOrdering.control('request/assemble')
// Vendor A — names only its own constraint, imports nothing from vendor B.
ctx.hooksOrdering.register('request/assemble', 'front', {
name: 'auth',
before: ['logging'],
run: (req) => authenticate(req),
})
// Vendor B — a different package, unaware of A.
ctx.hooksOrdering.register('request/assemble', 'front', {
name: 'logging',
run: (req) => log(req),
})
// Vendor C — must run after everything, even the host default.
ctx.hooksOrdering.register('request/assemble', 'back', {
name: 'metrics',
run: (req) => emitMetrics(req),
})
Regardless of the order these three plugins load or register, auth runs before logging, and metrics runs last.