[Phase 1] Port auto-upgrade POC to main#6999
Draft
alfonso-noriega wants to merge 5 commits intomainfrom
Draft
Conversation
- shopify upgrade now prompts to opt in to automatic upgrades and runs the upgrade - postrun hook auto-upgrades the CLI after a command when a newer version is cached and the user has opted in; shows a warning instead for major version bumps - prerun hook replaced warnOnAvailableUpgrade with a non-blocking checkForNewVersion - is-global: replaced npm-prefix execa call with getProjectDir (walks up for shopify.app*.toml / hydrogen.config.*); added Homebrew detection via symlink, /cellar/, SHOPIFY_HOMEBREW_FORMULA, HOMEBREW_PREFIX - upgrade: full rewrite — cliInstallCommand returns string|undefined with homebrew support; new runCLIUpgrade, versionToAutoUpgrade, promptAutoUpgrade, local upgrade helpers - conf-store: autoUpgradeEnabled flag + getAutoUpgradeEnabled / setAutoUpgradeEnabled - node-package-manager: homebrew added to PackageManager type; guarded addNPMDependencies - fs: added findPathUpSync (sync wrapper around find-up's findUpSync) - version: added isMajorVersionChange Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Mar 13, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/private/node/conf-store.d.ts@@ -24,6 +24,7 @@ export interface ConfSchema {
devSessionStore?: string;
currentDevSessionId?: string;
cache?: Cache;
+ autoUpgradeEnabled?: boolean;
}
/**
* Get session.
@@ -125,6 +126,18 @@ interface RunWithRateLimitOptions {
* @returns true, or undefined if the task was not run.
*/
export declare function runWithRateLimit(options: RunWithRateLimitOptions, config?: LocalStorage<ConfSchema>): Promise<boolean>;
+/**
+ * Get auto-upgrade preference.
+ *
+ * @returns Whether auto-upgrade is enabled, or undefined if not set.
+ */
+export declare function getAutoUpgradeEnabled(config?: LocalStorage<ConfSchema>): boolean | undefined;
+/**
+ * Set auto-upgrade preference.
+ *
+ * @param enabled - Whether auto-upgrade should be enabled.
+ */
+export declare function setAutoUpgradeEnabled(enabled: boolean, config?: LocalStorage<ConfSchema>): void;
export declare function getConfigStoreForPartnerStatus(): LocalStorage<Record<string, {
status: true;
checkedAt: string;
packages/cli-kit/dist/public/node/fs.d.ts@@ -1,6 +1,6 @@
import { OverloadParameters } from '../../private/common/ts/overloaded-parameters.js';
import { RandomNameFamily } from '../common/string.js';
-import { findUp as internalFindUp } from 'find-up';
+import { findUp as internalFindUp, findUpSync as internalFindUpSync } from 'find-up';
import { ReadStream, WriteStream } from 'fs';
import type { Pattern, Options as GlobOptions } from 'fast-glob';
/**
@@ -335,6 +335,7 @@ export declare function defaultEOL(): EOL;
* @returns The first path found that matches or if none could be found.
*/
export declare function findPathUp(matcher: OverloadParameters<typeof internalFindUp>[0], options: OverloadParameters<typeof internalFindUp>[1]): ReturnType<typeof internalFindUp>;
+export declare function findPathUpSync(matcher: OverloadParameters<typeof internalFindUp>[0], options: OverloadParameters<typeof internalFindUp>[1]): ReturnType<typeof internalFindUpSync>;
export interface MatchGlobOptions {
matchBase: boolean;
noglobstar: boolean;
packages/cli-kit/dist/public/node/is-global.d.ts@@ -26,6 +26,14 @@ export declare function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPrompt
* Infers the package manager used by the global CLI.
*
* @param argv - The arguments passed to the process.
+ * @param env - The environment variables of the process.
* @returns The package manager used by the global CLI.
*/
-export declare function inferPackageManagerForGlobalCLI(argv?: string[]): PackageManager;
\ No newline at end of file
+export declare function inferPackageManagerForGlobalCLI(argv?: string[], env?: NodeJS.ProcessEnv): PackageManager;
+/**
+ * Returns the project directory for the given path.
+ *
+ * @param directory - The path to the directory to get the project directory for.
+ * @returns The project directory for the given path.
+ */
+export declare function getProjectDir(directory: string): string | undefined;
\ No newline at end of file
packages/cli-kit/dist/public/node/node-package-manager.d.ts@@ -25,7 +25,7 @@ export type DependencyType = 'dev' | 'prod' | 'peer';
/**
* A union that represents the package managers available.
*/
-export declare const packageManager: readonly ["yarn", "npm", "pnpm", "bun", "unknown"];
+export declare const packageManager: readonly ["yarn", "npm", "pnpm", "bun", "unknown", "homebrew"];
export type PackageManager = (typeof packageManager)[number];
/**
* Returns an abort error that's thrown when the package manager can't be determined.
packages/cli-kit/dist/public/node/upgrade.d.ts@@ -2,13 +2,34 @@
* Utility function for generating an install command for the user to run
* to install an updated version of Shopify CLI.
*
- * @returns A string with the command to run.
+ * @returns A string with the command to run, or undefined if the package manager cannot be determined.
*/
-export declare function cliInstallCommand(): string;
+export declare function cliInstallCommand(): string | undefined;
+/**
+ * Runs the CLI upgrade using the appropriate package manager.
+ * Determines the install command and executes it.
+ *
+ * @throws Error if the package manager or command cannot be determined.
+ */
+export declare function runCLIUpgrade(): Promise<void>;
+/**
+ * Returns the version to auto-upgrade to, or undefined if auto-upgrade should be skipped.
+ * Auto-upgrade is disabled by default and must be enabled via .
+ * Also skips for CI, pre-release versions, or when no newer version is available.
+ *
+ * @returns The version string to upgrade to, or undefined if no upgrade should happen.
+ */
+export declare function versionToAutoUpgrade(): string | undefined;
/**
* Generates a message to remind the user to update the CLI.
*
* @param version - The version to update to.
* @returns The message to remind the user to update the CLI.
*/
-export declare function getOutputUpdateCLIReminder(version: string): string;
\ No newline at end of file
+export declare function getOutputUpdateCLIReminder(version: string): string;
+/**
+ * Prompts the user to enable or disable automatic upgrades, then persists their choice.
+ *
+ * @returns Whether the user chose to enable auto-upgrade.
+ */
+export declare function promptAutoUpgrade(): Promise<boolean>;
\ No newline at end of file
packages/cli-kit/dist/public/node/version.d.ts@@ -18,4 +18,13 @@ export declare function globalCLIVersion(): Promise<string | undefined>;
* @param version - The version to check.
* @returns True if the version is a pre-release version.
*/
-export declare function isPreReleaseVersion(version: string): boolean;
\ No newline at end of file
+export declare function isPreReleaseVersion(version: string): boolean;
+/**
+ * Checks if there is a major version change between two versions.
+ * Pre-release versions (0.0.0-*) are treated as not having a major version change.
+ *
+ * @param currentVersion - The current version.
+ * @param newerVersion - The newer version to compare against.
+ * @returns True if there is a major version change.
+ */
+export declare function isMajorVersionChange(currentVersion: string, newerVersion: string): boolean;
\ No newline at end of file
packages/cli-kit/dist/public/node/hooks/postrun.d.ts@@ -5,4 +5,10 @@ import { Hook } from '@oclif/core';
* @returns Whether post run hook has completed.
*/
export declare function postRunHookHasCompleted(): boolean;
-export declare const hook: Hook.Postrun;
\ No newline at end of file
+export declare const hook: Hook.Postrun;
+/**
+ * Auto-upgrades the CLI after a command completes, if a newer version is available.
+ *
+ * @returns Resolves when the upgrade attempt (or fallback warning) is complete.
+ */
+export declare function autoUpgradeIfNeeded(): Promise<void>;
\ No newline at end of file
packages/cli-kit/dist/public/node/hooks/prerun.d.ts@@ -11,6 +11,7 @@ export declare function parseCommandContent(cmdInfo: {
pluginAlias?: string;
}): CommandContent;
/**
- * Warns the user if there is a new version of the CLI available
+ * Triggers a background check for a newer CLI version (non-blocking).
+ * The result is cached and consumed by the postrun hook for auto-upgrade.
*/
-export declare function warnOnAvailableUpgrade(): Promise<void>;
\ No newline at end of file
+export declare function checkForNewVersionInBackground(): void;
\ No newline at end of file
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Ports the auto-upgrade POC from
origin/auto-upgradetomainin a productionized form.shopify upgradenow prompts the user to opt in to automatic upgrades, then runs the upgradeautoUpgradeIfNeeded()after every command (exceptupgradeandnotifications): auto-upgrades silently for minor/patch bumps, shows a warning for major version changeswarnOnAvailableUpgrade(with its rate-limit wrapper) with a simple non-blockingcheckForNewVersionInBackground()— the result is consumed by the postrun hookinferPackageManagerForGlobalCLI(via symlink resolution,/cellar/path,SHOPIFY_HOMEBREW_FORMULA,HOMEBREW_PREFIX)getProjectDir()replaces the oldnpm prefixexeca call incurrentProcessIsGlobal()versionToAutoUpgrade()guards: CI, pre-release, not-enabled,SHOPIFY_CLI_FORCE_AUTO_UPGRADEoverrideautoUpgradeEnabledpersisted in conf-store; defaultsfalseDeferred to separate issues
SHOPIFY_CLI_NO_AUTO_UPGRADEescape hatch → shop/issues-develop#22364Test plan
pnpm vitest run src/public/node/upgrade.test.ts src/public/node/hooks/postrun.test.ts src/public/node/hooks/prerun.test.ts src/public/node/is-global.test.ts src/public/node/version.test.ts— 36/36 passcd packages/cli && pnpm vitest run src/cli/commands/upgrade.test.ts— 1/1 pass@shopify/cli-kitsuite — 119 files, 1232 tests, 0 failures@shopify/clisuite — 11 files, 18 tests, 0 failuresTracking
🤖 Generated with Claude Code