Closed
Description
Describe the Bug
I'm trying to create a plugin for the javascript project EventCatalog in Rust with wasm_bindgen.
Their plugin system is fairly simple and it works by:
- Adding your plugin as a nodejs package.
- Place the name of the added package in a config file.
- When the EventCatalog gets build, it
require
your package/plugin that's defined in the config file and calls the default exported function, i.e. whats exported withexport default ...
in the main module of the added nodejs package. For the curios you can find the code for the plugin loading code here.
I tried to create my plugin with the following code:
#[wasm_bindgen(js_name = default)]
pub fn init_my_plugin() {
...
}
Unfortunately the above function gets exported as _default
instead of default
and the generated JS code (with --target nodejs
) looks like this:
module.exports._default = function() {
wasm._default();
};
which means that EventCatalog
fails to call my plugin. This issue is very much related to #3012 and is just the other side of the coin. I think it's reasonable that if you can import fn default
, you should also be able to export fn default
.
Expected Behavior
The following Rust function
#[wasm_bindgen(js_name = default)]
pub fn init_my_plugin() {
...
}
should be exported as default
and not _default
and the generated javascript code should be:
module.exports.default = function() {
wasm.default();
};
Additional Context
I'll create a PR soon (PR created #3930)