I need to run some js code from an npm library in a CLI written in rust. Unsure about which way should I go.
Have the following solutions in mind though not satisfied with either of these ( might not even be correct )
compiling the whole application to a wasm binary and then running that. But don't want users to install wasm runtime specially for this.
compiling the rust code into wasm and using same in a node js project. But with this I think I would have to handle the CLI argument handling in node js which also I don't want to do and the CLI will then again have a dependency on node being present in the system. ( this still feels like a better solution than first one )
Is there a way to create a binary for this usecase which isn't dependent either on node.js or wasm runtime being present ? If not, any recommendations on how should I go about doing this ?
I don't think it's possible (or a reasonable expectation) to run NPM packages without Node. You really can't get around having the actual runtime for the language if it requires a runtime (which JavaScript does).
Wasm probably wouldn't help here. It would still require a JS runtime for running the JS code itself.
You should probably look into embedding deno into your Rust code, which is a Node.JS replacement written in Rust.
It's postman-code-generator@jeanas . As it's very coupled to postman, didn't think there will be a pure rust alternative to this. Am planning to offer the same functionality in the CLI ( pocc ) that am working on. I have successfully converted a postman request to a reqwest::request. So if there is rust crate which can convert a reqwest::Request to other languages, should be able to use it.
PS: Initial plan was to just implement conversion to curl ( which is implemented today ) though then I discovered the above library and thought it might be a great feature to add.