-
Notifications
You must be signed in to change notification settings - Fork 3
chore: [PR-1797] re-land sf migrate command and Rust CLI migration banner
#268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import * as console from "node:console"; | ||
| import process from "node:process"; | ||
| import type { Command } from "@commander-js/extra-typings"; | ||
| import boxen from "boxen"; | ||
| import chalk from "chalk"; | ||
| import ora from "ora"; | ||
|
|
||
| const NEW_CLI_INSTALL_URL = "https://cli.sfcompute.com"; | ||
| const MIGRATION_GUIDE_URL = "https://sfcompute.com/migrate"; | ||
|
|
||
| export function showMigrateBanner() { | ||
| const message = `We've rewritten the sf CLI in Rust. | ||
|
|
||
| List idle capacity on the orderbook to | ||
| recoup up to 20% of your spend. | ||
|
|
||
| Run 'sf migrate' to switch. Your current | ||
| CLI stays as 'sf-old'. | ||
|
|
||
| Docs: ${MIGRATION_GUIDE_URL} | ||
| Hide: SF_CLI_DISABLE_MIGRATE_BANNER=1`; | ||
|
|
||
| console.log( | ||
| boxen(chalk.yellow(message), { | ||
| padding: 1, | ||
| borderColor: "yellow", | ||
| borderStyle: "round", | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| export function registerMigrate(program: Command) { | ||
| return program | ||
| .command("migrate") | ||
| .description("Install the new Rust-based sf CLI") | ||
| .action(async () => { | ||
| const spinner = ora("Downloading install script").start(); | ||
| let script: string; | ||
| try { | ||
| const response = await fetch(NEW_CLI_INSTALL_URL); | ||
| if (!response.ok) { | ||
| spinner.fail("Failed to download install script."); | ||
| process.exit(1); | ||
| } | ||
| script = await response.text(); | ||
| spinner.succeed(); | ||
| } catch (err) { | ||
| spinner.fail("Failed to download install script."); | ||
| console.error(err); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log(chalk.cyan("\nInstalling the new Rust sf CLI...\n")); | ||
|
|
||
| if (process.env.IS_DEVELOPMENT_CLI_ENV) { | ||
| console.log( | ||
| chalk.yellow( | ||
| "[dev] Skipping install script execution (IS_DEVELOPMENT_CLI_ENV).\n", | ||
| ), | ||
| ); | ||
| } else { | ||
| const bashProcess = spawn("bash", [], { | ||
| stdio: ["pipe", "inherit", "inherit"], | ||
| env: process.env, | ||
| }); | ||
|
|
||
| // Without an error listener, spawn failures (ENOENT/EACCES on bash) emit | ||
| // an unhandled 'error' event and crash the CLI instead of exiting cleanly. | ||
| const spawnError = new Promise<Error>((resolve) => { | ||
| bashProcess.once("error", resolve); | ||
| }); | ||
|
|
||
| try { | ||
| bashProcess.stdin.write(script); | ||
| bashProcess.stdin.end(); | ||
| } catch { | ||
| // If stdin is already torn down (e.g. spawn failed synchronously), the | ||
| // 'error' event handler below will surface the real reason. | ||
| } | ||
|
|
||
| const result = await Promise.race([ | ||
| new Promise<{ kind: "close"; code: number | null }>((resolve) => { | ||
| bashProcess.once("close", (code) => | ||
| resolve({ kind: "close", code }), | ||
| ); | ||
| }), | ||
| spawnError.then((err) => ({ kind: "error" as const, err })), | ||
| ]); | ||
|
|
||
| if (result.kind === "error") { | ||
| console.error(chalk.red(`Failed to run bash: ${result.err.message}`)); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (result.code !== 0) { | ||
| console.error(chalk.red("\nMigration failed.")); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| console.log( | ||
| boxen( | ||
| chalk.cyan( | ||
| `You're on the new sf. | ||
|
|
||
| Your previous CLI is still available as 'sf-old'. | ||
|
|
||
| Next steps: | ||
| sf login | ||
| sf availability | ||
|
|
||
| Docs: ${MIGRATION_GUIDE_URL}`, | ||
| ), | ||
| { | ||
| padding: 1, | ||
| borderColor: "cyan", | ||
| borderStyle: "round", | ||
| }, | ||
| ), | ||
| ); | ||
| process.exit(0); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latent UX regression for non-default install paths: when
process.execPathis e.g./usr/local/bin/sf,install.shwill nowmkdir -p /usr/local/binandmv "${TMPDIR}/dist/sf-$target" /usr/local/bin/sf(lines 50 and 129 of install.sh) withoutsudo. Both calls EACCES for non-root users, so the upgrade fails after fetching/extracting — a worse UX than the previous behavior of silently dropping a duplicate at~/.local/bin/sf. The comment above explicitly chose this trade-off, so this is a callout, not necessarily a blocker — but if a user reportssf upgradesuddenly broken after this lands, this is the first place to look.