Skip to content

Commit

Permalink
use constants for package manager names
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 committed Dec 27, 2024
1 parent 2c5fcb6 commit 15b9eba
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/create-fuels/src/lib/getPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,43 @@ const runnableApplicator =
(command: string = '') =>
`${commandPrefix} ${command}`;

export const packageMangers = {
export const packageMangers: Record<
PackageManager,
{
install: string;
run: (command: string) => string;
name: PackageManager;
}
> = {
pnpm: {
install: 'pnpm install',
run: runnableApplicator('pnpm'),
name: 'pnpm',
},
npm: {
install: 'npm install',
run: runnableApplicator('npm run'),
name: 'npm',
},
bun: {
install: 'bun install',
run: runnableApplicator('bun run'),
name: 'bun',
},
} as const;

export function getUserPkgManager(): PackageManager {
const userAgent = process.env.npm_config_user_agent || '';

if (userAgent.startsWith('pnpm')) {
return 'pnpm';
if (userAgent.startsWith(packageMangers.pnpm.name)) {
return packageMangers.pnpm.name;
}

if (userAgent.startsWith('bun')) {
return 'bun';
if (userAgent.startsWith(packageMangers.bun.name)) {
return packageMangers.bun.name;
}

return 'npm';
return packageMangers.npm.name;
}

export const getPackageManager = () => {
Expand Down

0 comments on commit 15b9eba

Please sign in to comment.