diff --git a/.gitignore b/.gitignore index 585a88d1..3ae014eb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ npm-debug.log* # Dependency directory node_modules +bun.lockb # Coverage directory used by tools like istanbul coverage diff --git a/which-pm/index.d.ts b/which-pm/index.d.ts index a5ecac7b..17835e0e 100644 --- a/which-pm/index.d.ts +++ b/which-pm/index.d.ts @@ -1,7 +1,7 @@ declare function whichpm (pkgPath: string): Promise declare namespace whichpm { - type Result = NPM | YARN | PNPM | Other + type Result = NPM | YARN | PNPM | BUN | Other interface NPM { readonly name: 'npm' @@ -16,6 +16,10 @@ declare namespace whichpm { readonly version: string } + interface BUN { + readonly name: 'bun' + } + interface Other { readonly name: string readonly version?: string diff --git a/which-pm/index.js b/which-pm/index.js index 1f0d8f96..68564b22 100644 --- a/which-pm/index.js +++ b/which-pm/index.js @@ -8,6 +8,8 @@ module.exports = async function (pkgPath) { const exists = await pathExists(path.join(modulesPath, '.yarn-integrity')) if (exists) return { name: 'yarn' } + if (await pathExists(path.join(pkgPath, 'bun.lockb'))) return { name: 'bun' } + try { const modules = await loadYamlFile(path.join(modulesPath, '.modules.yaml')) return toNameAndVersion(modules.packageManager) diff --git a/which-pm/package.json b/which-pm/package.json index 64f02baf..9090f826 100644 --- a/which-pm/package.json +++ b/which-pm/package.json @@ -21,6 +21,7 @@ "keywords": [ "npm", "pnpm", + "bun", "yarn" ], "author": "Zoltan Kochan", diff --git a/which-pm/test/fixtures/bun/bun.lockb b/which-pm/test/fixtures/bun/bun.lockb new file mode 100755 index 00000000..320a269b Binary files /dev/null and b/which-pm/test/fixtures/bun/bun.lockb differ diff --git a/which-pm/test/fixtures/bun/package.json b/which-pm/test/fixtures/bun/package.json new file mode 100644 index 00000000..7a72be86 --- /dev/null +++ b/which-pm/test/fixtures/bun/package.json @@ -0,0 +1,11 @@ +{ + "name": "bun", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/which-pm/test/index.js b/which-pm/test/index.js index e6cdb9e0..a10b8d48 100644 --- a/which-pm/test/index.js +++ b/which-pm/test/index.js @@ -23,6 +23,12 @@ test('identifies yarn installation', async t => { t.end() }) +test('identifies bun installation', async t => { + const pm = await whichpm(path.join(fixturesDir, 'bun')) + t.deepEqual(pm, { name: 'bun' }) + t.end() +}) + test('identifies npm installation', async t => { const pm = await whichpm(path.join(fixturesDir, 'npm')) t.deepEqual(pm, { name: 'npm' })