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 (issue #6111) #6445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aychtang
Copy link

@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

⚠️ No Changeset found

Latest commit: ed3860c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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 4, 2025 0:13am

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

2 participants