Skip to content

Add plugin auto-discovery mechanism#376

Merged
marcospassos merged 3 commits into
masterfrom
plugin-auto-discovery
Jun 25, 2026
Merged

Add plugin auto-discovery mechanism#376
marcospassos merged 3 commits into
masterfrom
plugin-auto-discovery

Conversation

@marcospassos

Copy link
Copy Markdown
Member

Summary

Add plugin auto-discovery mechanism.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@croct/plug@376

commit: 0f75973

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GlobalPlug to scan and then “watch” the global plugin registry using a Proxy, 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.

Comment thread src/plugin.ts
Comment thread src/plug.ts
Comment thread src/plug.ts
Comment thread src/plug.ts
Comment thread src/plug.ts
continue;
}
window.croctPlugins = new Proxy(registry, {
set: (target, property, factory): boolean => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 renan628 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the previous comments, LGTM

@marcospassos marcospassos merged commit cde3510 into master Jun 25, 2026
11 checks passed
@marcospassos marcospassos deleted the plugin-auto-discovery branch June 25, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants