From 779191a652e2a28538d7bc86605fe1f0d04d80d3 Mon Sep 17 00:00:00 2001 From: Jacob Andersen <19645494+simpleauthority@users.noreply.github.com> Date: Sat, 7 Oct 2023 02:25:35 -0700 Subject: [PATCH 1/4] add bun support --- src/packageManagers.test.ts | 18 ++++++++++++++++++ src/packageManagers.ts | 7 +++++++ test/bun/bun.lockb | 0 test/bun/index.ts | 26 ++++++++++++++++++++++++++ test/bun/package.json | 3 +++ test/bun/wrangler.toml | 4 ++++ 6 files changed, 58 insertions(+) create mode 100755 test/bun/bun.lockb create mode 100644 test/bun/index.ts create mode 100644 test/bun/package.json create mode 100644 test/bun/wrangler.toml diff --git a/src/packageManagers.test.ts b/src/packageManagers.test.ts index 9e97032..4536c67 100644 --- a/src/packageManagers.test.ts +++ b/src/packageManagers.test.ts @@ -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", () => { @@ -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(` diff --git a/src/packageManagers.ts b/src/packageManagers.ts index b395932..e87f9ee 100644 --- a/src/packageManagers.ts +++ b/src/packageManagers.ts @@ -19,6 +19,10 @@ const PACKAGE_MANAGERS = { install: "pnpm add", exec: "pnpm exec", }, + bun: { + install: "bun i", + exec: "bunx" + }, } as const satisfies Readonly>; type PackageManagerValue = keyof typeof PACKAGE_MANAGERS; @@ -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; } diff --git a/test/bun/bun.lockb b/test/bun/bun.lockb new file mode 100755 index 0000000..e69de29 diff --git a/test/bun/index.ts b/test/bun/index.ts new file mode 100644 index 0000000..a330557 --- /dev/null +++ b/test/bun/index.ts @@ -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), + }); + }, +}; diff --git a/test/bun/package.json b/test/bun/package.json new file mode 100644 index 0000000..478c7c8 --- /dev/null +++ b/test/bun/package.json @@ -0,0 +1,3 @@ +{ + "name": "wrangler-action-npm-test", +} diff --git a/test/bun/wrangler.toml b/test/bun/wrangler.toml new file mode 100644 index 0000000..4c09785 --- /dev/null +++ b/test/bun/wrangler.toml @@ -0,0 +1,4 @@ +name = "wrangler-action-test" +main = "./index.ts" +compatibility_date = "2023-07-07" +workers_dev = true From d9a0a00f8bc502ceea2a60e5af258416b35a85b9 Mon Sep 17 00:00:00 2001 From: Jacob Andersen <19645494+simpleauthority@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:41:00 -0700 Subject: [PATCH 2/4] Add changeset --- .changeset/forty-poets-guess.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/forty-poets-guess.md diff --git a/.changeset/forty-poets-guess.md b/.changeset/forty-poets-guess.md new file mode 100644 index 0000000..9ebbb21 --- /dev/null +++ b/.changeset/forty-poets-guess.md @@ -0,0 +1,5 @@ +--- +"wrangler-action": minor +--- + +Added support for Bun as a package manager From 231d787db175b5fbc9fa62b101fdf89be84d3333 Mon Sep 17 00:00:00 2001 From: Cina Saffary Date: Tue, 10 Oct 2023 15:05:59 -0500 Subject: [PATCH 3/4] Update test/bun/package.json --- test/bun/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bun/package.json b/test/bun/package.json index 478c7c8..75d5eeb 100644 --- a/test/bun/package.json +++ b/test/bun/package.json @@ -1,3 +1,3 @@ { - "name": "wrangler-action-npm-test", + "name": "wrangler-action-bun-test", } From 080373bdb63a67a35db45a476191004c768f0a99 Mon Sep 17 00:00:00 2001 From: Jacob Andersen <19645494+simpleauthority@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:17:05 -0700 Subject: [PATCH 4/4] Add bun as a package manager option in action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 6974b31..657d76a 100644 --- a/action.yml +++ b/action.yml @@ -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