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
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/hot-birds-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Use `npm_config_user_agent` to determine what package manager to use for project creation
16 changes: 14 additions & 2 deletions packages/hardhat-core/src/internal/cli/project-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,24 @@ function isInstalled(dep: string) {
return dep in allDependencies;
}

function getProjectTypeFromUserAgent() {
const userAgent = process.env.npm_config_user_agent;
// Get first part of user agent string
const [projectType] = userAgent?.split("/") ?? [];
return projectType;
}

async function isYarnProject() {
return fsExtra.pathExists("yarn.lock");
return (
getProjectTypeFromUserAgent() === "yarn" || fsExtra.pathExists("yarn.lock")
);
}

async function isPnpmProject() {
return fsExtra.pathExists("pnpm-lock.yaml");
return (
getProjectTypeFromUserAgent() === "pnpm" ||
fsExtra.pathExists("pnpm-lock.yaml")
);
}

async function getProjectPackageManager(): Promise<PackageManager> {
Expand Down
Loading