Skip to content

feat: support ESM plugins or plugins with named exports#221

Open
calfzhou wants to merge 3 commits intohexojs:masterfrom
calfzhou:feature/support-complex-plugins
Open

feat: support ESM plugins or plugins with named exports#221
calfzhou wants to merge 3 commits intohexojs:masterfrom
calfzhou:feature/support-complex-plugins

Conversation

@calfzhou
Copy link
Copy Markdown

check list

  • Add test cases for the changes.
  • Passed the CI test.

Description

This PR adds support for loading plugins that use ESM-style exports (interop) or named exports.

Previously, the renderer assumed that require('plugin-name') would directly return the plugin function. However, some modern plugins or dual-mode packages might export the plugin function under a default property or a specific named export.

With this change, users can now specify an import property in the plugin configuration to choose which export to use.

Logic:

  • If the required module is an object and the user specifies an import key (or defaults to 'default'), it tries to use that property.
  • If the property doesn't exist, it throws a descriptive error listing available exports.
  • Fallback behavior is preserved for standard CommonJS plugins.

Example Config:

plugins:
  - name: 'some-esm-plugin'
    import: 'default' # Optional, defaults to 'default' if the module is an object
    options: ...

Additional information

  • Updated README.md with usage examples for the new feature.
  • Added unit tests covering default and named exports.

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.

1 participant