Repository navigation
feat: plugin model for drivers and the console - #27
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a plugin model on top of the existing
Hookregistry, so packages and apps can extend the driver setup and thearkconsole without editing core files. This is the first "Next priorities" item in the roadmap.Hook
Hook.listen(name, positions)adds callbacks next to theHook.on()one instead of replacing it, and returns a function that removes them.Hook.emit()runs theon()callback, then thelisten()callbacks in order, awaiting each async one. It still returns the first callback's result, so existing callers behave the same.has(),off()andclear()coverlisten()callbacks too.Plugins (
@arkstack/foundry, re-exported by@arkstack/common)ArkstackPluginbase class withname,drivers,hooks(),commands()andregister().Pluginsregistry:use,has,get,all,commands,remove,clear,assertSupports. Installing the same name twice is a no-op. Plugin hooks go throughHook.listen().HookMaptype sohooks(): HookMapgets typed callbacks fromHookRegistry.Drivers (
@arkstack/contract)ArkstackKitDriver.prepare(app, { publicPath, middleware })runs assets, middleware, routes and the error handler, and fires the newdriver:preparehook atbefore,router(just before routes) andafter.prepare()first checks installed plugins against the driver's name and throws for one that does not support it.app.use(...plugins)onArkstackforwards toPlugins.use().driver.prepare()inboot().Console
@arkstack/consoleand@arkstack/console-slimaddPlugins.commands()to the base commands.arkalready loadssrc/core/bootstrap.tsfirst, so plugins installed there are picked up.Docs
docs/guide/plugins.md,Hook.listen()anddriver:preparein the hooks guide, roadmap item marked done.Upgrade note
Existing apps keep working. To get the
driver:preparehook, replace the four driver calls insrc/core/app.tsboot()withdriver.prepare()as shown in the plugins guide.Tests
packages/foundry/tests/plugins.test.ts,Hook.listencases inhook.test.ts,packages/contract/tests/prepare.test.ts, and an Express end-to-end test where a plugin adds middleware and a route.mainthat need Postgres on :5432 (auth middleware tests) and the console command-surface test that runspnpm prepare.