Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bun support #188

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-poets-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler-action": minor
---

Added support for Bun as a package manager
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ inputs:
description: "A string of environment variable names, separated by newlines. These will be bound to your Worker using the values of matching environment variables declared in `env` of this workflow."
required: false
packageManager:
description: "The package manager you'd like to use to install and run wrangler. If not specified, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn]"
description: "The package manager you'd like to use to install and run wrangler. If not specified, a value will be inferred based on the presence of a lockfile. Valid values: [npm, pnpm, yarn, bun]"
required: false
default: npm
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-bun-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
Loading