sebastianwessel / quickjs

A typescript package to execute JavaScript and TypeScript code in a webassembly quickjs sandbox
https://sebastianwessel.github.io/quickjs/
MIT License
609 stars 16 forks source link

Improve custom virtual file system and modue loader to allow relative imports #8

Closed sebastianwessel closed 3 months ago

sebastianwessel commented 3 months ago

Allow relative imports of source files from virtual file system. Add documentation for virtual file system usage.

MarketingPip commented 3 months ago

@sebastianwessel - sorry to be a bothersome. Can I get an example of how to use this with a exported function as import in the vfs?

ps; when using this via cdn in browser from esm.sh I am getting this error:

Uncaught TypeError: Failed to resolve module specifier '@jitl/quickjs-ng-wasmfile-release-sync'
sebastianwessel commented 3 months ago

Hey @MarketingPip,

Thanks for your interest in this library! I'm happy to help out if I can.

Are you looking to add a file to the virtual file system and then import it into your script? If so, you might find this example useful:

Custom Module Example

Feel free to reach out if you have any more questions!

sebastianwessel commented 3 months ago

...regarding the usage in browser.

It is currently not the highest priority, but I will add some more documentation about it and I also need to investigate a bit more

Issue will be tracked here: #22

MarketingPip commented 3 months ago

@sebastianwessel - you're the best! Was right in front of my eyes!

That said would be VERY cool to see this for usage of browser. (Would be very useful for in browser code editors 😉).

ps; since I have been looking for something exactly like this library for a while for browser - possible suggestion. Add feature for building a HTML document too with support for style sheets etc.... that gets written out with imports / style sheets etc parsed. (Could be useful for serving pages etc from web server too - as well in browser code editors as I said). Which if you're looking to collaborate on anything too - do let me know. Maybe you could implement your library into project I am working on! 👌

sebastianwessel commented 3 months ago

@MarketingPip

Small doc: https://sebastianwessel.github.io/quickjs/usage-in-browser-and-providers.html

browser example: https://github.com/sebastianwessel/quickjs/tree/main/example/browser

Little test: https://sebastianwessel.github.io/quickjs/example.html (chrome only atm)

MarketingPip commented 3 months ago

@sebastianwessel - I see your CSS skills are way better than mine lol!

I got this when running

caught TypeError: Symbol.dispose is not defined.
    at pt (quickJS.js:10:40)
    at evalCode (quickJS.js:148:43)
sebastianwessel commented 3 months ago

I see your CSS skills are way better than mine lol! 🤫 ChatGPT

Which browser do you use? I've seen this too in Firefox & Safari - but not in Chrome for 🤷‍♂️ reason.

MarketingPip commented 3 months ago

@sebastianwessel older version of chrome running in indigo version.

MarketingPip commented 3 months ago

@sebastianwessel - I found a polyfill that solved this, maybe you want to document it or look into the polyfill itself further etc...

See here

MarketingPip commented 3 months ago

@sebastianwessel - no chance you got to look at that poly fill? (Possibly dynamically import it etc if not found...?) - Worked on my device to solve my issue.

sebastianwessel commented 3 months ago

I'm currently focusing on the next version, which, in theory, should not have this issue.

MarketingPip commented 3 months ago

@sebastianwessel - no worries. (Not that I am bugging you for this). Just figured maybe it might be help to you!

Cheers 🥂