diff --git a/src/utils.ts b/src/utils.ts index 2c6670d..ef23b4e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,7 +118,13 @@ export async function findProjectDir( // prefer bun.lockb over yarn.lock // In some cases, both bun.lockb and yarn.lock can exist in the same project. // https://bun.sh/docs/install/lockfile - const bunLockfile = path.join(dir, "bun.lockb"); + const bunbLockfile = path.join(dir, "bun.lockb"); + if (await fileExists(bunbLockfile)) { + logDebug(`Detected bun from lockfile ${bunbLockfile}`); + result.pkgManagerName = "bun"; + return result; + } + const bunLockfile = path.join(dir, "bun.lock"); if (await fileExists(bunLockfile)) { logDebug(`Detected bun from lockfile ${bunLockfile}`); result.pkgManagerName = "bun"; diff --git a/test/commands.test.ts b/test/commands.test.ts index cccbfb4..4ceb392 100644 --- a/test/commands.test.ts +++ b/test/commands.test.ts @@ -277,7 +277,7 @@ describe("install", () => { ["i", "--bun", "--save-dev", "@std/encoding@0.216.0"], async (dir) => { assert.ok( - await isFile(path.join(dir, "bun.lockb")), + await isFile(path.join(dir, "bun.lock")), "bun lockfile not created", ); const pkgJson = await readJson( @@ -333,7 +333,7 @@ describe("install", () => { ["i", "--bun", "--save-optional", "@std/encoding@0.216.0"], async (dir) => { assert.ok( - await isFile(path.join(dir, "bun.lockb")), + await isFile(path.join(dir, "bun.lock")), "bun lockfile not created", ); const pkgJson = await readJson( @@ -440,7 +440,7 @@ describe("install", () => { ["i", "--bun", "@std/encoding@0.216.0"], async (dir) => { assert.ok( - await isFile(path.join(dir, "bun.lockb")), + await isFile(path.join(dir, "bun.lock")), "bun lockfile not created", ); @@ -584,7 +584,7 @@ describe("install", () => { ["i", "@std/encoding@0.216.0"], async (dir) => { assert.ok( - await isFile(path.join(dir, "bun.lockb")), + await isFile(path.join(dir, "bun.lock")), "bun lockfile not created", ); }, diff --git a/test/utils.test.ts b/test/utils.test.ts index 9e712ef..359fad7 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -42,6 +42,14 @@ describe("findProjectDir", () => { }); }); + it("should return bun if bun.lock is found", async () => { + await runInTempDir(async (tempDir) => { + await writeTextFile(path.join(tempDir, "bun.lock"), ""); + const result = await findProjectDir(tempDir); + assert.strictEqual(result.pkgManagerName, "bun"); + }); + }); + it("should return bun if bun.lockb and yarn.lock are found", async () => { // bun allow to save bun.lockb and yarn.lock // https://bun.sh/docs/install/lockfile