Skip to content

Commit

Permalink
bun.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Jan 23, 2025
1 parent 070d650 commit 68dc033
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe("install", () => {
["i", "--bun", "--save-dev", "@std/[email protected]"],
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<PkgJson>(
Expand Down Expand Up @@ -333,7 +333,7 @@ describe("install", () => {
["i", "--bun", "--save-optional", "@std/[email protected]"],
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<PkgJson>(
Expand Down Expand Up @@ -440,7 +440,7 @@ describe("install", () => {
["i", "--bun", "@std/[email protected]"],
async (dir) => {
assert.ok(
await isFile(path.join(dir, "bun.lockb")),
await isFile(path.join(dir, "bun.lock")),
"bun lockfile not created",
);

Expand Down Expand Up @@ -584,7 +584,7 @@ describe("install", () => {
["i", "@std/[email protected]"],
async (dir) => {
assert.ok(
await isFile(path.join(dir, "bun.lockb")),
await isFile(path.join(dir, "bun.lock")),
"bun lockfile not created",
);
},
Expand Down
8 changes: 8 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 68dc033

Please sign in to comment.