From 250c2eb93d26910ecee284fede52739fbbdef209 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 15 May 2024 14:44:04 -0700 Subject: [PATCH] feat(which-pm): add bun support (#188) * which-pm: add bun support * remove unneeded files --- .gitignore | 1 + which-pm/index.d.ts | 6 +++++- which-pm/index.js | 2 ++ which-pm/package.json | 1 + which-pm/test/fixtures/bun/bun.lockb | Bin 0 -> 3125 bytes which-pm/test/fixtures/bun/package.json | 11 +++++++++++ which-pm/test/index.js | 6 ++++++ 7 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 which-pm/test/fixtures/bun/bun.lockb create mode 100644 which-pm/test/fixtures/bun/package.json 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 0000000000000000000000000000000000000000..320a269be3c9eae1ff6090d2a11efe763b81a74c GIT binary patch literal 3125 zcmY#Z)GsYA(of3F(@)JSQ%EY!;{sycoc!eMw9K4T-L(9o+{6;yG6OCq1_lO>%ik6+ z*L7=u%bWUgS*DDDmU@oD2kWRwDN0k-WsbBQU&;+s1O)65ih%=-Zh-Q$VG0<4mVw2% zfFuw%cmZinAUzXG_W^03p$!6z3=BL#8ps8!JJ5J<<=K1IS5C2M?)5fk{8IfU{cMNO zYo*1fXH?G5x|BIlKdM)4tF0wxzRj^$fwOkcS8dSIZcR-B8bc8Pg#rkO0I?a+Juvft zZX*i7^ale~TO;XLAxbv`15E!Spn4OaeozRr0x>B3hygJD*MN$xfcioH07aS{F`9vD zVESc%9(M%l2iYwJ#2}g&0Mnld)NcdT&jQp)tbULkATvN16!y$eHb_5+&jzJo2@FO9 zg~`c?b)r8yw)pzfi z{fk+=A%@LJvdHR(=>LswYi}Ru3z;4%W~E@ha?!abA9D_DMKTu_&LC&AG%k|9sAp<1d1yFN`{uuJsVp;h1BRIgV)`Gnu;vO-n;6*G&1YjbN0Z!~t@ zR80N7z)O4@lDVMph5?p+DMEqAZ%vz|bx}U+-IEu$Lf^c6*s<(>!M38iM*qFTCMk39 z|J(U3aIt0R!tkYv9UG5FFW?YrZmYN5SIr{vVB;4gb3thU23SgptEOFvm6<9cVk$hN#NLYsP+oRTJ>>qwDD_L#6Vx!`-fT@0GRrL3^ z%!sUHjnVI@*)&P<`@{X-qG_+HmLQo6N@p;@viFch(3FJcvl)t_tOsSqJQ`1Jk4;zK z(hwHLtMq=tvgMm%{x4X{RP=YAow!@uQAG=*HOeQeul==oFkyq?4aW9^KywEQz``9y zljDv7bUr!G9Vk5;pk>h!D9vS4T$HSrnO9trn3JOit8w*0ic(YU6pRcMiZiQH^V4(` zOcWAxGSl<&(_m%%zyA;b@(3s$et;Ut0j+MiY)Xxd?11`km;j0|Q27AL%b<7%nPCCd z8$zTRuyPh;4#*6cS)lyZ0X4%8SdoJOmrb;hS!}5V&{t+~HyNV)3R17b>S+PSI8!|X zJp)M125K3=YI+W)oWzpU;t~c1SX%*B_cJjX0<{6Ev0X4`#V*K|O+q{!4+*MLsoLU4l zE%vfPV^Es+k62(Ng4#nZ7N%zyEBOBXfVyBVv;_uC1HkY$#2MTrl?AEA$wiq3B@SSw zKCmH{QBqP+Y^ASXl$xGdTvAl2msgORRjij^l&+6Zq^}E7stXEfLnFPC^ePY!Yy=+d za5YffVD(@#jLkr1K#kAKPf3L`%Zu?C2Ui0$uDnv=G=IVmegef>kz>x=uFg#8|!~xJK1P5r42{1_l9R*E)gN_0KS)f5* literal 0 HcmV?d00001 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' })