melody
melody3mo ago

how to "slim down" deno_core crate

for reasons too complex to get into, i'm bundling deno_core with my project to parse some JS. I only need very basic JS funcionality: if, switch, objects, arrays, and functions. the only "standard library" function i need is parseInt, but it's not the end of the world if i have to implement it myself. is it possible to trim deno_core down to only include the very basic stuff? thanks!
4 Replies
Deno AI Helper
Deno AI Helper3mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you are looking to customize the deno_core crate to include only a subset of JavaScript features. The deno_core crate is designed to provide a minimal JavaScript runtime, and it is not typically meant to be "slimmed down" in the way you're describing. It is built on top of V8, which is a full-featured JavaScript engine, and doesn't offer a straightforward way to selectively disable language features like if, switch, objects, arrays, and functions. If you need to reduce the size of your binary, you might consider the following non-Deno-documentation-based suggestions: 1. Ensure you're using the --release flag when compiling your Rust code to optimize for size and performance. 2. Look into using Rust features to conditionally compile parts of the deno_core crate, though this would require significant understanding and modification of the crate's internals. 3. Investigate if any Cargo.toml optimizations can be made, such as using lto = true for link-time optimizations. Please note that these suggestions are not based on the Deno documentation, and you should double-check the accuracy of this advice. It's also worth noting that modifying deno_core in such a way would likely be a complex and error-prone task, and it may be more practical to use the crate as provided or to look for alternative solutions that better fit your size constraints.
ioB
ioB3mo ago
If you really only want the stupid basics, deno_core is the wrong crate for you you should look at https://crates.io/crates/v8 instead
melody
melody3mo ago
I saw that but I couldn’t find good docs anywhere for how to use it Oh the docs.rs page has an example Boy am I stupid
ioB
ioB3mo ago
the github repo has a few examples definitely worth checking out