deno-cliffy
deno-cliffy copied to clipboard
UpgradeCommand and deno compile
We ship some cli binaries compiled using deno compile
because it provides a convenient single executable to download and install. One downside of this approach is that apparently UpgradeCommand
does not work because it assumes a deno runtime instead of a compiled deno environment.
e.g.
Deno.execPath(): /Users/xx/dev/mc/unipipe-service-broker/cli/bin/unipipe
error: Unknown option "--allow-read". Did you mean option "--help"?
I'm not sure what the right answer is wrt. behavior. I'm thinking of using a somewhat simplified check like this right now
const denoExecutable = Deno.execPath();
const isRuntime = path.basename(denoExecutable) === "deno"; // simple and stupid, but avoids recursively invoking ourselves!
if (!isRuntime) {
const msg = `Upgrade is only supported when cli was installed via "deno install".`;
program
.command("upgrade")
.description(msg)
.action(() => {
console.error(
msg
+ `\nThis version at ${denoExecutable} appears to be a self-contained binary.\n`
+ `\nTry installing via:\n`
+ `\n\tdeno install https://raw.githubusercontent.com/meshcloud/unipipe-cli/v${VERSION}/unipipe/main.ts ${FLAGS}`
);
Deno.exit(1);
});
}
@c4spar Do you have plans to support it?
Yes i want to support this. I think we can adapt the GithubProvider
to support downloading binaries uploaded on github. PR's are welcome.
The function needs to read the user OS type. It should add a prefix to the filename of the binary depending on the OS. If you share an image of the spec it. I will work.
We could do it the following:
- Detect if the cli is a binary or a script.
- Each provider should have a property which indicates if it supports binary and/or script updates.
- If no registry is provided via cli option, use the first supported provider in the options array.
- Get the github release for the requested version via github api and look for an asset which includes
Deno.build.os
andDeno.build.arch
. - Download the binary and install it in the target location.
- Try to auto detect the location of the binary and fallback to a provider
location
option. - Add a global option to the upgrade command to be able to override the provider location option.
- Maybe add also a global environment variable to the upgrade command for the location which can be optionally enabled. The prefix of the env var should be also configurable.