fix(plugin): slim main entry so OpenCode can load it#16
Conversation
OpenCode's plugin loader iterates every named export of the resolved
plugin module and requires each value to be a function (or
`{ server: fn }`). The package's `dist/index.js` re-exported two number
constants (`DEFAULT_HTTP_TIMEOUT_MS`, `DEFAULT_SYNC_INTERVAL_MINUTES`),
which caused `TypeError: Plugin export is not a function` on load. Every
other named function (validateConfig, fetchModels, FileCacheStore, even
the factory itself) would also have been invoked as a plugin.
Restructure so the OpenCode entry exposes only the plugin function, and
move the library API to a `./lib` subpath via the `exports` map.
- src/index.ts: re-exports only `default` from ./opencode.js
- src/lib.ts (new): holds the former named exports
- package.json: adds `exports` map with `.` (plugin) and `./lib` (API)
- docs/troubleshooting.md: updates embedder example to `/lib` subpath
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request restructures the exports of the @vymalo/opencode-oauth2 package to prevent the host environment from incorrectly invoking non-plugin exports. The main entry point (index.ts) now only exports the default plugin function, while the library API has been moved to a new lib.ts file and exposed via the ./lib subpath in package.json. The documentation has been updated accordingly. The reviewer pointed out a regression where the pre-instantiated OpencodeOauth2Plugin was omitted from the new lib.ts exports, and provided a suggestion to restore it.
|
|
||
| export { resolveCacheDir, FileCacheStore } from "./cache.js"; | ||
|
|
||
| export { createOpencodeOauth2Plugin } from "./opencode.js"; |
There was a problem hiding this comment.
The pre-instantiated plugin instance OpencodeOauth2Plugin is not exported from lib.ts. Since it was previously exported from index.ts (and can no longer be exported there to prevent OpenCode from invoking it with incorrect arguments), it should be exported from lib.ts so that embedders who import named exports can still access it.
| export { createOpencodeOauth2Plugin } from "./opencode.js"; | |
| export { createOpencodeOauth2Plugin, OpencodeOauth2Plugin } from "./opencode.js"; |
Patch release for the plugin-entry fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Fixes
TypeError: Plugin export is not a functionwhen OpenCode loads@vymalo/opencode-oauth2.OpenCode's plugin loader (verified against
opencode-ai@1.15.10) iterates every named export of the resolved plugin module and requires each value to be either a function or{ server: fn }. Ourdist/index.jsre-exported two number constants —DEFAULT_HTTP_TIMEOUT_MSandDEFAULT_SYNC_INTERVAL_MINUTES— which trip the check. Even without those, every other named function (validateConfig,fetchModels,FileCacheStore, and thecreateOpencodeOauth2Pluginfactory itself) would have been invoked as a plugin with the wrong arguments.Changes
src/index.ts— slimmed to a singleexport { default } from "./opencode.js". The OpenCode-facing entry now exposes exactly one value: the plugin function.src/lib.ts(new) — holds the former public API (validateConfig,OAuth2ModelSyncPlugin,FileCacheStore, the defaults, types, etc.) for embedders that want to drive the runtime directly.package.json— adds anexportsmap:.→ slim plugin entry,./lib→ library API.main/typesare kept for legacy resolvers.docs/troubleshooting.md— updates the embedder snippet to import from@vymalo/opencode-oauth2/lib.Verification
pnpm typecheckpassespnpm buildpassespnpm testpasses (94/94)Test plan
Plugin export is not a function.import { OAuth2ModelSyncPlugin } from "@vymalo/opencode-oauth2/lib"resolves for embedders.🤖 Generated with Claude Code