fix(opencode): prevent plugin deduplication collision for index.js entry points#11161
fix(opencode): prevent plugin deduplication collision for index.js entry points#11161guazi04 wants to merge 3 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
Why it's related: This PR also addresses file:// URL plugin deduplication issues. It may be a previous attempt at fixing a similar problem, so check if #8758 was closed/abandoned or if it's a different approach to the same root cause (issue #11159). |
00637c0 to
71e0ba2
Compare
f1ae801 to
08fa7f7
Compare
…try points getPluginName() now uses a 3-tier resolution for file:// URLs: 1. Walk up to find package.json name (stops at .opencode boundary) 2. Use filename if not "index" 3. For index entry points, walk up skipping generic dirs (src/dist/lib/build/out/esm/cjs) Also uses fileURLToPath() for cross-platform correctness. Fixes anomalyco#11159
ed97ab6 to
3682053
Compare
file:// URLs always use forward slashes, but fileURLToPath() converts them to backslashes on Windows. Use path.posix for URL pathname parsing (directory walking heuristic) while keeping fileURLToPath() for actual filesystem operations in findPackageName().
…URL helper Replace hardcoded Unix file:// URLs with pathToFileURL(path.resolve()) so fileURLToPath() receives valid absolute paths on Windows.
|
FYI — I've opened #15598 with a similar fix but a different approach: instead of using the full URL as identity, it extracts the npm package name from This preserves the original design intent where a local |
|
Thanks for the heads-up @cyberprophet! Nice approach with the Our PR takes a slightly broader approach since the Both would still resolve to
Definitely some overlap though! Might be worth letting the maintainers decide which trade-off they prefer — minimal and targeted vs. broader coverage. Either way the core |
|
Good point @guazi04 — the local That said, I intentionally kept #15598 minimal for a couple of reasons:
But you're right that both approaches fix the core issue. Happy to let @rekram1-node decide which trade-off fits better — or if a combined approach makes sense. |
|
Haha to be honest, I just noticed this issue had been open for a while with no fix landed, so I figured I'd take a crack at it. No strong attachment to which PR gets merged — as long as the collision bug gets resolved, that's a win for everyone 🎉 |
Issue for this PR
Closes #11159
Type of change
What does this PR do?
getPluginName()returns only the filename forfile://URLs. Plugins withindex.js/index.tsentry points all return"index", causing incorrect deduplication — earlier plugins are silently dropped.Solution: 3-tier name resolution for
file://URLspackage.jsonwith anamefield. Stops at.opencodeboundary to avoid picking up the host project's name for.opencode/plugin/*scripts."index", use the filename."index"entry points, walk up directories skipping generic names (src/dist/lib/build/out/esm/cjs).Also uses
fileURLToPath()instead ofnew URL(...).pathnamefor cross-platform correctness (Windows paths, URL-encoded chars).How does this compare to PR #8758?
Similar strategy (package.json + heuristic fallback), but:
.opencodeboundary guard (prevents host project's package.json from breaking local plugin dedup)How did you verify your code works?
.opencode/plugin/a.js+b.jswith hostpackage.json→ both resolve to filename, not project namepackage.json+src/index.ts→ resolves to package nameChecklist