Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hydrogen upgrade command when using yarn as the package manager #2677

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
81 changes: 74 additions & 7 deletions packages/cli/src/commands/hydrogen/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import {
} from '@shopify/cli-kit/node/fs';
import {
getDependencies,
installNodeModules,
getPackageManager,
addNPMDependenciesIfNeeded,
type PackageJson,
type DependencyVersion,
} from '@shopify/cli-kit/node/node-package-manager';
import {AbortError} from '@shopify/cli-kit/node/error';
import {dirname, joinPath, resolvePath} from '@shopify/cli-kit/node/path';
Expand Down Expand Up @@ -645,13 +646,79 @@ export async function upgradeNodeModules({
{
title: `Upgrading dependencies`,
task: async () => {
await installNodeModules({
const packageManager = await getPackageManager(appPath);

/* Update prodDependencies */
const dependencies: DependencyVersion[] = Object.entries(
selectedRelease.dependencies,
)
.filter((dependency) => {
const shouldUpgradeDep = maybeIncludeDependency({
currentDependencies,
dependency,
selectedRelease,
});
if (shouldUpgradeDep) return dependency;
})
.map((dependency) => {
return {
name: dependency[0],
version: getAbsoluteVersion(dependency[1]),
};
});

await addNPMDependenciesIfNeeded(dependencies, {
type: 'prod',
directory: appPath,
packageManager: await getPackageManager(appPath),
args: buildUpgradeCommandArgs({
selectedRelease,
currentDependencies,
}),
packageManager: packageManager,
});

/* Update devDependencies */
const devDependencies: DependencyVersion[] = Object.entries(
selectedRelease.devDependencies,
)
.filter((dependency) => {
const shouldUpgradeDep = maybeIncludeDependency({
currentDependencies,
dependency,
selectedRelease,
});
if (shouldUpgradeDep) return dependency;
})
.map((dependency) => {
return {
name: dependency[0],
version: getAbsoluteVersion(dependency[1]),
};
});

await addNPMDependenciesIfNeeded(devDependencies, {
type: 'dev',
directory: appPath,
packageManager: packageManager,
});

/* Update Remix */
const remixDependencies: DependencyVersion[] = [];
for (const [name, version] of Object.entries(currentDependencies)) {
const isRemixPackage = isRemixDependency([name, version]);
const selectedRemix = Object.entries(
selectedRelease.dependencies,
).find(isRemixDependency);

if (!isRemixPackage || !selectedRemix) {
continue;
}
remixDependencies.push({
name: name,
version: getAbsoluteVersion(selectedRemix[1]),
});
}

await addNPMDependenciesIfNeeded(dependencies, {
type: 'prod',
directory: appPath,
packageManager: packageManager,
});
},
},
Expand Down
Loading