extism / js-pdk

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

feat: Add a simple polyfill system #17

Closed bhelx closed 7 months ago

bhelx commented 1 year ago

This adds a basic npm project which will be imported into core to polyfill globals that lots of JS programs expect.

$ extism call plugin.wasm evalcode --input=(new TextEncoder()).encode('€') --wasi
# => 226,130,172

Closes https://github.com/extism/js-pdk/issues/27

nilslice commented 1 year ago

excellent!

bhelx commented 8 months ago

Going to double check the size difference this creates. If it's too big i'm going to add a flag so that you have to opt into including the polyfills

bhelx commented 8 months ago

This only partly works. Doesn't seem to be able to find TextEncoder when included as a dependency. need to do a little more work on this. Might be a good time to see if we can support ESM as i suspect that might help.

bhelx commented 7 months ago

This is on hold but I'm going to come back to it after some refactors. Although it's nice to do all of this in JS, i think some of these should be in rust.

bhelx commented 7 months ago

I think this is in a better spot now. Uses rust to do text encoding and decoding and it's just exposed in JS.

$ extism call plugin.wasm evalcode --wasi --input="new TextEncoder().encode('über')"
# => 195,188,98,101,114
bhelx commented 7 months ago

Also i've gotten it work work with react so we know it seems to work in the real world

bhelx commented 7 months ago

Will have some follow ups here but good enough to move forward