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

Conversation

dsnvs
Copy link

@dsnvs dsnvs commented Dec 13, 2024

WHY are these changes introduced?

hydrogen upgrade command currently uses installNodeModules() from the cli-kit to upgrade packages, this function uses install as the arg for the package manager, and when using yarn, the arg for adding new dependencies (or updating existing ones) is add.

WHAT is this pull request doing?

It updates the hydrogen upgrade command to instead use addNPMDependenciesIfNeeded() (also from cli-kit) which appears to be the most adequate solution for this command.

HOW to test your changes?

Upgrade hydrogen from an older version to a newer version using yarn (and other package managers to validate they also work as expected).

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@dsnvs
Copy link
Author

dsnvs commented Dec 13, 2024

I have signed the CLA!

@wizardlyhel
Copy link
Contributor

Mmm .. didn't realize that yarn didn't work for hydrogen upgrade. Thanks for the catch.

There are a couple problems that we identify with this approach:

  1. addNPMDependenciesIfNeeded skips dependencies that are already included in package.json. That means it won't update the versions, as far as we understand.
  2. It splits the installation in 3 steps: prod, dev, remix. That's going to be slower than doing it all at once.
  3. It stops using buildUpgradeCommandArgs, which is the function we test in upgrade.test.ts. If the way we install deps change, we should update the tests accordingly to have the new path covered.
  4. There are only check for remix dependencies for the prod dependencies but didn't check for the dev dependencies. Since this command modifies package.json in the end, the remix dev dependencies version should match those in dependencies list

Since the actual problem is in installNodeModules where it assumes the args is install, I think a simpler fix is actually in the cli-kit itself https://github.com/Shopify/cli/blob/main/packages/cli-kit/src/public/node/node-package-manager.ts#L202
In that function, we know what package manager is being used. It's simpler to make the change there.

Copy link
Contributor

@wizardlyhel wizardlyhel left a comment

Choose a reason for hiding this comment

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

^

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.

2 participants