Skip to content

Fix autoupgrade incorrectly skipping in development mode#7313

Merged
alfonso-noriega merged 1 commit intomainfrom
fix-autoupgrade-pnpm-detection
Apr 17, 2026
Merged

Fix autoupgrade incorrectly skipping in development mode#7313
alfonso-noriega merged 1 commit intomainfrom
fix-autoupgrade-pnpm-detection

Conversation

@alfonso-noriega
Copy link
Copy Markdown
Contributor

@alfonso-noriega alfonso-noriega commented Apr 15, 2026

WHY are these changes introduced?

When running `pnpm shopify` from the CLI repo itself, autoupgrade incorrectly fires as if the CLI were globally installed. This causes contributors to see unexpected upgrade attempts during local development.

Root cause: The previous guard was `!isGlobal && isDevelopment()`, which only skipped the upgrade when both conditions were true. But `currentProcessIsGlobal()` misidentified a pnpm run from the CLI repo as global (since there's no `shopify.app.toml` to detect a local project), so the guard never triggered.

WHAT is this pull request doing?

Simplifies the guard to just `isDevelopment()`. `isDevelopment()` checks `SHOPIFY_CLI_ENV === development`, which is only set by the CLI repo's pnpm dev scripts — not by a globally-installed binary, even if run from the CLI folder. So contributors are protected and regular users are unaffected.

How to test your changes?

  1. From the root of the CLI repo, run any command: `pnpm shopify version`
  2. Enable autoupgrade first if needed: `pnpm shopify upgrade` → opt in
  3. Confirm no upgrade attempt is made after the command completes

You can also force the autoupgrade check with:

```
SHOPIFY_CLI_FORCE_AUTO_UPGRADE=1 pnpm shopify version
```

Before this fix: upgrade runs (SHOPIFY_CLI_ENV=development is set but `!isGlobal` was false, so the guard was skipped).
After this fix: upgrade is skipped (isDevelopment() returns true).

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing, so I've added a changelog entry with `pnpm changeset add`

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@alfonso-noriega alfonso-noriega force-pushed the fix-autoupgrade-pnpm-detection branch from 6c59415 to f456318 Compare April 15, 2026 16:45
@github-actions
Copy link
Copy Markdown
Contributor

Differences in type declarations

We 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:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/is-global.d.ts
@@ -30,6 +30,14 @@ export declare function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPrompt
  * @returns The package manager used by the global CLI.
  */
 export declare function inferPackageManagerForGlobalCLI(argv?: string[], env?: NodeJS.ProcessEnv): PackageManager;
+/**
+ * Returns the workspace (monorepo) root for the given path by searching upward
+ * for a pnpm-workspace.yaml file.
+ *
+ * @param directory - The path to search upward from.
+ * @returns The workspace root directory, or undefined if not in a workspace.
+ */
+export declare function getWorkspaceRoot(directory: string): string | undefined;
 /**
  * Returns the project directory for the given path.
  *

@alfonso-noriega alfonso-noriega marked this pull request as ready for review April 16, 2026 09:32
@alfonso-noriega alfonso-noriega requested a review from a team as a code owner April 16, 2026 09:32
Copy link
Copy Markdown
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just adding another guard clause before to check if isDevelopment()? In that case, just skip the auto-upgrade before checking if it's global or not.

This code seems a bit complex and our dev environment is a bit of a special case...

Copy link
Copy Markdown
Contributor Author

What about just adding another guard clause before to check if isDevelopment()? In that case, just skip the auto-upgrade before checking if it's global or not.

This code seems a bit complex and our dev environment is a bit of a special case...

​we are currently checking isDevelopment && !isGlobal to decide that we are running the local sources of the CLI. The problem with just checking isDevelopment() is that we may run global from the CLI folder.

This fix is actually addressing a problem with isGlobal assuming that if we are not in a project dir then we are running a global instance.

But yes, we could actually just check isDevelopment and there would be a small amount of times that we fail to run upgrade for CLI contributors only

Copy link
Copy Markdown
Contributor

isDevelopment() simply checks if SHOPIFY_CLI_ENV === development,so if you just run a global CLI in the CLI folder, it should be false.

Use isDevelopment() as the sole guard instead of the previous workspace-root
detection. isDevelopment() checks SHOPIFY_CLI_ENV=development, which is only
set by the pnpm dev scripts, so global CLI runs from the CLI folder are
unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@alfonso-noriega alfonso-noriega force-pushed the fix-autoupgrade-pnpm-detection branch from f456318 to a92af4d Compare April 17, 2026 12:28
@alfonso-noriega alfonso-noriega changed the title Fix autoupgrade incorrectly treating pnpm shopify (from CLI repo) as global Fix autoupgrade incorrectly skipping in development mode Apr 17, 2026

// Don't auto-upgrade for development mode
if (!isGlobal && isDevelopment()) {
if (isDevelopment()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no test for this which needs updated?

@alfonso-noriega alfonso-noriega added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit 8d7074e Apr 17, 2026
25 checks passed
@alfonso-noriega alfonso-noriega deleted the fix-autoupgrade-pnpm-detection branch April 17, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants