From 15b9eba61a93bb030ecb50bb7180994e818f4da2 Mon Sep 17 00:00:00 2001 From: Dhai Date: Fri, 27 Dec 2024 20:58:13 +0530 Subject: [PATCH] use constants for package manager names --- .../create-fuels/src/lib/getPackageManager.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/create-fuels/src/lib/getPackageManager.ts b/packages/create-fuels/src/lib/getPackageManager.ts index 654b338172..f4893d37c9 100644 --- a/packages/create-fuels/src/lib/getPackageManager.ts +++ b/packages/create-fuels/src/lib/getPackageManager.ts @@ -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 = () => {