amir3683
amir36832w ago

Embedding Deno in a Rust App to evaluate dynamic javascript/typescript inputs/files?

Given deno is written in pure rust, can i embed deno as an internal javascript/typescript evaluator for a rust app. The use-case is having user submitted scripts to evaluate on a streaming input and collect response generate by the script against that input. having a dynamic script submitted as a javascript/typescript offers big flexibility for my system.
8 Replies
bartlomieju
bartlomieju2w ago
Deno Blog
Roll your own JavaScript runtime
A walk-through of creating a CLI that executes JavaScript files.
amir3683
amir36832w ago
so is there a example of enriching the runtime with most used APIs? or a full fledged nodejs like/compatible standard library? or will have to hand-craft each based on the script using those methods and then patching it up?
bartlomieju
bartlomieju2w ago
Deno itself is the only example that has Node apis available
amir3683
amir36832w ago
And can I embed deno in my rust app?
bartlomieju
bartlomieju2w ago
You'd have to fork Deno. We don't distribute it as a library
amir3683
amir36832w ago
This use case have wide impact on deno adoption. Any plans to support this in near future?
Kalleby Santos
You can use the deno_runtime crate instead of raw deno_core it comes with standard Deno ops like: like fetch, Deno apis etc... you still need to hand craft the Typescript parser and the external import system like npm, esm etc... but its a good start point since already impl a loot of Js apis You can also use the v8 crate direct to evaluate Js code directly from rust and combine it with the serde_v8 crate to I/O between rust and Js. All of this packages are re-exported by the deno_core crate as well the deno_runtime
Kalleby Santos
You can check the Supabase Edge Runtime source code to get a strong example of embedding deno.
GitHub
GitHub - supabase/edge-runtime: A server based on Deno runtime, cap...
A server based on Deno runtime, capable of running JavaScript, TypeScript, and WASM services. - supabase/edge-runtime