extism / js-pdk

Write Extism plugins in JavaScript & TypeScript
52 stars 16 forks source link

fix: plugin functions being accessed from global instead of from `module.exports` #65

Closed gabrielmfern closed 5 months ago

gabrielmfern commented 5 months ago

Sometimes when using bundlers to bundle the code for the plugin, bundlers would rename the function before exporting it, so if you had something like:

function myFunction() {
    Host.outputString('Hello');
}

module.exports = { myFunction };

It could turn into something like:

function myFunction2() {
    Host.outputString('Hello');
}

module.exports = { myFunction: myFunction2 };

This would make it so that once the PDK invoked the function it would still try calling the myFunction() on the global context, which would end up calling another function except for the one exported.

This PR fixes that by finding the export name inside module.exports instead of the global.