fix: skip non-function exports when loading external plugins#13544
Closed
intergrado-cg wants to merge 1 commit into
Closed
fix: skip non-function exports when loading external plugins#13544intergrado-cg wants to merge 1 commit into
intergrado-cg wants to merge 1 commit into
Conversation
External plugins typically export many things besides the Plugin function (helpers, constants, types). The plugin loading code iterates over ALL exports from a module and tries to call each as a Plugin function, which causes a TypeError when non-functions are encountered. This fix adds a typeof check to skip non-function exports.
Contributor
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
External plugins fail to load with
TypeError: fn is not a functionbecause the plugin loading code iterates over ALL exports from a module and tries to call each as a Plugin function. External plugins typically export many things besides the Plugin function (helpers, constants, types), causing the error when non-function exports are encountered.Root Cause
In
packages/opencode/src/plugin/index.ts, the plugin loading loop iterates over all exports usingObject.entries(mod)and attempts to call each as a Plugin function without checking if the export is actually a function.Fix
Add a
typeof fn !== "function"check before attempting to call the export as a Plugin function.Changes
Testing
Created a test plugin that exports additional non-function values (
SOME_CONSTANT,someObject) alongside the Plugin function. Verified the plugin now loads successfully.Related Issue
Fixes #13543