opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: use full URL for file:// plugin deduplication

Open coleleavitt opened this issue 10 hours ago • 3 comments

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.

coleleavitt avatar Jan 15 '26 23:01 coleleavitt