Skip to content

Commit 198e4b9

Browse files
committed
Enhance version check and upgrade command functionality
- Disable auto-upgrade if the environment variable SF_CLI_DISABLE_AUTO_UPGRADE is set. - Prevent automatic upgrades when on a prerelease version. - Add a force option to the upgrade command to allow upgrades even if the current version matches the specified version.
1 parent d746d3c commit 198e4b9

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/checkVersion.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ async function checkProductionCLIVersion() {
9393
}
9494

9595
export async function checkVersion() {
96+
// Disable auto-upgrade if env var is set
97+
if (process.env.SF_CLI_DISABLE_AUTO_UPGRADE) {
98+
return;
99+
}
100+
96101
// Skip version check if running upgrade command
97102
const args = process.argv.slice(2);
98103
if (args[0] === "upgrade") return;
@@ -109,6 +114,9 @@ export async function checkVersion() {
109114
const latestIsPrerelease = semver.prerelease(latestVersion);
110115
if (currentIsStable && latestIsPrerelease) return;
111116

117+
// Don't upgrade automatically if on prerelease
118+
if (semver.prerelease(version)) return;
119+
112120
const isOutdated = semver.lt(version, latestVersion);
113121
if (!isOutdated) return;
114122

src/lib/upgrade.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Command } from "@commander-js/extra-typings";
2-
import process from "node:process";
32
import * as console from "node:console";
3+
import process from "node:process";
44
import ora from "ora";
55

66
/**
@@ -30,8 +30,9 @@ export function registerUpgrade(program: Command) {
3030
return program
3131
.command("upgrade")
3232
.argument("[version]", "The version to upgrade to")
33+
.option("-f, --force", "Force upgrade even if already on specified version")
3334
.description("Upgrade to the latest version or a specific version")
34-
.action(async (version) => {
35+
.action(async (version, options) => {
3536
const spinner = ora();
3637
const currentVersion = program.version();
3738

@@ -49,13 +50,13 @@ export function registerUpgrade(program: Command) {
4950
}
5051

5152
// Check if user has already installed latest version.
52-
if (version === currentVersion) {
53+
if (version === currentVersion && !options.force) {
5354
spinner.succeed(`You are already on version ${currentVersion}.`);
5455
return;
5556
}
5657

5758
const isOnLatestVersion = await getIsOnLatestVersion(currentVersion);
58-
if (isOnLatestVersion) {
59+
if (isOnLatestVersion && !version && !options.force) {
5960
spinner.succeed(
6061
`You are already on the latest version (${currentVersion}).`,
6162
);

0 commit comments

Comments
 (0)