fix: remove dependency on postinstall script#260
Conversation
l-hellmann
left a comment
There was a problem hiding this comment.
A couple of items that can't be one-click suggestions:
utils/install.jsis now dead code — it was only thepostinstallentry point that this PR removes, but it's still shipped viafiles: ["/utils"]. Safe to delete.- Trailing newlines —
package.json,utils/binary.js, andutils/run.jsnow end without a trailing newline. Worth re-adding (the package shipsstandard).
| const getBinaryPath = () => { | ||
| const { join } = require("path"); | ||
| const platform_arch = getPlatform(); | ||
| return join(__dirname, "bin", "bin", `zcli-${platform_arch}`); | ||
| }; |
There was a problem hiding this comment.
This re-derives the installDir/bin/bin/name layout that binary-source.js already owns, so the two can drift. Suggest delegating to a small public getter on the Binary class:
| const getBinaryPath = () => { | |
| const { join } = require("path"); | |
| const platform_arch = getPlatform(); | |
| return join(__dirname, "bin", "bin", `zcli-${platform_arch}`); | |
| }; | |
| const getBinaryPath = () => getBinary().getPath(); |
This needs a matching getPath() on Binary in binary-source.js. It can't reuse the existing _getBinaryPath(), which calls process.exit(1) when the binary isn't installed — the very case we're checking here:
getPath() {
return join(this.installDirectory, "bin", this.name);
}| install() | ||
| .then(() => run()) | ||
| .catch((err) => { | ||
| process.stderr.write(`download failed: ${err.message}\n`); | ||
| process.exit(1); | ||
| }); |
There was a problem hiding this comment.
binary-source.install() already handles download failures internally (error() → process.exit(1)), so this .catch is unreachable. Simplify to:
| install() | |
| .then(() => run()) | |
| .catch((err) => { | |
| process.stderr.write(`download failed: ${err.message}\n`); | |
| process.exit(1); | |
| }); | |
| install().then(() => run()); |
|
Thanks again for tackling the Bun issue here @KrishnaSSH 🙏 After reviewing, I prototyped an alternative in #261 using the That said, the runtime-download approach here is a valid smaller step. If we'd rather go this route, here's what it would still need to avoid regressing existing users (beyond the inline suggestions above): Required to not regress:
Plus the smaller items (inline above):
One caveat either way: moving the binary out of I prototyped all three "required" changes locally and they check out — happy to push them onto this branch if we pick this direction. Either way, would love your thoughts on which way to go. |
|
makes sense, thanks for the thorough |
What Type of Change is this?
Description (required)
fixes bun compatibility bun blocks postinstall scripts by default,
so the binary was never downloaded. this pr removes the dependency on postinstall script