binary-install
binary-install copied to clipboard
Allow passing args to run
Ideally, the run command should accept args in place of process.argv.
function run() {
...
if (arguments.length > 0) var args = arguments;
else var [, , ...args] = process.argv;
Hi @innovate-invent - do you have a specific use case for this? Happy to add support, just curious about the utility 😄
Applications installed via this utility can be run via the run() interface. Those applications expect command line arguments. The run() function basically just acts as a convenient wrapper for child_process with some path resolution. It would be good to forward a bit more of the underlying interface.
This would really help with a transient dependency here: https://github.com/wasm-tool/rollup-plugin-rust/commit/9027e61e6426c2cae59f6eb7b71449efb07fca7c
While it makes sense that install is a "binary" to run in npm scripts, in many cases a deep dependency binary is run programatically, which can be done more performantly and ergonomically without the .cmd -> .js -> stubs.
An alternative would be making _getBinaryPath public, so that people can do whatever they want with it, binary-install handling just the npm lifecycle. https://github.com/rustwasm/wasm-pack/pull/827 <- possibly this change should be applied to the template?
I'd love this as well — use case is calling Wrangler programmatically from a CI script written in JavaScript.
Adding on top of this, returning from run would also be helpful. It's useful for projects that want the main CLI tool to be written in Node, but certain parts of it to be written in another language. For example if a CLI tool was written for a programming language:
const compiler = require("./compiler") // loads a compiler binary
function command_install(...) {...} // uses axios to install a package
function command_compile(...) {
const args = preprocess(...) // do some preprocessing
const stdout = compiler.run(args)
postprocess(stdout)
}
If the language compiles to JavaScript, you may want to use an existing node package to minify the output before the file is saved to the system, but use a language better suited for compilation such as Rust to generate that initial output.