Skip to content

Commit

Permalink
chore(cli): add support for bun package manager (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 authored Nov 8, 2024
1 parent 79fda1b commit 1ae29bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/cli/src/node/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promisify } from 'util'

const execPromise = promisify(exec)

export const PACKAGE_MANAGER_TYPES = ['pnpm', 'yarn', 'npm'] as const
export const PACKAGE_MANAGER_TYPES = ['pnpm', 'bun', 'yarn', 'npm'] as const

export type PackageManagerType = (typeof PACKAGE_MANAGER_TYPES)[number]

Expand All @@ -30,6 +30,10 @@ export async function selectPackageManager(): Promise<PackageManager> {
return createPnpm()
}

if (await isPackageManagerAvailable('bun')) {
return createRunner({ type: 'bun' })
}

if (await isPackageManagerAvailable('npm')) {
return createNpm()
}
Expand All @@ -45,6 +49,7 @@ export async function selectPackageManager(): Promise<PackageManager> {

export function getPackageManager(type: PackageManagerType) {
if (type === 'pnpm') return createPnpm()
if (type === 'bun') return createBun()
if (type === 'yarn') return createYarn()
if (type === 'npm') return createNpm()
throw new Error(`Unknown package manager ${type as string}.`)
Expand All @@ -62,6 +67,10 @@ function createNpm(): PackageManager {
return createRunner({ type: 'npm', installArgs: ['--legacy-peer-deps'] })
}

function createBun(): PackageManager {
return createRunner({ type: 'bun' })
}

function createRunner({
type,
installArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ setupMarkedExtensions()
// Alllows custom commands to highlight in shell syntax
Prism.languages.insertBefore('shell', 'function', {
keyword: {
pattern: /(^\s*)(?:magidoc|pnpm|npm|yarn)(?=\s)/m,
pattern: /(^\s*)(?:magidoc|pnpm|npm|yarn|bun)(?=\s)/m,
lookbehind: true,
},
})
Expand Down

0 comments on commit 1ae29bc

Please sign in to comment.