From ed3860cd4b04dfb747180a75ed4abbe32248fc4f Mon Sep 17 00:00:00 2001 From: aychtang Date: Tue, 4 Mar 2025 12:09:55 +0000 Subject: [PATCH 1/2] fix: correct package manager selection in CLI install --- .../src/internal/cli/project-creation.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/hardhat-core/src/internal/cli/project-creation.ts b/packages/hardhat-core/src/internal/cli/project-creation.ts index 4cf3c880d1..0c0bc976cb 100644 --- a/packages/hardhat-core/src/internal/cli/project-creation.ts +++ b/packages/hardhat-core/src/internal/cli/project-creation.ts @@ -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 { From add0158f901fae7bb8a13eed1648ea183d3f4a26 Mon Sep 17 00:00:00 2001 From: galargh Date: Tue, 11 Mar 2025 22:16:58 +0100 Subject: [PATCH 2/2] chore: add changeset --- .changeset/hot-birds-cover.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hot-birds-cover.md diff --git a/.changeset/hot-birds-cover.md b/.changeset/hot-birds-cover.md new file mode 100644 index 0000000000..fa3b910715 --- /dev/null +++ b/.changeset/hot-birds-cover.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Use `npm_config_user_agent` to determine what package manager to use for project creation