Fix autoupgrade incorrectly treating pnpm shopify (from CLI repo) as global#7313
Fix autoupgrade incorrectly treating pnpm shopify (from CLI repo) as global#7313alfonso-noriega wants to merge 1 commit intomainfrom
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
…global When running `pnpm shopify` from the CLI repo, getProjectDir returns undefined because there is no shopify.app.toml or hydrogen.config.js in the repo. The previous code immediately returned true (global) in that case, causing autoupgrade to fire as if the CLI were globally installed. Fix: when no app/hydrogen project is found, fall back to checking whether the binary (argv[1]) is inside a pnpm workspace root (detected via pnpm-workspace.yaml). If it is, the process is local and autoupgrade is skipped.
6c59415 to
f456318
Compare
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/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.
*
|
gonzaloriestra
left a comment
There was a problem hiding this comment.
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 This fix is actually addressing a problem with But yes, we could actually just check |
|
|

WHY are these changes introduced?
When running
pnpm shopifyfrom 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:
currentProcessIsGlobal()inis-global.tssearches upward from the working directory for ashopify.app.tomlorhydrogen.config.{js,ts}to identify a local project. The CLI repo has neither, sogetProjectDir()returnsundefined— and the previous code immediately returnedtrue(global) without checking whether the binary itself is inside the repo.WHAT is this pull request doing?
Adds a
getWorkspaceRoot()helper that walks up fromcwd()looking for apnpm-workspace.yaml. When no app/hydrogen project is found,currentProcessIsGlobal()now falls back to checking whetherargv[1](the binary) lives inside that workspace root before concluding the process is global.If the binary is within the workspace, the process is correctly identified as local and autoupgrade is skipped.
How to test your changes?
pnpm shopify versionpnpm shopify upgrade→ opt inYou can also force the autoupgrade check with:
Before this fix: upgrade runs (treats the process as global).
After this fix: upgrade is skipped (correctly identified as local).
Checklist
pnpm changeset add