Skip to content

Commit

Permalink
feat(helper): add bun support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 2, 2024
1 parent 9edfd71 commit ebedb81
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tools/helper/src/node/utils/packageManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawnSync } from 'node:child_process'
import { fs, path } from 'vuepress/utils'

export type PackageManager = 'npm' | 'yarn' | 'pnpm'
export type PackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'

const globalCache = new Map<string, boolean>()
const localCache = new Map<string, PackageManager>()
Expand All @@ -10,6 +10,7 @@ const PACKAGE_CONFIG = 'package.json'
const NPM_LOCK = 'package-lock.json'
const YARN_LOCK = 'yarn.lock'
const PNPM_LOCK = 'pnpm-lock.yaml'
const BUN_LOCK = 'bun.lockb'

const isInstalled = (packageManager: PackageManager): boolean => {
try {
Expand Down Expand Up @@ -134,6 +135,12 @@ export const getTypeofLockFile = (
return 'yarn'
}

if (fs.existsSync(path.resolve(cwd, BUN_LOCK))) {
localCache.set(key, 'bun')

return 'bun'
}

if (fs.existsSync(path.resolve(cwd, NPM_LOCK))) {
localCache.set(key, 'npm')

Expand All @@ -158,6 +165,12 @@ export const getTypeofLockFile = (
return 'yarn'
}

if (fs.existsSync(path.resolve(cwd, BUN_LOCK))) {
localCache.set(key, 'bun')

return 'bun'
}

if (fs.existsSync(path.resolve(dir, NPM_LOCK))) {
localCache.set(key, 'npm')

Expand Down Expand Up @@ -186,4 +199,6 @@ export const getPackageManager = (
? 'pnpm'
: isPackageManagerInstalled('yarn')
? 'yarn'
: 'npm')
: isPackageManagerInstalled('bun')
? 'bun'
: 'npm')

0 comments on commit ebedb81

Please sign in to comment.