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: bug in semver check on installProjectDependencies #6426

Merged
merged 5 commits into from
Mar 4, 2025

Conversation

antico5
Copy link
Contributor

@antico5 antico5 commented Feb 27, 2025

The parameter order was inverted when calling semver.satisfies() and semver.intersects() on installProjectDependencies

Closes #6323

@antico5 antico5 requested a review from galargh February 27, 2025 18:19
Copy link

changeset-bot bot commented Feb 27, 2025

🦋 Changeset detected

Latest commit: 83c0156

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 4:03pm

@kanej kanej linked an issue Feb 28, 2025 that may be closed by this pull request
@kanej kanej requested review from kanej and removed request for galargh February 28, 2025 13:40
Copy link
Member

@galargh galargh left a comment

Choose a reason for hiding this comment

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

This is a great catch! Thank you for fixing it 🙇

packageJson: {
name: "test",
version: "0.0.1",
devDependencies: { hardhat: "^3.0.0-next.0" }, // <-- required version
Copy link
Member

Choose a reason for hiding this comment

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

When reading through it for the first time, I started worrying and double-checking if we were going to have to update the version here with every release. Now I know we don't, but I guess we could still consider using clearly fake dependency to avoid that momentary confusion for others in the future. Something like:

Suggested change
devDependencies: { hardhat: "^3.0.0-next.0" }, // <-- required version
devDependencies: { fake-dependency: "^1.2.3-dev" }, // <-- required version

It's all correct so I'm not requesting this change definitively. Just putting it out there to consider if you want to.

!semver.satisfies(version, workspaceVersion) &&
!semver.intersects(version, workspaceVersion)
!semver.satisfies(workspaceVersion, version) &&
!semver.intersects(workspaceVersion, version)
Copy link
Member

Choose a reason for hiding this comment

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

Why does this test include intersects? Why not just satisfies?

@galargh

Copy link
Member

Choose a reason for hiding this comment

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

That's in case the workspaceVersion (the one that user has currently defined in their package) is a range rather than an exact version.

However, now I wonder why can't we use just intersects. I would assume that if the workspaceVersion is a single version rather than a range, the intersection with a range should still work. Let me double-check that.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so the intersects works only for ranges and a specific version is not considered a range.

Copy link
Member

@kanej kanej Mar 4, 2025

Choose a reason for hiding this comment

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

But is this a safe move? Could I not have an installed version say >= 1.0.0 and a required version of >= 1.2.3 and these would intersect - but we would say that we should update the installed version in this case?

Is it not that we want to ensure that the installed version range is a subset of the required range:

subset(subRange, superRange): Return true if the subRange range is entirely contained by the superRange range.

https://www.npmjs.com/package/semver#ranges-1

Copy link
Member

Choose a reason for hiding this comment

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

That's a great point! We didn't account for the workspace version being "too high" in the initial implementation of this function.

I went ahead and refactored the logic here a bit to be able to better test in what scenario an update should happen.

See #6446

Feel free to merge if you think that's useful.

kanej added 2 commits March 4, 2025 14:21
Use an example that clarifies the reason for the test, unconnected with
any implication around the hardhat package.
Copy link
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

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

LGTM!

@kanej kanej added this pull request to the merge queue Mar 4, 2025
Merged via the queue into v-next with commit 82946e3 Mar 4, 2025
76 checks passed
@kanej kanej deleted the hardhat-init-reinstall branch March 4, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

init triggering unnecessary re-install of Hardhat
3 participants