#typescript #run-time #deno #powered #embeddable #directory #yasumu

bin+lib tanxium

Embeddable JavaScript/TypeScript runtime for Yasumu powered by Deno

2 releases

0.2.1 Oct 27, 2024
0.2.0 Oct 17, 2024
0.1.5 Sep 29, 2024

#12 in #powered

Download history 381/week @ 2024-09-14 13/week @ 2024-09-21 146/week @ 2024-09-28 15/week @ 2024-10-05 156/week @ 2024-10-12 28/week @ 2024-10-19 127/week @ 2024-10-26 5/week @ 2024-11-02

187 downloads per month

MIT license

52KB
885 lines

Tanxium

Embeddable JavaScript/TypeScript runtime for Yasumu powered by Deno.

[!CAUTION] This project is still in development and not ready for production use.

Installation

cargo add tanxium

Example

This is an example of how to use Tanxium to run JavaScript/TypeScript code. You can also find this example in the examples directory.

use tanxium::tanxium::{run_current_thread, Tanxium, TanxiumOptions};

fn main() {
    let future = async {
        let cwd = std::env::current_dir().unwrap();
        let target_file = std::env::args().nth(1).expect("missing target file");
        let target_file = cwd.join(target_file);
        let main_module = deno_core::ModuleSpecifier::from_file_path(target_file).unwrap();

        // Create a new Tanxium runtime instance
        let mut tanxium = Tanxium::new(TanxiumOptions {
            main_module: main_module.clone(),
            cwd: cwd.to_string_lossy().to_string(),
            extensions: vec![],
            test: true,
            stdout: None,
            stderr: None,
            stdin: None,
        })
        .unwrap();

        // load runtime apis
        match tanxium.load_runtime_api(None).await {
            Err(e) => eprintln!("{}", e.to_string()),
            _ => (),
        };

        // set runtime data
        let rt_data = r#"{ "foo": "bar" }"#.to_string();

        match tanxium.set_runtime_data(rt_data) {
            Err(e) => eprintln!("{}", e.to_string()),
            _ => (),
        }

        // run main module
        match tanxium.execute_main_module(&main_module).await {
            Err(e) => eprintln!("{}", e.to_string()),
            _ => (),
        };

        // run event loop
        match tanxium.run_event_loop(false).await {
            Err(e) => eprintln!("{}", e.to_string()),
            _ => (),
        }

        // get runtime data
        match tanxium.get_runtime_data() {
            Err(e) => eprintln!("{}", e.to_string()),
            Ok(data) => println!("Runtime Data:\n{}", data),
        };
    };

    run_current_thread(future);
}

Now you can run your JavaScript/TypeScript code using Tanxium:

cargo run ./file.ts

Dependencies

~199MB
~4M SLoC