Skip to content

Commit

Permalink
fix(create-clarity-feature): detect package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed May 3, 2024
1 parent f574aa6 commit efa3c58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/create-clarity-feature/src/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from 'fs-extra'
import dedent from 'dedent-js'
import chalk from 'chalk'
import validateNpmPackageName from 'validate-npm-package-name'
import { getPackageManager } from '../../getPackageManager'

export const command = '$0'
export const description = `create a new Clarity feature project`
Expand Down Expand Up @@ -154,7 +155,7 @@ export async function handler(): Promise<void> {
})
)

const packageManager = 'pnpm'
const packageManager = getPackageManager()

// eslint-disable-next-line no-console
console.error(dedent`
Expand Down
19 changes: 19 additions & 0 deletions packages/create-clarity-feature/src/getPackageManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'

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

if (userAgent.startsWith('yarn')) {
return 'yarn'
}

if (userAgent.startsWith('pnpm')) {
return 'pnpm'
}

if (userAgent.startsWith('bun')) {
return 'bun'
}

return 'npm'
}

0 comments on commit efa3c58

Please sign in to comment.