-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat(config): deduplicate plugins by name with priority-based resolution #5957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| export function getPluginName(plugin: string): string { | ||
| if (plugin.startsWith("file://")) { | ||
| const filename = path.basename(new URL(plugin).pathname) | ||
| return filename.replace(/\.(ts|js)$/, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of regex maybe use path parse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rekram1-node makes sense. Updated the implementation to use path.parse() instead.
| * we reverse, deduplicate (keeping first occurrence), then restore order. | ||
| */ | ||
| export function deduplicatePlugins(plugins: string[]): string[] { | ||
| const seen = new Set<string>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why create a set and array? You can convert a set to array pretty easily:
Array.from(seen.values())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rekram1-node The Set and Array store different values:
seenNames: canonical plugin names for duplicate detection (e.g.,"oh-my-opencode")uniqueSpecifiers: full plugin specifiers to return (e.g.,"oh-my-opencode@2.4.3","file:///path/to/plugin.js")
For clarity, I updated the variable names and added some comments.
|
@rekram1-node Thanks for the review. I updated some implementation. Feel free to check when you're available! |
a487bb8 to
3929b68
Compare
|
Just rebased the latest dev branch and resolved conflicts. |
|
this pr is genius |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Fixes #7427 |
|
/review |
|
lgtm |
|
can u rebase this? looks like a bunch of random commits got picked up |
sure thing, just rebased @rekram1-node |
|
/review |
|
lgtm |
…ion (anomalyco#5957) Cherry-picked from upstream 8e3ab4a. Plugins with the same name are deduplicated with priority: local > project > global.
Summary
Problem
Previously, if the same plugin existed in both
opencode.jsonand.opencode/plugin/directory, both would be loaded.oh-my-opencode@2.4.3(npm) +oh-my-opencode.js(local) → both executedSolution
getPluginName: Extract canonical name from plugin specifier (supports file:// URLs, npm packages, scoped packages)deduplicatePlugins: Deduplicate by name, later entries (higher priority) winPriority (highest to lowest)
plugin/directoryopencode.jsonplugin/directoryopencode.jsonTests
getPluginName(file URLs, npm packages, scoped packages)deduplicatePlugins(priority resolution, order preservation)