Skip to content

Commit

Permalink
fix: Determine PM via the user-agent if no lockfile is found
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Nov 22, 2023
1 parent 96488b1 commit 35088a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-plants-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@melt-ui/cli': patch
---

fix: If no lockfile is found, install dependencies via the user-agent
10 changes: 10 additions & 0 deletions src/utils/get-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,15 @@ export async function getPackageManager(
if (packageManager === 'pnpm@6') return 'pnpm';
if (packageManager === 'bun') return 'bun';

// ni couldn't find a lockfile, so we'll try to determine the PM via the user agent
if (packageManager === null) {
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 packageManager ?? 'npm';
}

0 comments on commit 35088a0

Please sign in to comment.