Skip to content

Commit a5419a7

Browse files
aychtanggalargh
andauthored
fix: correct package manager selection in CLI install (#6445)
* fix: correct package manager selection in CLI install * chore: add changeset --------- Co-authored-by: galargh <[email protected]>
1 parent 5451baf commit a5419a7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/hot-birds-cover.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Use `npm_config_user_agent` to determine what package manager to use for project creation

packages/hardhat-core/src/internal/cli/project-creation.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,24 @@ function isInstalled(dep: string) {
554554
return dep in allDependencies;
555555
}
556556

557+
function getProjectTypeFromUserAgent() {
558+
const userAgent = process.env.npm_config_user_agent;
559+
// Get first part of user agent string
560+
const [projectType] = userAgent?.split("/") ?? [];
561+
return projectType;
562+
}
563+
557564
async function isYarnProject() {
558-
return fsExtra.pathExists("yarn.lock");
565+
return (
566+
getProjectTypeFromUserAgent() === "yarn" || fsExtra.pathExists("yarn.lock")
567+
);
559568
}
560569

561570
async function isPnpmProject() {
562-
return fsExtra.pathExists("pnpm-lock.yaml");
571+
return (
572+
getProjectTypeFromUserAgent() === "pnpm" ||
573+
fsExtra.pathExists("pnpm-lock.yaml")
574+
);
563575
}
564576

565577
async function getProjectPackageManager(): Promise<PackageManager> {

0 commit comments

Comments
 (0)