Skip to content

Commit

Permalink
add bun support
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsandersen committed Oct 10, 2023
1 parent 556068f commit 779191a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/packageManagers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe("getPackageManager", () => {
"install": "pnpm add",
}
`);

expect(getPackageManager('bun', { workingDirectory: "test/bun" }))
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"install": "bun i",
}
`);
});

test("should use npm if no value provided and package-lock.json exists", () => {
Expand Down Expand Up @@ -58,6 +66,16 @@ describe("getPackageManager", () => {
`);
});

test("should use bun if no value provided and bun.lockb exists", () => {
expect(getPackageManager("", { workingDirectory: "test/bun" }))
.toMatchInlineSnapshot(`
{
"exec": "bunx",
"install": "bun i",
}
`);
});

test("should use npm if no value provided and no lockfile is present", () => {
expect(getPackageManager("", { workingDirectory: "test/empty" }))
.toMatchInlineSnapshot(`
Expand Down
7 changes: 7 additions & 0 deletions src/packageManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const PACKAGE_MANAGERS = {
install: "pnpm add",
exec: "pnpm exec",
},
bun: {
install: "bun i",
exec: "bunx"
},
} as const satisfies Readonly<Record<string, PackageManager>>;

type PackageManagerValue = keyof typeof PACKAGE_MANAGERS;
Expand All @@ -35,6 +39,9 @@ function detectPackageManager(
if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
return "pnpm";
}
if (existsSync(path.join(workingDirectory, "bun.lockb"))) {
return "bun";
}
return null;
}

Expand Down
Empty file added test/bun/bun.lockb
Empty file.
26 changes: 26 additions & 0 deletions test/bun/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};

export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);

if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;

if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}

return new Response("OK");
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};
3 changes: 3 additions & 0 deletions test/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "wrangler-action-npm-test",
}
4 changes: 4 additions & 0 deletions test/bun/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "wrangler-action-test"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true

0 comments on commit 779191a

Please sign in to comment.