Skip to content

Commit

Permalink
undo: try with user defined agent first
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolguevara committed Aug 13, 2024
1 parent dc2a1ee commit 49c6be2
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/cli/src/utils/get-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import process from "node:process";
import { findUp } from "find-up";

export async function getPackageManager(targetDir: string) {
const userAgent = process.env.npm_config_user_agent;
if (userAgent) {
// try to determine the PM via the user agent first
if (userAgent === undefined) return "npm";
if (userAgent.startsWith("yarn")) return "yarn";
if (userAgent.startsWith("pnpm")) return "pnpm";
}

const packageManager = await detect(targetDir);

if (packageManager === "yarn@berry") return "yarn";
Expand All @@ -20,6 +12,12 @@ export async function getPackageManager(targetDir: string) {
// ni successfully detected a PM
if (packageManager !== null) return packageManager;

// ni couldn't find a lockfile, so we'll try to determine the PM via the user agent
const userAgent = process.env.npm_config_user_agent;
if (userAgent === undefined) return "npm";
if (userAgent.startsWith("yarn")) return "yarn";
if (userAgent.startsWith("pnpm")) return "pnpm";

// default to npm as the last resort
return "npm";
}
Expand Down

0 comments on commit 49c6be2

Please sign in to comment.