Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-yarn-upgrade-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Fix `hydrogen upgrade` failing with yarn and pnpm by using the correct package-specific install subcommand (`add` for yarn/pnpm, `install` for npm/bun) when upgrading dependencies
44 changes: 33 additions & 11 deletions packages/cli/src/commands/hydrogen/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from '@shopify/cli-kit/node/fs';
import {
getDependencies,
installNodeModules,
getPackageManager,
type PackageJson,
} from '@shopify/cli-kit/node/node-package-manager';
Comment thread
kdaviduik marked this conversation as resolved.
Expand Down Expand Up @@ -892,7 +891,9 @@ export async function upgradeNodeModules({
});
}

// Then install/upgrade dependencies
// Install/upgrade dependencies using exec() directly instead of cli-kit's
// installNodeModules(), which runs `<pm> install` and doesn't support adding
// specific packages with version specifiers (yarn/pnpm require `add`).
const upgradeArgs = buildUpgradeCommandArgs({
selectedRelease,
currentDependencies,
Expand All @@ -903,11 +904,24 @@ export async function upgradeNodeModules({
tasks.push({
title: `Upgrading dependencies`,
task: async () => {
await installNodeModules({
directory: appPath,
packageManager: await getPackageManager(appPath),
args: upgradeArgs,
});
const packageManager = await getPackageManager(appPath);
const command =
packageManager === 'npm'
? 'install'
: packageManager === 'yarn'
? 'add'
: packageManager === 'pnpm'
? 'add'
: packageManager === 'bun'
? 'install'
: 'install'; // fallback to npm for 'unknown'
await exec(
resolvePackageManagerName(packageManager),
[command, ...upgradeArgs],
{
cwd: appPath,
},
);
},
});
}
Expand All @@ -917,6 +931,15 @@ export async function upgradeNodeModules({
}
}

/**
* Normalizes the package manager name, falling back to npm for 'unknown'.
*/
function resolvePackageManagerName(
packageManager: 'npm' | 'yarn' | 'pnpm' | 'unknown' | 'bun',
): 'npm' | 'yarn' | 'pnpm' | 'bun' {
return packageManager === 'unknown' ? 'npm' : packageManager;
}

/**
* Uninstalls the specified dependencies
*/
Expand All @@ -942,10 +965,9 @@ async function uninstallNodeModules({
? 'remove'
: 'uninstall'; // fallback to npm for 'unknown'

const actualPackageManager =
packageManager === 'unknown' ? 'npm' : packageManager;

await exec(actualPackageManager, [command, ...args], {cwd: directory});
await exec(resolvePackageManagerName(packageManager), [command, ...args], {
cwd: directory,
});
}

/**
Expand Down
Loading