Embedding vaeljs-lite
vaeljs-lite-core is the primary interface for VaelJS Lite: a compact, embeddable QuickJS-NG (rquickjs 0.15.0) runtime for ECMAScript modules and erasable TypeScript with zero V8, Tokio, or Hyper dependencies.
vaeljs-lite-core is isolated from the workspace’s default V8 members, so normal workspace builds (cargo build) never pull QuickJS into the V8 dependency graph.
Basic Embedding
Section titled “Basic Embedding”Add vaeljs-lite-core as a path (or workspace) dependency (publish = false during alpha):
use vaeljs_lite_core::Runtime;
fn main() -> Result<(), vaeljs_lite_core::Error> { let mut runtime = Runtime::new()?; runtime.run_file("examples/hello.js")}Run the included workspace example:
cargo run --locked -p vaeljs-lite-core --example embed -- examples/hello.jsRunning In-Memory Modules (run_source)
Section titled “Running In-Memory Modules (run_source)”Use run_source(name, source) to evaluate an in-memory ES module without reading the entry from disk:
use vaeljs_lite_core::Runtime;
fn main() -> Result<(), vaeljs_lite_core::Error> { let mut runtime = Runtime::new()?; runtime.run_source( "/app/main.js", r#" import { v4 } from "vael:uuid"; console.log("job id:", v4()); "#, )}namesets the module identity and base directory for relative imports (pass an absolute path when the module imports local files).- The in-memory entry string’s own extension is not checked, while any imported files still go through
vaeljs-module-policy.
Running Tests from Rust (run_tests)
Section titled “Running Tests from Rust (run_tests)”Register tests in JS/TS with vael:test and retrieve structured counts via Runtime::run_tests():
use vaeljs_lite_core::Runtime;
fn main() -> Result<(), vaeljs_lite_core::Error> { let mut runtime = Runtime::new()?; runtime.run_file("example.test.ts")?; let report = runtime.run_tests()?; assert!(report.all_passed(), "failures: {:?}", report.failures); Ok(())}TestReport exposes total, passed, failed, pending, unhandled, unsettled, failures: Vec<String>, and all_passed(). Requires the vael-test feature.
RuntimeOptions, Remote, npm:, and vael.jsonc Manifests
Section titled “RuntimeOptions, Remote, npm:, and vael.jsonc Manifests”Runtime::new() keeps remote fetches disabled (remote = None), performs zero implicit vael.jsonc discovery, and enables node:* modules when node-compat is compiled in (and local/CAS npm: resolution when npm is compiled in). Customize behavior with RuntimeOptions:
- Remote & JSR (
remotefeature, since0.0.0-alpha.1): Opt in withRuntime::with_remote(RemoteOptions::new())orRuntimeOptions::with_remote(...), and execute remote entrypoints viaRuntime::run_url(url)(https:,gh:/github:,jsr:) using blockingvaeljs-remote(ureq+rustls, zero Tokio/hyper). Callingrun_urlwithoutwith_remotefails closed withError::RemoteDisabled. npm:&package.json(npmfeature, since0.0.0-alpha.1): ConfigureNpmOptions(with_enabled,with_frozen_lockfile,with_offline,with_cache_dir,with_registry_origin) viaRuntimeOptions::with_npm(...)or theRuntimeOptionsshortcutswithout_npm(),with_frozen_lockfile(...),with_offline(...), andwith_npm_cache_dir(...). Online registry fetches requirewith_remote(...)as well.vael.jsonc& Workspaces (manifestfeature): Opt in withRuntimeOptions::with_import_resolver(...)(orRuntime::with_import_resolver(...)).
use vaeljs_lite_core::{ ImportResolver, NpmOptions, RemoteOptions, Runtime, RuntimeOptions,};use vaeljs_manifest::{Workspace, discover_manifest};
fn run_configured() -> Result<(), Box<dyn std::error::Error>> { let mut options = RuntimeOptions::new() .with_node_compat(false) .with_remote(RemoteOptions::new()) .with_npm(NpmOptions::new().with_frozen_lockfile(true));
if let Some(found) = discover_manifest(".", None)? { let resolver = if found.manifest.workspaces.is_empty() { ImportResolver::from_manifest(&found) } else { let ws = Workspace::load(&found.path)?; let active = ws.member_for_path("main.ts")?.map(|m| m.name()); ImportResolver::from_workspace(&ws, active)? }; options = options.with_import_resolver(resolver); }
let mut runtime = Runtime::with_options(options)?; runtime.run_file("main.ts")?; if let Some(code) = runtime.exit_code() { println!("script requested exit code {code}"); } Ok(())}Or run a remote module directly from Rust:
use vaeljs_lite_core::{RemoteOptions, Runtime};
fn main() -> Result<(), vaeljs_lite_core::Error> { let mut runtime = Runtime::with_remote(RemoteOptions::new())?; runtime.run_url("jsr:@scope/pkg@^1.0.0")}Granular Cargo Feature Flags
Section titled “Granular Cargo Feature Flags”With default-features = false, vaeljs-lite-core omits all vaeljs-builtins, vaeljs-archive-core, vaeljs-crypto-core, vaeljs-exec-core, vaeljs-fetch-core, vaeljs-fs-core, vaeljs-os-core, vaeljs-ssh-core, vaeljs-template-core, vaeljs-node-core, vaeljs-remote, vaeljs-npm, and deno_ast (typescript) dependencies—leaving Vael.getBuiltInModulesList() as an empty frozen array and keeping only a minimal console.{log,error} shim.
| Feature | Default | Enables |
|---|---|---|
vael-ansi |
Yes | vael:ansi terminal ANSI escape codes, styling, and color detection (vaeljs-builtins/ansi) |
vael-archive |
Yes | vael:archive hardened synchronous tar, tar.gz, tar.zst, zip ops (vaeljs-archive-core) |
vael-assert |
Yes | vael:assert + Promise observation hooks |
vael-chars |
Yes | vael:chars Unicode character predicates |
vael-console |
Yes | vael:console and formatted console.{log,debug,info,warn,error} |
vael-crypto |
Yes | vael:crypto synchronous cryptographic exports (vaeljs-crypto-core) |
vael-exec |
Yes | vael:exec synchronous process execution, PATH lookup, and advisory file locking (vaeljs-exec-core) |
vael-fetch |
Yes | vael:fetch synchronous SSRF-guarded HTTP fetchSync and downloadSync (vaeljs-fetch-core) |
vael-fmt |
Yes | vael:fmt (vael:fmt, vael:fmt/bytes, vael:fmt/duration, vael:fmt/inspect, vael:fmt/printf, vael:fmt/strip-ansi-code) |
vael-fs |
Yes | vael:fs synchronous filesystem ops (vaeljs-fs-core) |
vael-os |
Yes | vael:os and vael:os/dirs (vaeljs-builtins/os, vaeljs-os-core) |
vael-path |
Yes | vael:path lexical path helpers |
vael-slices |
Yes | vael:slices (Slice, CharSlice; implies vael-chars) |
vael-ssh |
Yes | vael:ssh synchronous SSH client (vaeljs-ssh-core) |
vael-strings |
Yes | vael:strings Unicode 16.0 case-folding & trimming |
vael-template |
Yes | vael:template Go text/template + Sprig (vaeljs-template-core) |
vael-test |
Yes | vael:test + Runtime::run_tests() |
vael-uuid |
Yes | vael:uuid, vael:uuid/v4, vael:uuid/v7 |
node-compat |
Yes | 27 sync/pure-JS node:* compatibility modules (vaeljs-node-core) |
typescript |
Yes | Erasable .ts/.mts stripping (vaeljs-module-policy/typescript / deno_ast) |
remote |
Yes (since 0.0.0-alpha.1) |
https:, gh:/github:, jsr: loading via vaeljs-remote (ureq + rustls, zero Tokio/hyper), RemoteOptions, Runtime::with_remote, Runtime::run_url |
npm |
Yes (since 0.0.0-alpha.1) |
npm:, package.json, vael.lock, .npmrc CAS resolution (vaeljs-npm, implies remote), NpmOptions, RuntimeOptions::with_npm |
manifest |
No | vaeljs-manifest ImportResolver + Runtime::with_import_resolver |
virtual-fs |
No | Bounded in-memory virtual filesystem for module loading and (when configured on RuntimeOptions) a safe synchronous vael:fs virtual surface |
# Minimal footprint: pure ES module evaluation + only vael:fs and vael:template# (omits vaeljs-remote, vaeljs-npm, node-compat, and typescript)[dependencies]vaeljs-lite-core = { path = "../vaeljs-lite-core", default-features = false, features = ["vael-fs", "vael-template"] }Runtime Lifecycle & Guards
Section titled “Runtime Lifecycle & Guards”- Single-use per entry: Preflight failures (
Error::Entry,Error::UnsupportedEntry,Error::TypeScript,Error::RemoteDisabled,Error::RemoteEntry,Error::RemoteTypeScript) leave theRuntimeunused. Once evaluation begins, the runtime is consumed and a secondrun_file/run_url/run_sourcereturnsError::RuntimeConsumed. - Bounded job drain: After the entry settles, QuickJS drains queued jobs up to
100,000jobs (Error::NonConvergingJobs) and reports remaining unhandled promise rejections (Error::UnhandledRejection).
When to Embed vaeljs-core Instead
Section titled “When to Embed vaeljs-core Instead”Choose vaeljs-core (V8 + Tokio + Hyper) over vaeljs-lite-core when your host application needs:
- Async host I/O, timers, or servers (
vael:http,vael:db,vael:cron,vael:age,vael:stdio,*Asynccrypto,node:fs/promises,node:child_process.execFile). Runtime::run_file_asyncpolled on an async executor.- V8 JIT throughput for CPU-heavy JavaScript workloads.
