[PR #8758] fix: use full URL for file:// plugin deduplication #12859

Open
opened 2026-02-16 18:17:45 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8758

State: open
Merged: No


Summary

Fixes a bug in plugin deduplication logic where multiple file:// plugins with the same filename (e.g., index.js) would be incorrectly treated as duplicates and only the last one would load.

Problem

The getPluginName() function extracted only the filename for file:// URLs:

// Before
if (plugin.startsWith("file://")) {
  return path.parse(new URL(plugin).pathname).name  // "index"
}

This caused issues when using multiple plugins with standard entry points:

{
  "plugin": [
    "file:///path/to/plugin-a/dist/index.js",  // -> "index"
    "file:///path/to/plugin-b/dist/index.js",  // -> "index" (duplicate!)
    "file:///path/to/plugin-c/dist/index.js"   // -> "index" (duplicate!)
  ]
}

Result: Only the last plugin loaded because all were seen as duplicates of "index".

Solution

Use the full URL as the identity for file:// plugins:

// After
if (plugin.startsWith("file://")) {
  return plugin  // Full URL
}

This allows:

  • Multiple plugins in the same directory with different filenames
  • Multiple plugins in different directories with the same filename
  • Same file:// URL appearing twice → correctly deduplicated
  • npm packages continue to deduplicate by package name as expected

Testing

Verified with real-world setup using four local file:// plugins, all with index.js or index.mjs entry points:

  • custom-toolkit-alpha/dist/index.js
  • custom-toolkit-beta/dist/index.js
  • custom-toolkit-gamma/dist/index.js
  • custom-auth-plugin/index.mjs

Before fix: Only the last plugin loaded.
After fix: All four plugins load correctly.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8758 **State:** open **Merged:** No --- ## Summary Fixes a bug in plugin deduplication logic where multiple file:// plugins with the same filename (e.g., `index.js`) would be incorrectly treated as duplicates and only the last one would load. ## Problem The `getPluginName()` function extracted only the filename for file:// URLs: ```typescript // Before if (plugin.startsWith("file://")) { return path.parse(new URL(plugin).pathname).name // "index" } ``` This caused issues when using multiple plugins with standard entry points: ```json { "plugin": [ "file:///path/to/plugin-a/dist/index.js", // -> "index" "file:///path/to/plugin-b/dist/index.js", // -> "index" (duplicate!) "file:///path/to/plugin-c/dist/index.js" // -> "index" (duplicate!) ] } ``` Result: Only the last plugin loaded because all were seen as duplicates of "index". ## Solution Use the full URL as the identity for file:// plugins: ```typescript // After if (plugin.startsWith("file://")) { return plugin // Full URL } ``` This allows: - ✅ Multiple plugins in the same directory with different filenames - ✅ Multiple plugins in different directories with the same filename - ✅ Same file:// URL appearing twice → correctly deduplicated - ✅ npm packages continue to deduplicate by package name as expected ## Testing Verified with real-world setup using four local file:// plugins, all with `index.js` or `index.mjs` entry points: - `custom-toolkit-alpha/dist/index.js` - `custom-toolkit-beta/dist/index.js` - `custom-toolkit-gamma/dist/index.js` - `custom-auth-plugin/index.mjs` Before fix: Only the last plugin loaded. After fix: All four plugins load correctly.
yindo added the pull-request label 2026-02-16 18:17:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12859