Skip to content

fix(opencode): load legacy plugin functions next to a non-plugin default export - #50218

Open
argszero wants to merge 1 commit into
anomalyco:devfrom
argszero:plugin-legacy-fallback
Open

argszero wants to merge 1 commit into
anomalyco:devfrom
argszero:plugin-legacy-fallback

Conversation

@argszero

Copy link
Copy Markdown

Issue for this PR

Closes #50172

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A plugin file that exports its hooks by name and also default exports an object meant for another plugin runtime never loaded, because both load paths rejected it:

  • readV1Plugin(..., "detect") treated any default export object carrying an id as a v1 plugin, then threw for the missing server(). Detection now returns undefined when the default export does not carry the requested kind, so the module falls through to the legacy path. Strict mode and the malformed-shape errors are unchanged.
  • The legacy path threw Plugin export is not a function on the first export that is not a server plugin, which that default object always triggered. It now loads the plugin functions it finds, and only fails when the module exports none at all.

The caller already catches and logs these failures, so the symptom was a plugin that silently did nothing.

How did you verify your code works?

bun test test/plugin in packages/opencode: 215 pass, 0 fail. bun run typecheck (tsgo --noEmit) passes.

New coverage:

  • plugin.trigger > loads named exports next to a default export for another plugin shape builds a module with export default { id, setup } plus a named hook export and asserts the hook runs. Reverting either source change makes it fail.
  • readV1Plugin unit tests in test/plugin/shared.test.ts pin the detect mode contract: a default export without the requested kind returns undefined in detect mode and still throws in strict mode, while malformed exports keep throwing in both modes.

I also re-ran the existing object-shaped plugin tests in test/plugin/loader-shared.test.ts, which rely on detection reading { id, server } defaults.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ult export

A plugin module that exports its hooks as named plugin functions and also default
exports an object meant for another plugin runtime never loaded. Detection treated
any default export object carrying an `id` as a v1 plugin and then failed it for
missing `server()`, and the legacy path rejected the same module because that
default object is not a function.

Detection now reports a default export without the requested kind back to the
caller, and the legacy path loads the exports that are plugin functions while
ignoring the rest.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v1 file-plugin loader never falls back to legacy named exports when a v2 default export is present

1 participant