binary-install icon indicating copy to clipboard operation
binary-install copied to clipboard

Allow passing args to run

Open innovate-invent opened this issue 5 years ago • 5 comments

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;

innovate-invent avatar Mar 19 '20 00:03 innovate-invent

Hi @innovate-invent - do you have a specific use case for this? Happy to add support, just curious about the utility 😄

EverlastingBugstopper avatar Mar 20 '20 18:03 EverlastingBugstopper

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.

innovate-invent avatar Mar 20 '20 18:03 innovate-invent

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?

qm3ster avatar Apr 06 '20 15:04 qm3ster

I'd love this as well — use case is calling Wrangler programmatically from a CI script written in JavaScript.

iameli avatar Apr 08 '20 01:04 iameli

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.

giraffekey avatar Sep 19 '20 18:09 giraffekey