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: correct package manager selection in CLI install #6445

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

aychtang
Copy link
Contributor

@aychtang aychtang commented Mar 4, 2025

  • Because this PR includes a bug fix, relevant tests have been included.
    (It seems there are no existing tests for the CLI installation yet, so I have kept the same level of testing for now and added my manual test below).
  • The change was previously discussed on an Issue or with someone from the team.

Description:

  • (issue Support pnpm dlx hardhat --init #6111) Franco noticed that the install script defaults to using npm in some cases, noting that its probably to do with checking the directories package manager related files.
  • Confirmed that the checks in project-creation.ts are checking for related .lock files, and therefore if the project isn't set up correctly then the CLI could use the wrong package manager.
  • Added a new function getProjectTypeFromUserAgent which extracts the first part of process.env.npm_config_user_agent, this is then added as the first check in the isYarnProject and isPnpmProject functions.
  • Note: This also removes the need to make a file system check in most cases.
  • Note: process.env.npm_config_user_agent might not be available on all OS, and we still default back to initial behaviour for now.
  • Rebuilt, packaged, and tested the change by printing the results of getProjectTypeFromUserAgent at start of CLI code.

Manual CLI test output:

howardtang hardhat-test % pnpm dlx $(pwd)/hardhat-2.22.19.tgz init
 WARN  3 deprecated subdependencies found: [email protected], [email protected], [email protected]
Packages: +243
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 243, reused 242, downloaded 1, added 243, done
aychtang/hardhat
userAgent pnpm/8.8.0 npm/? node/v20.8.0 darwin arm64
projectType pnpm

Copy link

changeset-bot bot commented Mar 4, 2025

🦋 Changeset detected

Latest commit: add0158

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 Mar 4, 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 11, 2025 9:20pm

@aychtang aychtang changed the title fix: correct package manager selection in CLI install (#6111) fix: correct package manager selection in CLI install (issue #6111) Mar 4, 2025
@kanej kanej requested a review from galargh March 11, 2025 10: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.

Great job! Thank you for your contribution 🙇 I allowed myself to add a changeset to your PR. Once the CI is through, I'm going to merge this 🚀

@aychtang aychtang changed the title fix: correct package manager selection in CLI install (issue #6111) fix: correct package manager selection in CLI install Mar 11, 2025
@galargh galargh merged commit a5419a7 into NomicFoundation:main Mar 11, 2025
129 checks passed
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.

3 participants