Add plugin auto-discovery mechanism#376
Conversation
commit: |
There was a problem hiding this comment.
Pull request overview
Adds a plugin auto-discovery mechanism so plugins can be declared globally (via window.croctPlugins) or registered programmatically (via PluginSdk.register) and then automatically registered/enabled by GlobalPlug.
Changes:
- Introduces
PluginSdk.register()to register plugin factories into a global registry (window.croctPlugins). - Updates
GlobalPlugto scan and then “watch” the global plugin registry using aProxy, enabling plugins registered after the plug is loaded. - Expands unit tests to cover auto-discovery, configuration options/disablement, conflicts, and lifecycle behavior across plug/unplug cycles.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/plug.test.ts | Adds coverage for global plugin discovery/registration and lifecycle behaviors. |
| src/plugin.ts | Adds PluginSdk.register() as the programmatic entrypoint for global plugin registration. |
| src/plug.ts | Implements discovery + proxy-based watching of window.croctPlugins, plus refactors plugin enabling into helpers. |
| src/global.d.ts | Declares window.croctPlugins typing for consumers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| continue; | ||
| } | ||
| window.croctPlugins = new Proxy(registry, { | ||
| set: (target, property, factory): boolean => { |
There was a problem hiding this comment.
Since plugins can't be unregistered or overridden I'd also add a delete handler with an error log stating that the plugin will remain registered.
Currently it will log only when trying to set it to something else.
renan628
left a comment
There was a problem hiding this comment.
Besides the previous comments, LGTM
Summary
Add plugin auto-discovery mechanism.
Checklist