Don't fail package installation if binary can't be downloaded/run

#31 · closed · 1 comments

View on GitHub ↗

koterpillar

I'd like to have `cloudflared` as a dependency but manage the installation of the binaries manually from my package's code (by importing `install`/`upgrade`/`bin`). This is to prompt the users who have firewalls and other paranoid configurations to allow downloads from GitHub (or bring their own binaries). However, currently the package has somewhat confusing behaviour: * If the binary fails to download, the installation succeeds (`main` throws an error which is ignored [here](https://github.com/JacobLinCool/node-cloudflared/blob/1bde21eeeac782f4c685c16e2e3e8bbeb156355c/src/cloudflared.ts#L6)). * If the binary is downloaded but cannot execute (due to anti-virus-like software), the installation fails because of `process.exit` [here](https://github.com/JacobLinCool/node-cloudflared/blob/4147bb66e53995cdb6cb1f41cf0a40a262b02a04/src/index.ts#L84). Would you accept a PR removing `node lib/cloudflared.js -v` from the postinstall script so users can manage the installation themselves?

Comments

JacobLinCool

I want the package to make a best-effort attempt to download and install the binary automatically after installation. However, I think you're right—this may prevent the use of the package if the binary download or execution fails. I don't want to remove `node lib/cloudflared.js -v` from the postinstall script since it's intended to install the binary after installation. To prevent automatic installation, we could try detecting an environment variable like `CLOUDFLARED_DISABLE_AUTO_BINARY_INSTALL` (though it might be a bit too long, haha) to skip the installation. Alternatively, we could use another script, such as `node lib/auto-install.js`, as the postinstall script. This script would catch all errors and never fail.