Skip to content

Use bun for autoupgrade when CLI installed via bun add -g#7556

Merged
alfonso-noriega merged 1 commit into
mainfrom
bun-autoupgrade-uses-bun-not-npm
May 15, 2026
Merged

Use bun for autoupgrade when CLI installed via bun add -g#7556
alfonso-noriega merged 1 commit into
mainfrom
bun-autoupgrade-uses-bun-not-npm

Conversation

@alfonso-noriega
Copy link
Copy Markdown
Contributor

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

WHY are these changes introduced?

When the global Shopify CLI is installed via bun add -g @shopify/cli, the autoupgrade flow incorrectly shells out to npm install -g @shopify/cli@latest instead of using bun. Reproduction:

$ SHOPIFY_CLI_FORCE_AUTO_UPGRADE=1 shopify version
0.0.0-snapshot-20260513102036
Upgrading Shopify CLI by running: `npm install -g @shopify/cli@latest`...
npm is no longer supported in a global context.
Please migrate to pnpm, or come talk to us in #dev-up.
💡 Version 3.94.3 available! Run `npm install -g @shopify/cli@latest`
$ which shopify
/Users/fonso/.bun/bin/shopify

Root cause: inferPackageManagerForGlobalCLI in packages/cli-kit/src/public/node/is-global.ts only looked at the resolved realpathSync(argv[1]) to decide which package manager to use. But bun add -g creates ~/.bun/bin/<name> as a symlink whose target is ../../node_modules/<pkg>/bin/run.js, which resolves to <HOME>/node_modules/<pkg>/bin/run.js — a path that no longer contains the string bun. Detection fell through to the default npm branch, so the autoupgrade and the upgrade-available reminder both suggested the wrong command.

WHAT is this pull request doing?

  • Inspects both the unresolved symlink path (argv[1], e.g. ~/.bun/bin/shopify) and the resolved real path when matching the yarn / pnpm / bun signal. The original symlink under the package manager's bin dir is the most reliable indicator when the real path leaves that directory.
  • Keeps the existing Homebrew detection (env var first, then /cellar/ in the resolved path) unchanged.
  • Adds a regression test that mirrors the exact reproduction: a symlink at ~/.bun/bin/shopify resolving to <HOME>/node_modules/@shopify/cli/bin/run.js.

How to test your changes?

  1. Install bun (e.g. via Homebrew: brew install bun).
  2. bun add -g @shopify/cli and confirm which shopify returns a path under ~/.bun/bin.
  3. With this branch's cli-kit build, run SHOPIFY_CLI_FORCE_AUTO_UPGRADE=1 shopify version.
  4. Expected: the upgrade message reads Upgrading Shopify CLI by running: `bun install -g @shopify/cli@latest`... and bun (not npm) performs the install.

Unit tests:

pnpm --filter @shopify/cli-kit vitest run src/public/node/is-global.test.ts

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows) — fix is symmetric across platforms; the only path-shape assumption is that bun's bin dir contains the substring bun, which holds on all OSes.
  • I've considered possible documentation changes — none needed; behavior matches what users already expect.
  • I've considered analytics changes to measure impact — none needed.
  • The change is user-facing — bug fix, but no changeset is included in this PR per request. If shipped on its own it should be a patch.

bun add -g installs the global binary as a symlink that resolves out of ~/.bun (typically into <HOME>/node_modules), so the resolved real path no longer contains 'bun' and package-manager detection fell through to npm. This made the autoupgrade flow shell out to 'npm install -g @shopify/cli@latest' for users who installed the CLI with bun.

Also inspect the unresolved symlink path (argv[1]) when matching the yarn/pnpm/bun signal.
@alfonso-noriega alfonso-noriega requested a review from a team as a code owner May 15, 2026 09:36
Copy link
Copy Markdown
Contributor Author

alfonso-noriega commented May 15, 2026

@github-actions github-actions Bot added the no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users. label May 15, 2026
@alfonso-noriega
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

🫰✨ Thanks @alfonso-noriega! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/[email protected]

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Base automatically changed from bun-executes-npm-to-autoupgrade to main May 15, 2026 11:31
@alfonso-noriega alfonso-noriega added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit e23c9d0 May 15, 2026
25 of 27 checks passed
@alfonso-noriega alfonso-noriega deleted the bun-autoupgrade-uses-bun-not-npm branch May 15, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This PR doesn't include a changeset entry. Is an internal only change not relevant to end users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants