xinyuehtx/dsh-plugin-hooks-ordering ↗★ 0
@tengxiaohtx/dsh-plugin-hooks-ordering
Deterministic before/after ordering for Cordis waterfall hooks, contributed across independent plugins
AI Analysis
核心用途是解决多插件场景下的钩子执行冲突与竞争问题。适合 DSH 插件开发者,用于确保特定生命周期钩子(如请求组装)按预期顺序执行。
Install
This plugin has no verified bundle, or compatibility checks failed. Read the repository notes first. Read the full README ↗
README
Read the full 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.